semaphore : <asm/semaphore.h>
create a semaphore:
void sema_init(strct semaphore *sem, int val); //val: the initial value of semaphore
semaphore is usually used as mutex mode, so it can be defined and initialized as follow:
DECLARE_MUTEX(name);
DECLARE_MUTEX_LOCkED(name); //mutex started with locked status
dynamic initialization:
void init_MUTEX(struct semaphore *sem);
void init_MUTEX_LOCKED(struct semaphore *sem);
if a thread has called "down" successfully, it means that this thread has hold this semaphore and can r/w the protected section.
since finished the operation, semaphore must return by calling "up":
down:
void down(struct semaphore *sem);
int down_interruptible(struct semaphore *sem);
int down_trylock(struct semaphore *sem);
up:
void up(struct semaphore *sem);