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

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

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

revision 1.31 by ghouston, Sat Aug 17 20:39:35 2002 UTC revision 1.32 by mvo, Sun Oct 27 20:12:07 2002 UTC
# Line 1  Line 1 
1  /*      Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.  /*      Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
2   *   *
3   * This program is free software; you can redistribute it and/or modify   * This program is free software; you can redistribute it and/or modify
4   * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
# Line 293  int Line 293  int
293  coop_new_mutex_init (coop_m *m, coop_mattr *attr)  coop_new_mutex_init (coop_m *m, coop_mattr *attr)
294  {  {
295    m->owner = NULL;    m->owner = NULL;
296      m->level = 0;
297    coop_qinit(&(m->waiting));    coop_qinit(&(m->waiting));
298    return 0;    return 0;
299  }  }
# Line 305  coop_mutex_trylock (coop_m *m) Line 306  coop_mutex_trylock (coop_m *m)
306        m->owner = coop_global_curr;        m->owner = coop_global_curr;
307        return 0;        return 0;
308      }      }
309      else if (m->owner == coop_global_curr)
310        {
311          m->level++;
312          return 0;
313        }
314    else    else
315      return EBUSY;      return EBUSY;
316  }  }
# Line 316  coop_mutex_lock (coop_m *m) Line 322  coop_mutex_lock (coop_m *m)
322      {      {
323        m->owner = coop_global_curr;        m->owner = coop_global_curr;
324      }      }
325      else if (m->owner == coop_global_curr)
326        {
327          m->level++;
328        }
329    else    else
330      {      {
331        coop_t *old, *newthread;        coop_t *old, *newthread;
# Line 343  coop_mutex_unlock (coop_m *m) Line 353  coop_mutex_unlock (coop_m *m)
353  {  {
354    coop_t *old, *newthread;    coop_t *old, *newthread;
355        
356    newthread = coop_qget (&(m->waiting));    if (m->level == 0)
   if (newthread != NULL)  
357      {      {
358        /* Record the current top-of-stack before going to sleep */        newthread = coop_qget (&(m->waiting));
359        coop_global_curr->top = &old;        if (newthread != NULL)
360            {
361        old = coop_global_curr;            /* Record the current top-of-stack before going to sleep */
362        coop_global_curr = newthread;            coop_global_curr->top = &old;
363        /* The new thread came into m->waiting through a lock operation.            
364           It now owns this mutex. */            old = coop_global_curr;
365        m->owner = coop_global_curr;            coop_global_curr = newthread;
366        QT_BLOCK (coop_yieldhelp, old, &coop_global_runq, newthread->sp);            /* The new thread came into m->waiting through a lock operation.
367                 It now owns this mutex. */
368              m->owner = coop_global_curr;
369              QT_BLOCK (coop_yieldhelp, old, &coop_global_runq, newthread->sp);
370            }
371          else
372            {
373              m->owner = NULL;
374            }
375      }      }
376      else if (m->level > 0)
377        m->level--;
378    else    else
379      {      abort (); /* XXX */
380        m->owner = NULL;  
     }  
381    return 0;    return 0;
382  }  }
383    
# Line 472  coop_condition_variable_timed_wait_mutex Line 490  coop_condition_variable_timed_wait_mutex
490  }  }
491    
492  int  int
493  coop_condition_variable_signal (coop_c *c)  coop_condition_variable_broadcast (coop_c *c)
494  {  {
495    coop_t *newthread;    coop_t *newthread;
496    
# Line 483  coop_condition_variable_signal (coop_c * Line 501  coop_condition_variable_signal (coop_c *
501    return 0;    return 0;
502  }  }
503    
504    int
505    coop_condition_variable_signal (coop_c *c)
506    {
507      return coop_condition_variable_broadcast (c);
508    }
509    
510    
511  /* {Keys}  /* {Keys}
512   */   */
513    

Legend:
Removed from v.1.31  
changed lines
  Added in v.1.32

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