Offers interface for accessing semaphores. Semaphores are used to signal events between different thread_t or process_t. If a process executes another program the semaphore is closed. To prevent this an inherit function would be need and a way to transfer the id and init from id function.
Semaphore | Offers interface for accessing semaphores. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file of Semaphore. |
C-kern/ | Linux implementation file Semaphore Linuximpl. |
Types | |
struct semaphore_t | Export semaphore_t. |
Functions | |
test | |
unittest_platform_sync_semaphore | Tests system semaphore functionality. |
semaphore_t | Describes a system semaphore used between threads. |
lifetime | |
semaphore_FREE | Static initializer. |
init_semaphore | Initializes a semaphore. |
free_semaphore | Wakes up any waiting threads and frees the associated resources. |
synchronize | |
signal_semaphore | Wakes up signal_count waiters. |
wait_semaphore | Waits until a signal is received. |
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 Semaphore.
Linux implementation file Semaphore Linuximpl.
typedef struct semaphore_t semaphore_t
Export semaphore_t.
test | |
unittest_platform_sync_semaphore | Tests system semaphore functionality. |
struct semaphore_t
Describes a system semaphore used between threads. This thread safe object allows to wait for or to send a signal to one or more waiters.
lifetime | |
semaphore_FREE | Static initializer. |
init_semaphore | Initializes a semaphore. |
free_semaphore | Wakes up any waiting threads and frees the associated resources. |
synchronize | |
signal_semaphore | Wakes up signal_count waiters. |
wait_semaphore | Waits until a signal is received. |
int init_semaphore( /*out*/semaphore_t * semaobj, uint16_t init_signal_count )
Initializes a semaphore. The internal signal counter is set to init_signal_count. The next init_signal_count calls to wait_semaphore therefore succeed without waiting.
int free_semaphore( semaphore_t * semaobj )
Wakes up any waiting threads and frees the associated resources. Make sure that no other thread which is not already waiting on the semaphore accesses it after free_semaphore has been called.
int signal_semaphore( semaphore_t * semaobj, uint32_t signal_count )
Wakes up signal_count waiters. Or the next signal_count calls to wait_semaphore succeed without waiting. Internally this function increments a signal counter with the number signal_count. Calling this function signal_count times with a value of 1 has therefore the same effect. If the internal counter would overflow the signal function waits until at least that many calls to wait_semaphore has been done so that adding signal_count to the counter does no more produce an overflow. On Linux a 64bit counter is used internally.
Export semaphore_t.
typedef struct semaphore_t semaphore_t
Describes a system semaphore used between threads.
struct semaphore_t
Tests system semaphore functionality.
int unittest_platform_sync_semaphore( void )
Static initializer.
#define semaphore_FREE { sys_semaphore_FREE }
Initializes a semaphore.
int init_semaphore( /*out*/semaphore_t * semaobj, uint16_t init_signal_count )
Wakes up any waiting threads and frees the associated resources.
int free_semaphore( semaphore_t * semaobj )
Wakes up signal_count waiters.
int signal_semaphore( semaphore_t * semaobj, uint32_t signal_count )
Waits until a signal is received.
int wait_semaphore( semaphore_t * semaobj )