Encapsulates an os specific exclusive lock.
Mutex | Encapsulates an os specific exclusive lock. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file of Mutex. |
C-kern/ | Linux specific implementation Mutex Linuximpl. |
Types | |
struct mutex_t | Exports mutex_t into global namespace. |
Functions | |
test | |
unittest_platform_sync_mutex | Tests system thread functionality. |
mutex_t | Implements a mutual exclusion lock. |
lifetime | |
mutex_INIT_DEFAULT | Static initializer for mutex_t without error checking. |
init_mutex | Initializer for a mutex with error checking. |
free_mutex | Frees resources of mutex which is not in use. |
change | |
lock_mutex | Locks a mutex. |
unlock_mutex | Unlocks a previously locked mutex. |
slock_mutex | Same as lock_mutex. |
sunlock_mutex | Same as unlock_mutex. |
inline implementation | |
slock_mutex | Implements mutex_t.slock_mutex. |
sunlock_mutex | Implements mutex_t.sunlock_mutex. |
KONFIG_SUBSYS | |
init_mutex | Implement mutex_t.init_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD) |
free_mutex | Implement mutex_t.free_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD) |
lock_mutex | Implement mutex_t.lock_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD) |
unlock_mutex | Implement mutex_t.unlock_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD) |
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2011 Jörg Seebohn
Header file of Mutex.
Linux specific implementation Mutex Linuximpl.
Exports mutex_t into global namespace.
test | |
unittest_platform_sync_mutex | Tests system thread functionality. |
typedef sys_mutex_t mutex_t
Implements a mutual exclusion lock. This thread safe object is used to protect a critical section of code against simultaneous execution by several threads. Use lock_mutex before entering a critical section of code and use unlock_mutex just before you leave it. This mutex can also be used between different processes.
lifetime | |
mutex_INIT_DEFAULT | Static initializer for mutex_t without error checking. |
init_mutex | Initializer for a mutex with error checking. |
free_mutex | Frees resources of mutex which is not in use. |
change | |
lock_mutex | Locks a mutex. |
unlock_mutex | Unlocks a previously locked mutex. |
slock_mutex | Same as lock_mutex. |
sunlock_mutex | Same as unlock_mutex. |
#define mutex_INIT_DEFAULT sys_mutex_INIT_DEFAULT
Static initializer for mutex_t without error checking.
1. No deadlock detection. 2. Locking it more than once without first unlocking it => DEADLOCK (waits indefinitely). 3. Unlocking a mutex locked by a different thread works. It is the same as if the thread which holds the lock calls unlock. 4. Unlocking an already unlocked mutex is unspecified. So never do it. 5. Works only within a single process as inter thread mutex.
int init_mutex( /*out*/mutex_t * mutex )
Initializer for a mutex with error checking.
1. No deadlock detection. 2. Locking it more than once without first unlocking it returns error EDEADLK. 3. Unlocking a mutex locked by a different thread is prevented and returns error EPERM. 4. Unlocking an already unlocked mutex is prevented and returns error EPERM.
int unlock_mutex( mutex_t * mutex )
Unlocks a previously locked mutex. Unlocking a mutex more than once is unspecified and may return success but corrupts internal counters. Unlocking a mutex which another thread has locked works as if the lock holder thread would call unlock. If you try to lock a freed mutex EINVAL is returned.
void slock_mutex( mutex_t * mutex )
Same as lock_mutex. Except that an error leads to a system abort.
void sunlock_mutex( mutex_t * mutex )
Same as unlock_mutex. Except that an error leads to a system abort.
slock_mutex | Implements mutex_t.slock_mutex. |
sunlock_mutex | Implements mutex_t.sunlock_mutex. |
KONFIG_SUBSYS | |
init_mutex | Implement mutex_t.init_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD) |
free_mutex | Implement mutex_t.free_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD) |
lock_mutex | Implement mutex_t.lock_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD) |
unlock_mutex | Implement mutex_t.unlock_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD) |
#define slock_mutex( /*mutex_t * */mutex ) (assert(!lock_mutex(mutex))) ;
Implements mutex_t.slock_mutex.
#define sunlock_mutex( /*mutex_t * */mutex ) (assert(!unlock_mutex(mutex))) ;
Implements mutex_t.sunlock_mutex.
#define init_mutex( mutex ) (0)
Implement mutex_t.init_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD)
#define free_mutex( mutex ) (0)
Implement mutex_t.free_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD)
#define lock_mutex( mutex ) (0)
Implement mutex_t.lock_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD)
#define unlock_mutex( mutex ) (0)
Implement mutex_t.unlock_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD)
Implements a mutual exclusion lock.
typedef sys_mutex_t mutex_t
Tests system thread functionality.
int unittest_platform_sync_mutex( void )
Static initializer for mutex_t without error checking.
#define mutex_INIT_DEFAULT sys_mutex_INIT_DEFAULT
Initializer for a mutex with error checking.
int init_mutex( /*out*/mutex_t * mutex )
Frees resources of mutex which is not in use.
int free_mutex( mutex_t * mutex )
Locks a mutex.
int lock_mutex( mutex_t * mutex )
Unlocks a previously locked mutex.
int unlock_mutex( mutex_t * mutex )
Same as lock_mutex.
void slock_mutex( mutex_t * mutex )
Same as unlock_mutex.
void sunlock_mutex( mutex_t * mutex )
Implements mutex_t.slock_mutex.
#define slock_mutex( /*mutex_t * */mutex ) (assert(!lock_mutex(mutex))) ;
Implements mutex_t.sunlock_mutex.
#define sunlock_mutex( /*mutex_t * */mutex ) (assert(!unlock_mutex(mutex))) ;
Implement mutex_t.init_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD)
#define init_mutex( mutex ) (0)
Implement mutex_t.free_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD)
#define free_mutex( mutex ) (0)
Implement mutex_t.lock_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD)
#define lock_mutex( mutex ) (0)
Implement mutex_t.unlock_mutex as a no op if !defined(KONFIG_SUBSYS_THREAD)
#define unlock_mutex( mutex ) (0)