MEDIUM: threads: replace ha_set_tid() with ha_set_thread()
ha_set_tid() was randomly used either to explicitly set thread 0 or to
set any possibly incomplete thread during boot. Let's replace it with
a pointer to a valid thread or NULL for any thread. This allows us to
check that the designated threads are always valid, and to ignore the
thread 0's mapping when setting it to NULL, and always use group 0 with
it during boot.
The initialization code is also cleaner, as we don't pass ugly casts
of a thread ID to a pointer anymore.
diff --git a/src/hlua.c b/src/hlua.c
index d5d3f59..b03d8bb 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -11060,7 +11060,7 @@
/* loading for global state */
hlua_state_id = 0;
- ha_set_tid(0);
+ ha_set_thread(NULL);
return hlua_load_state(args[1], hlua_states[0], err);
}
@@ -11104,7 +11104,7 @@
/* loading for thread 1 only */
hlua_state_id = 1;
- ha_set_tid(0);
+ ha_set_thread(NULL);
return hlua_load_state(args[1], hlua_states[1], err);
}
@@ -11311,7 +11311,7 @@
/* Perform post init of common thread */
hlua_state_id = 0;
- ha_set_tid(0);
+ ha_set_thread(&ha_thread_info[0]);
ret = hlua_post_init_state(hlua_states[hlua_state_id]);
if (ret == 0)
return 0;
@@ -11320,7 +11320,7 @@
for (hlua_state_id = 2; hlua_state_id < global.nbthread + 1; hlua_state_id++) {
/* set thread context */
- ha_set_tid(hlua_state_id - 1);
+ ha_set_thread(&ha_thread_info[hlua_state_id - 1]);
/* Init lua state */
hlua_states[hlua_state_id] = hlua_init_state(hlua_state_id);
@@ -11336,13 +11336,13 @@
}
/* Reset thread context */
- ha_set_tid(0);
+ ha_set_thread(NULL);
/* Execute post init for all states */
for (hlua_state_id = 1; hlua_state_id < global.nbthread + 1; hlua_state_id++) {
/* set thread context */
- ha_set_tid(hlua_state_id - 1);
+ ha_set_thread(&ha_thread_info[hlua_state_id - 1]);
/* run post init */
ret = hlua_post_init_state(hlua_states[hlua_state_id]);
@@ -11351,7 +11351,7 @@
}
/* Reset thread context */
- ha_set_tid(0);
+ ha_set_thread(NULL);
/* control functions registering. Each function must have:
* - only the function_ref[0] set positive and all other to -1
@@ -12057,12 +12057,12 @@
/* Init state for common/shared lua parts */
hlua_state_id = 0;
- ha_set_tid(0);
+ ha_set_thread(NULL);
hlua_states[0] = hlua_init_state(0);
/* Init state 1 for thread 0. We have at least one thread. */
hlua_state_id = 1;
- ha_set_tid(0);
+ ha_set_thread(NULL);
hlua_states[1] = hlua_init_state(1);
/* Proxy and server configuration initialisation. */