/* Internal thread ID, useful for logging */
extern _Atomic uint max_thread_id;
extern _Thread_local uint this_thread_id;
-#define THIS_THREAD_ID (this_thread_id ?: (this_thread_id = atomic_fetch_add_explicit(&max_thread_id, 1, memory_order_acq_rel)))
+#define THIS_THREAD_ID this_thread_id
/* Debugging */
extern struct birdloop main_birdloop;
+#define MAX_THREADS 256
+
/* Currently running birdloop */
extern _Thread_local struct birdloop *this_birdloop;
conf: THREADS expr {
if ($2 < 1) cf_error("Number of threads must be at least one.");
+ if ($2 > MAX_THREADS) cf_error("Number of threads must not be higher than %i.", MAX_THREADS);
new_config->thread_count = $2;
}
#include "lib/event.h"
#include "lib/timer.h"
#include "lib/socket.h"
+#include "lib/bitmap.h"
#include "lib/io-loop.h"
#include "sysdep/unix/io-loop.h"
UNLOCK_DOMAIN(attrs, thr->group->domain);
}
+struct hmap hmap_thread_ids;
+
static void *
bird_thread_main(void *arg)
{
struct bird_thread *thr = this_thread = arg;
+ this_thread_id = thr->id;
rcu_thread_start();
thr->meta->thread = NULL;
thr->meta = NULL;
birdloop_free(meta);
+
+ /* Return the thread ID */
+ hmap_clear(&hmap_thread_ids, thr->id);
}
static struct bird_thread *
thr->meta = meta;
thr->meta->thread = thr;
+ thr->id = hmap_first_zero(&hmap_thread_ids);
+ hmap_set(&hmap_thread_ids, thr->id);
+ thr->id++;
+
wakeup_init(thr);
ev_init_list(&thr->priority_events, NULL, "Thread direct event list");
this_birdloop = &main_birdloop;
this_thread = &main_thread;
+ hmap_init(&hmap_thread_ids, &root_pool, 1024);
+
defer_init(lp_new(&root_pool));
}