Changeset 7201


Ignore:
Timestamp:
Sep 11, 2007, 11:59:04 AM (12 years ago)
Author:
gb
Message:

Macros for spinlocks; kinder, gentler, less stateful read-write locks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/working-0709/ccl/lisp-kernel/Threads.h

    r6260 r7201  
    4949Boolean extern threads_initialized;
    5050
     51#define LOCK_SPINLOCK(x,tcr) get_spin_lock(&(x),tcr)
     52#define RELEASE_SPINLOCK(x) (x)=0
     53
    5154#define TCR_TO_TSD(tcr) ((void *)((natural)(tcr)+TCR_BIAS))
    5255#define TCR_FROM_TSD(tsd) ((TCR *)((natural)(tsd)-TCR_BIAS))
     
    5659#define SEM_WAIT(s) sem_wait((SEMAPHORE)s)
    5760#define SEM_RAISE(s) sem_post((SEMAPHORE)s)
     61#define SEM_BROADCAST(s, count) do {while(count) {SEM_RAISE(s);(count)--;}}while(0)
    5862#define SEM_TIMEDWAIT(s,t) sem_timedwait((SEMAPHORE)s,(struct timespec *)t)
    5963#endif
     
    6367#define SEM_WAIT(s) semaphore_wait((SEMAPHORE)(natural)s)
    6468#define SEM_RAISE(s) semaphore_signal((SEMAPHORE)(natural)s)
     69#define SEM_BROADCAST(s,count)semaphore_signal_all((SEMAPHORE)(natural)s)
    6570#define SEM_TIMEDWAIT(s,t) semaphore_timedwait((SEMAPHORE)(natural)s,t)
    6671#endif
     
    121126Boolean resume_tcr(TCR *);
    122127
    123 typedef struct _rwquentry
    124 {
    125   struct _rwquentry *prev;
    126   struct _rwquentry *next;
    127   TCR *tcr;
    128   int count;
    129 } rwquentry;
    130 
    131128typedef struct
    132129{
    133   rwquentry head;
    134   int state;                    /* sum of all counts on queue */
    135   pthread_mutex_t *lock;        /* lock access to this data structure */
    136   pthread_cond_t *reader_signal;
    137   pthread_cond_t *writer_signal;
    138   int write_wait_count;
    139   int read_wait_count;
    140   int dying;
    141   rwquentry freelist;
     130  signed_natural spin; /* need spin lock to change fields */
     131  signed_natural state; /* 0 = free, positive if writer, negative if readers; */
     132  natural blocked_writers;
     133  natural blocked_readers;
     134  TCR  *writer;
     135  void * reader_signal;
     136  void * writer_signal;
     137  void *malloced_ptr;
    142138} rwlock;
    143139
    144 #define RWLOCK_WRITER(rw) rw->head.tcr
    145 #define RWLOCK_WRITE_COUNT(rw) rw->head.count
    146140
    147141rwlock * rwlock_new(void);
    148 int rwlock_destroy(rwlock *);
     142void rwlock_destroy(rwlock *);
    149143int rwlock_rlock(rwlock *, TCR *, struct timespec *);
    150144int rwlock_wlock(rwlock *, TCR *, struct timespec *);
    151145int rwlock_try_wlock(rwlock *, TCR *);
     146int rwlock_try_rlock(rwlock *, TCR *);
    152147int rwlock_unlock(rwlock *, TCR *);
    153148
Note: See TracChangeset for help on using the changeset viewer.