Usermode/libposix - Fixed compilation error with higher warnings
[tpg/acess2.git] / KernelLand / Kernel / include / rwlock.h
1 /*
2  * Acess2 Kernel
3  * 
4  * rwmutex.c
5  * - Reader-Writer Mutex (Multiple Readers, One Writer)
6  */
7 #ifndef _RWLOCK_H
8 #define _RWLOCK_H
9
10 #include <acess.h>
11
12 typedef struct sRWLock  tRWLock;
13
14 struct sRWLock
15 {
16         tShortSpinlock  Protector;      //!< Protector for the lock strucure
17         const char      *Name;  //!< Human-readable name
18          int    Level;  // Number of readers active
19         struct sThread  *volatile Owner;        //!< Owner of the lock (set upon getting the lock)
20         struct sThread  *ReaderWaiting;         //!< Waiting threads (readers)
21         struct sThread  *ReaderWaitingLast;     //!< Waiting threads
22         
23         struct sThread  *WriterWaiting;         //!< Waiting threads (writers)
24         struct sThread  *WriterWaitingLast;     //!< Waiting threads
25 };
26
27 /**
28  * \brief Acquire a read-write lock for reading
29  * \param Lock Lock to acquire
30  * \return zero on success, -1 if terminated
31  * 
32  * Waits until the lock is readable and the increments the reader count
33  */
34 extern int      RWLock_AcquireRead(tRWLock *Lock);
35
36 /**
37  * \brief Acquire a read-write lock for writing
38  * \param Lock Lock to acquire
39  * \return zero on success, -1 if terminated
40  *
41  * Waits until there are no writers, flags all readers to wait, then acquires the lock.
42  */
43 extern int      RWLock_AcquireWrite(tRWLock *Lock);
44
45 /**
46  * \brief Release a held rw lock
47  * \param Lock  Lock to release
48  * \note Releasing a non-held lock has no effect
49  */
50 extern void     RWLock_Release(tRWLock *Lock);
51
52 #endif

UCC git Repository :: git.ucc.asn.au