/[guile]/guile/guile-core/libguile/threads.c
ViewVC logotype

Diff of /guile/guile-core/libguile/threads.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.35 by mdj, Tue Dec 10 16:09:37 2002 UTC revision 1.36 by mdj, Tue Dec 10 16:51:14 2002 UTC
# Line 341  really_launch (SCM_STACKITEM *base, laun Line 341  really_launch (SCM_STACKITEM *base, laun
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 *
# Line 374  create_thread (scm_t_catch_body body, vo Line 375  create_thread (scm_t_catch_body body, vo
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;
# Line 402  create_thread (scm_t_catch_body body, vo Line 403  create_thread (scm_t_catch_body body, vo
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)
# Line 1169  scm_i_thread_put_to_sleep () Line 1174  scm_i_thread_put_to_sleep ()
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))
# Line 1179  scm_i_thread_put_to_sleep () Line 1186  scm_i_thread_put_to_sleep ()
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)
# Line 1199  scm_i_thread_wake_up () Line 1208  scm_i_thread_wake_up ()
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)
# Line 1207  scm_i_thread_wake_up () Line 1219  scm_i_thread_wake_up ()
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  }  }

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.36

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26