1 /*-------------------------------------------------------------
3 mutex.h -- Thread subsystem III
6 Michael Wiedenbauer (shagkur)
7 Dave Murphy (WinterMute)
9 This software is provided 'as-is', without any express or implied
10 warranty. In no event will the authors be held liable for any
11 damages arising from the use of this software.
13 Permission is granted to anyone to use this software for any
14 purpose, including commercial applications, and to alter it and
15 redistribute it freely, subject to the following restrictions:
17 1. The origin of this software must not be misrepresented; you
18 must not claim that you wrote the original software. If you use
19 this software in a product, an acknowledgment in the product
20 documentation would be appreciated but is not required.
22 2. Altered source versions must be plainly marked as such, and
23 must not be misrepresented as being the original software.
25 3. This notice may not be removed or altered from any source
28 -------------------------------------------------------------*/
35 \brief Thread subsystem III
41 #define LWP_MUTEX_NULL 0xffffffff
48 /*! \typedef u32 mutex_t
49 \brief typedef for the mutex handle
54 /*! \fn s32 LWP_MutexInit(mutex_t *mutex,boolean use_recursive)
55 \brief Initializes a mutex lock.
56 \param[out] mutex pointer to a mutex_t handle.
57 \param[in] use_recursive whether to allow the thread, whithin the same context, to enter multiple times the lock or not.
59 \return 0 on success, <0 on error
61 s32
LWP_MutexInit(mutex_t
*mutex
,boolean use_recursive
);
64 /*! \fn s32 LWP_MutexDestroy(mutex_t mutex)
65 \brief Close mutex lock, release all threads and handles locked on this mutex.
66 \param[in] mutex handle to the mutex_t structure.
68 \return 0 on success, <0 on error
70 s32
LWP_MutexDestroy(mutex_t mutex
);
73 /*! \fn s32 LWP_MutexLock(mutex_t mutex)
74 \brief Enter the mutex lock.
75 \param[in] mutex handle to the mutext_t structure.
77 \return 0 on success, <0 on error
79 s32
LWP_MutexLock(mutex_t mutex
);
82 /*! \fn s32 LWP_MutexTryLock(mutex_t mutex)
83 \brief Try to enter the mutex lock.
84 \param[in] mutex handle to the mutex_t structure.
86 \return 0: on first aquire, 1: would lock
88 s32
LWP_MutexTryLock(mutex_t mutex
);
91 /*! \fn s32 LWP_MutexUnlock(mutex_t mutex)
92 \brief Release the mutex lock and let other threads process further on this mutex.
93 \param[in] mutex handle to the mutex_t structure.
95 \return 0 on success, <0 on error
97 s32
LWP_MutexUnlock(mutex_t mutex
);