#include <sync/chSem.h>int semInit(KnSem * sem, unsigned int count);
The function or functions documented here may not be used safely in all application contexts with all APIs provided in the ChorusOS 5.0 product.
See API(5FEA) for details.
Semaphores are KnSem structures allocated in the user memory.
semInit() initializes the semaphore, the address of which is sem . Count is the initial positive value given to the semaphore counter.
Unless they are shared between two or more actors, statically allocated semaphores can be initialized using the K_KNSEM_INITIALIZER(cnt) macro, where cnt is the initial positive value given to the semaphore counter. This macro is used as follows:
KnSem mySem = K_KNSEM_INITIALIZER(cnt) ;
semInit() is used to initialize a semaphore that is shared between two or more actors.
semP() decrements the semaphore counter. If the counter reaches a strictly negative value, the calling thread is blocked, according to the options described by waitLimit in intro(2K) . waitLimit is a pointer to a KnTimeVal structure containing a timeout interval as described in sysTime(2K) .
semV() increments the counter. If the new value is less than or equal to 0 , the thread that has been blocked behind the semaphore for the longest time is awakened.
As semaphore structures are allocated in the client memory, the number of semaphores used by an application is not limited. Any modification to the semaphore structure while the semaphore is in use will cause unpredictable synchronization behavior in the application.
A blocking semP() is ABORTABLE (see threadAbort(2K) ).
A user application and a supervisor application may not share a semaphore.
On the contrary, two user applications may share a semaphore by mapping it in both user address spaces.
On successful completion, a value of 0 is returned. Otherwise, a negative error code is returned.
The waitLimit is not a valid KnTimeVal .
semP() has been aborted.
T imeout occurred.
See attributes(5) for descriptions of the following attributes:
|ATTRIBUTE TYPE||ATTRIBUTE VALUE|