Bug #9884 ยป opaque_thread_id.patch
thread_win32.c (working copy) | ||
---|---|---|
th->native_thread_data.interrupt_event = CreateEvent(0, TRUE, FALSE, 0);
|
||
thread_debug("initial thread (th: %p, thid: %p, event: %p)\n",
|
||
th, GET_THREAD()->thread_id,
|
||
fill_thread_id_str(th);
|
||
thread_debug("initial thread (th: %p, thid: %s, event: %p)\n",
|
||
th, GET_THREAD()->thread_id_str,
|
||
th->native_thread_data.interrupt_event);
|
||
}
|
||
... | ... | |
native_thread_destroy(rb_thread_t *th)
|
||
{
|
||
HANDLE intr = InterlockedExchangePointer(&th->native_thread_data.interrupt_event, 0);
|
||
thread_debug("close handle - intr: %p, thid: %p\n", intr, th->thread_id);
|
||
thread_debug("close handle - intr: %p, thid: %s\n", intr, th->thread_id_str);
|
||
w32_close_handle(intr);
|
||
}
|
||
... | ... | |
th->native_thread_data.interrupt_event = CreateEvent(0, TRUE, FALSE, 0);
|
||
/* run */
|
||
thread_debug("thread created (th: %p, thid: %p, event: %p)\n", th,
|
||
th->thread_id, th->native_thread_data.interrupt_event);
|
||
fill_thread_id_str(th);
|
||
thread_debug("thread created (th: %p, thid: %s, event: %p)\n", th,
|
||
th->thread_id_str, th->native_thread_data.interrupt_event);
|
||
thread_start_func_2(th, th->machine.stack_start, rb_ia64_bsp());
|
||
... | ... | |
if (THREAD_DEBUG) {
|
||
Sleep(0);
|
||
thread_debug("create: (th: %p, thid: %p, intr: %p), stack size: %"PRIdSIZE"\n",
|
||
th, th->thread_id,
|
||
fill_thread_id_str(th);
|
||
thread_debug("create: (th: %p, thid: %s, intr: %p), stack size: %"PRIdSIZE"\n",
|
||
th, th->thread_id_str,
|
||
th->native_thread_data.interrupt_event, stack_size);
|
||
}
|
||
return 0;
|
||
... | ... | |
}
|
||
static HANDLE timer_thread_id = 0;
|
||
static int timer_thread_created = 0;
|
||
static HANDLE timer_thread_lock;
|
||
static unsigned long __stdcall
|
||
... | ... | |
}
|
||
timer_thread_id = w32_create_thread(1024 + (THREAD_DEBUG ? BUFSIZ : 0),
|
||
timer_thread_func, 0);
|
||
timer_thread_created = 1;
|
||
w32_resume_thread(timer_thread_id);
|
||
}
|
||
}
|
||
... | ... | |
native_thread_join(timer_thread_id);
|
||
CloseHandle(timer_thread_lock);
|
||
timer_thread_lock = 0;
|
||
timer_thread_created = 0;
|
||
}
|
||
return stopped;
|
||
}
|
||
... | ... | |
if (timer_thread_id) {
|
||
CloseHandle(timer_thread_id);
|
||
timer_thread_id = 0;
|
||
timer_thread_created = 0;
|
||
}
|
||
}
|
||
thread_pthread.c (working copy) | ||
---|---|---|
static void native_cond_destroy(rb_nativethread_cond_t *cond);
|
||
static void rb_thread_wakeup_timer_thread_low(void);
|
||
static pthread_t timer_thread_id;
|
||
static int timer_thread_created;
|
||
#define RB_CONDATTR_CLOCK_MONOTONIC 1
|
||
... | ... | |
pthread_key_create(&ruby_native_thread_key, NULL);
|
||
th->thread_id = pthread_self();
|
||
fill_thread_id_str(th);
|
||
native_thread_init(th);
|
||
#ifdef USE_SIGNAL_THREAD_LIST
|
||
native_mutex_initialize(&signal_thread_list_lock);
|
||
... | ... | |
VALUE stack_start;
|
||
#endif
|
||
fill_thread_id_str(th);
|
||
#if defined USE_NATIVE_THREAD_INIT
|
||
native_thread_init_stack(th);
|
||
#endif
|
||
... | ... | |
native_mutex_unlock(&th->interrupt_lock);
|
||
#endif
|
||
thread_debug("create: %p (%d)\n", (void *)th, err);
|
||
fill_thread_id_str(th);
|
||
#ifdef HAVE_PTHREAD_ATTR_INIT
|
||
CHECK_ERR(pthread_attr_destroy(&attr));
|
||
#endif
|
||
... | ... | |
static void
|
||
ubf_select_each(rb_thread_t *th)
|
||
{
|
||
thread_debug("ubf_select_each (%p)\n", (void *)th->thread_id);
|
||
thread_debug("ubf_select_each (%s)\n", th->thread_id_str);
|
||
if (th) {
|
||
pthread_kill(th->thread_id, SIGVTALRM);
|
||
}
|
||
... | ... | |
static void
|
||
rb_thread_create_timer_thread(void)
|
||
{
|
||
if (!timer_thread_id) {
|
||
if (!timer_thread_created) {
|
||
int err;
|
||
#ifdef HAVE_PTHREAD_ATTR_INIT
|
||
pthread_attr_t attr;
|
||
... | ... | |
#endif /* USE_SLEEPY_TIMER_THREAD */
|
||
/* create timer thread */
|
||
if (timer_thread_id) {
|
||
if (timer_thread_created) {
|
||
rb_bug("rb_thread_create_timer_thread: Timer thread was already created\n");
|
||
}
|
||
#ifdef HAVE_PTHREAD_ATTR_INIT
|
||
... | ... | |
fprintf(stderr, "[FATAL] Failed to create timer thread: %s\n", strerror(err));
|
||
exit(EXIT_FAILURE);
|
||
}
|
||
timer_thread_created = 1;
|
||
#ifdef HAVE_PTHREAD_ATTR_INIT
|
||
pthread_attr_destroy(&attr);
|
||
#endif
|
||
... | ... | |
rb_thread_wakeup_timer_thread();
|
||
native_thread_join(timer_thread_id);
|
||
if (TT_DEBUG) fprintf(stderr, "joined timer thread\n");
|
||
timer_thread_id = 0;
|
||
timer_thread_created = 0;
|
||
/* close communication pipe */
|
||
if (close_anyway) {
|
vm_core.h (working copy) | ||
---|---|---|
/* thread control */
|
||
rb_nativethread_id_t thread_id;
|
||
char thread_id_str[sizeof(rb_nativethread_id_t) * 2 + 3];
|
||
enum rb_thread_status status;
|
||
int to_kill;
|
||
int priority;
|
thread.c (working copy) | ||
---|---|---|
#define POSITION_ARGS
|
||
#endif
|
||
static void
|
||
fill_thread_id_str(rb_thread_t *th)
|
||
{
|
||
size_t i;
|
||
strncpy(&th->thread_id_str[0], "0x", 2);
|
||
for (i = 0; i < sizeof(th->thread_id); i++) {
|
||
snprintf(&th->thread_id_str[2 + i * 2], 3, "%02x", ((char *)&th->thread_id)[i]);
|
||
}
|
||
}
|
||
# if THREAD_DEBUG < 0
|
||
static int rb_thread_debug_enabled;
|
||
... | ... | |
# endif
|
||
#else
|
||
#define thread_debug if(0)printf
|
||
#define fill_thread_id_str(th)
|
||
#endif
|
||
#ifndef __ia64
|
||
... | ... | |
else {
|
||
now = timeofday();
|
||
if (now > limit) {
|
||
thread_debug("thread_join: timeout (thid: %p)\n",
|
||
(void *)target_th->thread_id);
|
||
thread_debug("thread_join: timeout (thid: %s)\n",
|
||
target_th->thread_id_str);
|
||
return Qfalse;
|
||
}
|
||
sleep_wait_for_interrupt(th, limit - now, 0);
|
||
}
|
||
thread_debug("thread_join: interrupted (thid: %p)\n",
|
||
(void *)target_th->thread_id);
|
||
thread_debug("thread_join: interrupted (thid: %s)\n",
|
||
target_th->thread_id_str);
|
||
}
|
||
return Qtrue;
|
||
}
|
||
... | ... | |
arg.limit = timeofday() + delay;
|
||
arg.forever = delay == DELAY_INFTY;
|
||
thread_debug("thread_join (thid: %p)\n", (void *)target_th->thread_id);
|
||
thread_debug("thread_join (thid: %s)\n", target_th->thread_id_str);
|
||
if (target_th->status != THREAD_KILLED) {
|
||
rb_thread_list_t list;
|
||
... | ... | |
}
|
||
}
|
||
thread_debug("thread_join: success (thid: %p)\n",
|
||
(void *)target_th->thread_id);
|
||
thread_debug("thread_join: success (thid: %s)\n",
|
||
target_th->thread_id_str);
|
||
if (target_th->errinfo != Qnil) {
|
||
VALUE err = target_th->errinfo;
|
||
... | ... | |
rb_exit(EXIT_SUCCESS);
|
||
}
|
||
thread_debug("rb_thread_kill: %p (%p)\n", (void *)th, (void *)th->thread_id);
|
||
thread_debug("rb_thread_kill: %p (%s)\n", (void *)th, th->thread_id_str);
|
||
if (th == GET_THREAD()) {
|
||
/* kill myself immediately */
|
||
... | ... | |
void
|
||
rb_thread_stop_timer_thread(int close_anyway)
|
||
{
|
||
if (timer_thread_id && native_stop_timer_thread(close_anyway)) {
|
||
if (timer_thread_created && native_stop_timer_thread(close_anyway)) {
|
||
native_reset_timer_thread();
|
||
}
|
||
}
|
vm.c (working copy) | ||
---|---|---|
th->last_status = Qnil;
|
||
th->waiting_fd = -1;
|
||
th->root_svar = Qnil;
|
||
th->thread_id_str[0] = '\0';
|
||
#if OPT_CALL_THREADED_CODE
|
||
th->retval = Qundef;
|