semphr. h
xSemaphoreGive( xSemaphoreHandle xSemaphore )
セマフォをリリースするマクロ。 セマフォはこれ以前にvSemaphoreCreateBinary () 、 xSemaphoreCreateMutex
() あるいは xSemaphoreCreateCounting () を使って作成されて、sSemaphoreTake () を使って得られたものです。これマクロは
ISR で使用することは出来ません。 ISR から使える代替APIは xSemaphoreGiveFromISR () を参照してしてください。
このマクロはxSemaphoreCreateRecursiveMutex () を使って作られたセマフォの上で使用できません。
xSemaphoreGive () はタスク間通信 API の一部です。 xSemaphoreAltGive () は代替の 同等API です。
両バージョンは同じパラメータを使用し、同じ値を返します。
パラメータ:
xSemaphore
リリースされているセマフォへのハンドル。 セマフォが作られたとき、これは返されるハンドルです。
リターン:
pdTRUE
もしセマフォがリリースされたなら。
pdFALSE
もしエラーが発生したなら。 Semaphores が待ち行列を使って実行されます。 もし待ち行列の上にメッセージをポストするスペースがないなら、(セマフォが最初に適切に得られなかったことを示すため)エラーを発生する。
使用例:
xSemaphoreHandle xSemaphore = NULL;
void vATask( void * pvParameters )
{
// Create the semaphore to guard a shared resource. As we are using
// the semaphore for mutual exclusion we create a mutex semaphore
// rather than a binary semaphore.
xSemaphore = xSemaphoreCreateMutex();
if( xSemaphore != NULL ) {
if( xSemaphoreGive( xSemaphore ) != pdTRUE ) {
// We would expect this call to fail because we cannot give
// a semaphore without first "taking" it!
}
// Obtain the semaphore - don't block if the semaphore is not
// immediately available.
if( xSemaphoreTake( xSemaphore, ( portTickType ) 0 ) ) {
// We now have the semaphore and can access the shared resource.
// ...
// We have finished accessing the shared resource so can free the
// semaphore.
if( xSemaphoreGive( xSemaphore ) != pdTRUE ) {
// We would not expect this call to fail because we must have
// obtained the semaphore to get here.
}
}
}
}