+#define WQPTR_IS_INITING_VALUE ((void *)~(uintptr_t)0)
+
+static void *
+proc_get_wqptr(struct proc *p) {
+ void *wqptr = p->p_wqptr;
+ return (wqptr == WQPTR_IS_INITING_VALUE) ? NULL : wqptr;
+}
+static void
+proc_set_wqptr(struct proc *p, void *y) {
+ proc_lock(p);
+
+ assert(y == NULL || p->p_wqptr == WQPTR_IS_INITING_VALUE);
+
+ p->p_wqptr = y;
+
+ if (y != NULL){
+ wakeup(&p->p_wqptr);
+ }
+
+ proc_unlock(p);
+}
+static boolean_t
+proc_init_wqptr_or_wait(struct proc *p) {
+ proc_lock(p);
+
+ if (p->p_wqptr == NULL){
+ p->p_wqptr = WQPTR_IS_INITING_VALUE;
+ proc_unlock(p);
+
+ return TRUE;
+ } else if (p->p_wqptr == WQPTR_IS_INITING_VALUE){
+ assert_wait(&p->p_wqptr, THREAD_UNINT);
+ proc_unlock(p);
+ thread_block(THREAD_CONTINUE_NULL);
+
+ return FALSE;
+ } else {
+ proc_unlock(p);
+
+ return FALSE;
+ }
+}
+
+__attribute__((noreturn))