The latter passes a thread ID instead of a mask, making the code simpler.
function for local tasks or for shared tasks who have the calling
thread in their thread mask.
-void task_set_affinity(t, m)
- Change task <t>'s thread_mask to new value <m>. This may only be
+void task_set_thread(t, id)
+ Change task <t>'s thread ID to new value <id>. This may only be
performed by the task itself while running. This is only used to let a
- task voluntarily migrate to another thread.
+ task voluntarily migrate to another thread. Thread id -1 is used to
+ indicate "any thread". It's ignored and replaced by zero when threads
+ are disabled.
void tasklet_wakeup(tl)
Make sure that tasklet <tl> will wake up, that is, will execute at
* eventually be created. The affinity must be set now !
*/
BUG_ON(appctx->t->tid != tid);
- task_set_affinity(appctx->t, tid_bit);
+ task_set_thread(appctx->t, tid);
if (appctx->applet->init)
return appctx->applet->init(appctx);
}
}
-/* change the thread affinity of a task to <thread_mask>.
+/* Change the thread affinity of a task to <thr>, which may either be a valid
+ * thread number from 0 to nbthread-1, or a negative value to allow the task
+ * to run on any thread.
+ *
* This may only be done from within the running task itself or during its
* initialization. It will unqueue and requeue the task from the wait queue
* if it was in it. This is safe against a concurrent task_queue() call because
* task_queue() itself will unlink again if needed after taking into account
* the new thread_mask.
*/
-static inline void task_set_affinity(struct task *t, unsigned long thread_mask)
+static inline void task_set_thread(struct task *t, int thr)
{
- int thr;
-
- if (atleast2(thread_mask))
- thr = -1;
- else
- thr = my_ffsl(thread_mask) - 1;
-
+#ifndef USE_THREAD
+ /* no shared queue without threads */
+ thr = 0;
+#endif
if (unlikely(task_in_wq(t))) {
task_unlink_wq(t);
t->tid = thr;
check->state |= CHK_ST_INPROGRESS;
TRACE_STATE("init new health-check", CHK_EV_TASK_WAKE|CHK_EV_HCHK_START, check);
- task_set_affinity(t, tid_bit);
+ task_set_thread(t, tid);
check->current_step = NULL;
if (LIST_INLIST(&check->buf_wait.list))
LIST_DEL_INIT(&check->buf_wait.list);
- task_set_affinity(t, all_threads_mask);
+ task_set_thread(t, -1);
check_release_buf(check, &check->bi);
check_release_buf(check, &check->bo);
check->state &= ~(CHK_ST_INPROGRESS|CHK_ST_IN_ALLOC|CHK_ST_OUT_ALLOC);
int t_con = tick_add(now_ms, s->proxy->timeout.connect);
t->expire = tick_first(t->expire, t_con);
}
- task_set_affinity(t, tid_bit);
+ task_set_thread(t, tid);
goto reschedule;
}
/* a success was detected */
check_notify_success(check);
}
- task_set_affinity(t, 1);
+ task_set_thread(t, 0);
check->state &= ~CHK_ST_INPROGRESS;
pid_list_del(check->curpid);