sem.c File Reference

Semaphore based synchronization services. More...

#include "sem.h"
#include <kern/proc.h>
#include <kern/proc_p.h>
#include <kern/signal.h>
#include <cfg/debug.h>

Go to the source code of this file.


Functions

void sem_init (struct Semaphore *s)
 Initialize a Semaphore structure.
bool sem_attempt (struct Semaphore *s)
 Attempt to lock a semaphore without waiting.
void sem_obtain (struct Semaphore *s)
 Lock a semaphore.
void sem_release (struct Semaphore *s)
 Release a lock on a previously locked semaphore.

Detailed Description

Semaphore based synchronization services.

Version:
Id
sem.c 1043 2008-01-16 15:34:01Z asterix

Author:
Bernardo Innocenti <bernie@develer.com>

Definition in file sem.c.


Function Documentation

bool sem_attempt ( struct Semaphore *  s  ) 

Attempt to lock a semaphore without waiting.

Returns:
true in case of success, false if the semaphore was already locked by someone else.
Note:
each call to sem_attempt() must be matched by a call to sem_release().
See also:
sem_obtain() sem_release()

Definition at line 79 of file sem.c.

void sem_obtain ( struct Semaphore *  s  ) 

Lock a semaphore.

If the semaphore is already owned by another process, the caller process will be enqueued into the waiting list and sleep until the semaphore is available.

Note:
Each call to sem_obtain() must be matched by a call to sem_release().

This routine is optimized for highest speed in the most common case: the semaphore is free or locked by the calling process itself. Rearranging this code is probably a bad idea.

See also:
sem_release() sem_attempt()

Definition at line 114 of file sem.c.

void sem_release ( struct Semaphore *  s  ) 

Release a lock on a previously locked semaphore.

If the nesting count of the semaphore reaches zero, the next process waiting for it will be awaken.

Note:
This routine is optimized for highest speed in the most common case: the semaphore has been locked just once and nobody else was waiting for it. Rearranging this code is probably a bad idea.
See also:
sem_obtain() sem_attempt()

Definition at line 158 of file sem.c.