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

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

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

revision 1.4 by mdj, Mon Dec 16 21:02:37 2002 UTC revision 1.5 by mdj, Wed Dec 18 10:53:23 2002 UTC
# Line 68  static scm_t_mutex rec_mutex_mutex; Line 68  static scm_t_mutex rec_mutex_mutex;
68  #define REC_MUTEX 2  #define REC_MUTEX 2
69    
70  typedef struct mutex {  typedef struct mutex {
 #ifdef SCM_DEBUG_THREADS  
71    int kind;    int kind;
 #endif  
72    pthread_mutex_t mutex;    pthread_mutex_t mutex;
73    scm_thread *owner;    scm_thread *owner;
74    int count;    int count;
# Line 147  int Line 145  int
145  scm_i_plugin_cond_wait (scm_t_cond *c, scm_t_mutex *mx)  scm_i_plugin_cond_wait (scm_t_cond *c, scm_t_mutex *mx)
146  {  {
147    mutex *m = (mutex *) mx;    mutex *m = (mutex *) mx;
148    return pthread_cond_wait ((pthread_cond_t *) c, &m->mutex);    int res;
149      if (m->owner != SCM_CURRENT_THREAD || m->count != 1)
150        {
151          fprintf (stderr, "mutex not locked by self\n");
152          abort ();
153        }
154      res = pthread_cond_wait ((pthread_cond_t *) c, &m->mutex);
155      if (m->owner != 0 || m->count != 0)
156        {
157          fprintf (stderr, "strange internal state\n");
158          abort ();
159        }
160      m->owner = SCM_CURRENT_THREAD;
161      m->count = 1;
162      return res;
163  }  }
164    
165  int  int
# Line 159  scm_i_plugin_cond_timedwait (scm_t_cond Line 171  scm_i_plugin_cond_timedwait (scm_t_cond
171    return pthread_cond_timedwait ((pthread_cond_t *) c, &m->mutex, t);    return pthread_cond_timedwait ((pthread_cond_t *) c, &m->mutex, t);
172  }  }
173    
174    void
175    scm_i_assert_heap_locked ()
176    {
177      mutex *m = (mutex *) &SCM_CURRENT_THREAD->heap_mutex;
178      pthread_mutex_lock (&mutex_mutex);
179      if (gc_running)
180        {
181          fprintf (stderr, "thread running during gc\n");
182          abort ();
183        }
184      if (m->count != 1)
185        {
186          fprintf (stderr, "mutex not locked\n");
187          abort ();
188        }
189      pthread_mutex_unlock (&mutex_mutex);
190    }
191    
192  #endif  #endif
193    
194  /* The following section belongs in threads.c, or rather  /* The following section belongs in threads.c, or rather
# Line 270  int pthread_mutexattr_settype (pthread_m Line 300  int pthread_mutexattr_settype (pthread_m
300  void  void
301  scm_init_pthread_threads ()  scm_init_pthread_threads ()
302  {  {
303      size_t mutex_size, rec_mutex_size;
304    pthread_mutexattr_init (&scm_i_plugin_mutex);    pthread_mutexattr_init (&scm_i_plugin_mutex);
305  #ifdef SCM_MUTEX_FAST  #ifdef SCM_MUTEX_FAST
306    pthread_mutexattr_settype (&scm_i_plugin_mutex, SCM_MUTEX_FAST);    pthread_mutexattr_settype (&scm_i_plugin_mutex, SCM_MUTEX_FAST);
307  #endif  #endif
308    
309  #if defined (SCM_MUTEX_RECURSIVE) && !defined (SCM_DEBUG_THREADS)  #if defined (SCM_MUTEX_RECURSIVE) && !defined (SCM_DEBUG_THREADS)
310    if (sizeof (pthread_mutex_t) > SCM_REC_MUTEX_MAXSIZE)    rec_mutex_size = sizeof (pthread_mutex_t);
311      {    pthread_mutexattr_init (&scm_i_plugin_rec_mutex);
       fprintf (stderr, "Internal error: Need to upgrade mutex size\n");  
       abort ();  
     }  
     pthread_mutexattr_init (&scm_i_plugin_rec_mutex);  
312    pthread_mutexattr_settype (&scm_i_plugin_rec_mutex, SCM_MUTEX_RECURSIVE);    pthread_mutexattr_settype (&scm_i_plugin_rec_mutex, SCM_MUTEX_RECURSIVE);
313  #else  #else
314    /* If PTHREAD_MUTEX_RECURSIVE is not defined,    /* If PTHREAD_MUTEX_RECURSIVE is not defined,
315       scm_i_plugin_rec_mutex_init won't pay attention to it anyway       scm_i_plugin_rec_mutex_init won't pay attention to it anyway
316    */    */
317    if (sizeof (rec_mutex) > SCM_REC_MUTEX_MAXSIZE)    rec_mutex_size = sizeof (rec_mutex);
     {  
       fprintf (stderr, "Internal error: Need to upgrade mutex size\n");  
       abort ();  
     }  
318    scm_i_plugin_mutex_init (&rec_mutex_mutex, &scm_i_plugin_mutex);    scm_i_plugin_mutex_init (&rec_mutex_mutex, &scm_i_plugin_mutex);
319  #endif  #endif
320  #ifdef SCM_DEBUG_THREADS  #ifdef SCM_DEBUG_THREADS
321      mutex_size = sizeof (mutex);
322    pthread_mutex_init (&mutex_mutex, &scm_i_plugin_mutex);    pthread_mutex_init (&mutex_mutex, &scm_i_plugin_mutex);
323    #else
324      mutex_size = sizeof (pthread_mutex_t);
325  #endif  #endif
326      if (mutex_size > SCM_MUTEX_MAXSIZE || rec_mutex_size > SCM_REC_MUTEX_MAXSIZE)
327        {
328          fprintf (stderr, "Internal error: Need to upgrade mutex size\n");
329          abort ();
330        }
331  }  }
332    
333  /*  /*

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

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