Sorting source tree a bit
[tpg/acess2.git] / KernelLand / Kernel / include / mutex.h
1 /*
2  * Acess2 Kernel
3  * mutex.h
4  * - Mutual Exclusion syncronisation primitive
5  */
6 #ifndef _MUTEX_H
7 #define _MUTEX_H
8
9 #include <acess.h>
10
11 typedef struct sMutex   tMutex;
12
13 struct sMutex
14 {
15         tShortSpinlock  Protector;      //!< Protector for the lock strucure
16         const char      *Name;  //!< Human-readable name
17         struct sThread  *volatile Owner;        //!< Owner of the lock (set upon getting the lock)
18         struct sThread  *Waiting;       //!< Waiting threads
19         struct sThread  *LastWaiting;   //!< Waiting threads
20 };
21
22 /**
23  * \brief Acquire a heavy mutex
24  * \param Mutex Mutex to acquire
25  * \return zero on success, -1 if terminated
26  * 
27  * This type of mutex checks if the mutex is avaliable, and acquires it
28  * if it is. Otherwise, the current thread is added to the mutex's wait
29  * queue and the thread suspends. When the holder of the mutex completes,
30  * the oldest thread (top thread) on the queue is given the lock and
31  * restarted.
32  */
33 extern int      Mutex_Acquire(tMutex *Mutex);
34
35 /**
36  * \brief Release a held mutex
37  * \param Mutex Mutex to release
38  * \note Releasing a non-held mutex has no effect
39  */
40 extern void     Mutex_Release(tMutex *Mutex);
41
42 /**
43  * \brief Is this mutex locked?
44  * \param Mutex Mutex pointer
45  */
46 extern int      Mutex_IsLocked(tMutex *Mutex);
47
48 #endif

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