341 |
data, |
data, |
342 |
(scm_t_catch_handler) handler_bootstrip, |
(scm_t_catch_handler) handler_bootstrip, |
343 |
data, base); |
data, base); |
344 |
|
scm_i_plugin_mutex_unlock (&t->heap_mutex); /* release the heap */ |
345 |
free (data); |
free (data); |
346 |
|
|
|
scm_thread_detach (t->thread); |
|
347 |
scm_i_plugin_mutex_lock (&thread_admin_mutex); |
scm_i_plugin_mutex_lock (&thread_admin_mutex); |
348 |
all_threads = scm_delq_x (thread, all_threads); |
all_threads = scm_delq_x (thread, all_threads); |
349 |
t->exited = 1; |
t->exited = 1; |
350 |
thread_count--; |
thread_count--; |
351 |
scm_i_plugin_mutex_unlock (&thread_admin_mutex); |
scm_i_plugin_mutex_unlock (&thread_admin_mutex); |
352 |
/* We're leaving with heap_mutex still locked. */ |
/* We're leaving with heap_mutex still locked. */ |
353 |
|
scm_thread_detach (t->thread); |
354 |
} |
} |
355 |
|
|
356 |
static void * |
static void * |
375 |
|
|
376 |
{ |
{ |
377 |
scm_t_thread th; |
scm_t_thread th; |
378 |
SCM root, old_winds, new_threads; |
SCM root, old_winds; |
379 |
launch_data *data; |
launch_data *data; |
380 |
scm_thread *t; |
scm_thread *t; |
381 |
int err; |
int err; |
403 |
/* In order to avoid the need of synchronization between parent |
/* In order to avoid the need of synchronization between parent |
404 |
and child thread, we need to insert the child into all_threads |
and child thread, we need to insert the child into all_threads |
405 |
before creation. */ |
before creation. */ |
406 |
new_threads = scm_cons (thread, SCM_BOOL_F); /* could cause GC */ |
{ |
407 |
scm_i_plugin_mutex_lock (&thread_admin_mutex); |
SCM new_threads = scm_cons (thread, SCM_BOOL_F); /* could cause GC */ |
408 |
SCM_SETCDR (new_threads, all_threads); |
scm_thread *parent = scm_i_leave_guile (); /* to prevent deadlock */ |
409 |
all_threads = new_threads; |
scm_i_plugin_mutex_lock (&thread_admin_mutex); |
410 |
thread_count++; |
SCM_SETCDR (new_threads, all_threads); |
411 |
scm_i_plugin_mutex_unlock (&thread_admin_mutex); |
all_threads = new_threads; |
412 |
|
thread_count++; |
413 |
|
scm_i_plugin_mutex_unlock (&thread_admin_mutex); |
414 |
|
scm_i_enter_guile (parent); |
415 |
|
} |
416 |
|
|
417 |
err = scm_i_plugin_thread_create (&th, 0, launch_thread, (void *) data); |
err = scm_i_plugin_thread_create (&th, 0, launch_thread, (void *) data); |
418 |
if (err != 0) |
if (err != 0) |
1174 |
SCM_REC_CRITICAL_SECTION_START (gc_section); |
SCM_REC_CRITICAL_SECTION_START (gc_section); |
1175 |
if (threads_initialized_p && gc_section_count == 1) |
if (threads_initialized_p && gc_section_count == 1) |
1176 |
{ |
{ |
1177 |
SCM threads = all_threads; |
SCM threads; |
1178 |
|
scm_i_plugin_mutex_lock (&thread_admin_mutex); |
1179 |
|
threads = all_threads; |
1180 |
/* Signal all threads to go to sleep */ |
/* Signal all threads to go to sleep */ |
1181 |
scm_i_thread_go_to_sleep = 1; |
scm_i_thread_go_to_sleep = 1; |
1182 |
for (; !SCM_NULLP (threads); threads = SCM_CDR (threads)) |
for (; !SCM_NULLP (threads); threads = SCM_CDR (threads)) |
1186 |
scm_i_plugin_mutex_lock (&t->heap_mutex); |
scm_i_plugin_mutex_lock (&t->heap_mutex); |
1187 |
} |
} |
1188 |
scm_i_thread_go_to_sleep = 0; |
scm_i_thread_go_to_sleep = 0; |
1189 |
|
scm_i_plugin_mutex_unlock (&thread_admin_mutex); |
1190 |
} |
} |
1191 |
} |
} |
1192 |
|
|
1193 |
void |
void |
1194 |
scm_i_thread_invalidate_freelists () |
scm_i_thread_invalidate_freelists () |
1195 |
{ |
{ |
1196 |
|
/* Don't need to lock thread_admin_mutex here since we are sinle threaded */ |
1197 |
SCM threads = all_threads; |
SCM threads = all_threads; |
1198 |
for (; !SCM_NULLP (threads); threads = SCM_CDR (threads)) |
for (; !SCM_NULLP (threads); threads = SCM_CDR (threads)) |
1199 |
if (SCM_CAR (threads) != cur_thread) |
if (SCM_CAR (threads) != cur_thread) |
1208 |
{ |
{ |
1209 |
if (threads_initialized_p && gc_section_count == 1) |
if (threads_initialized_p && gc_section_count == 1) |
1210 |
{ |
{ |
1211 |
SCM threads = all_threads; |
SCM threads; |
1212 |
|
/* Need to lock since woken threads can die and be deleted from list */ |
1213 |
|
scm_i_plugin_mutex_lock (&thread_admin_mutex); |
1214 |
|
threads = all_threads; |
1215 |
scm_i_plugin_cond_broadcast (&wake_up_cond); |
scm_i_plugin_cond_broadcast (&wake_up_cond); |
1216 |
for (; !SCM_NULLP (threads); threads = SCM_CDR (threads)) |
for (; !SCM_NULLP (threads); threads = SCM_CDR (threads)) |
1217 |
if (SCM_CAR (threads) != cur_thread) |
if (SCM_CAR (threads) != cur_thread) |
1219 |
scm_thread *t = SCM_THREAD_DATA (SCM_CAR (threads)); |
scm_thread *t = SCM_THREAD_DATA (SCM_CAR (threads)); |
1220 |
scm_i_plugin_mutex_unlock (&t->heap_mutex); |
scm_i_plugin_mutex_unlock (&t->heap_mutex); |
1221 |
} |
} |
1222 |
|
scm_i_plugin_mutex_unlock (&thread_admin_mutex); |
1223 |
} |
} |
1224 |
SCM_REC_CRITICAL_SECTION_END (gc_section); |
SCM_REC_CRITICAL_SECTION_END (gc_section); |
1225 |
} |
} |