semaphore.c File Reference

implementation of semaphores More...

#include "semaphore.h"
#include "errnums.h"
#include "debug.h"
#include "timers.h"
#include "int.h"
#include "io.h"

Functions

void sem_init (semaphore_t *sem, const int value)
 Initilaization of the semaphore.
void sem_destroy (semaphore_t *sem)
 free semaphore structures.
int sem_get_value (semaphore_t *sem)
 Get value of the semaphore.
void sem_up (semaphore_t *sem)
 Function increment semaphore value, in case some threads are waiting on the semaphore, it \ wakeup one of them.
void sem_down (semaphore_t *sem)
 Sets down semaphore If the semaphore can not be set down, thread suspendon it.
int sem_try_down (semaphore_t *sem)
 Internal function.
int sem_down_timeout (semaphore_t *sem, const unsigned int usec)


Detailed Description

implementation of semaphores

Semaphores are implemented as a integer variable and queue of threads waiting on the semaphore. The implementation don't solve this cases (&& we know it && we think it can cause troubles ) Is undefined what happens, if thread waiting in the quque is waked up by another thread and not by semaphore. It is undefined, what happens, if thread "owning" semaphore is killed.

This file is based on Kalisto, Development Kernel copyrighted (c) to Distributed Systems Research Group MFF UK, Czech republic.


Function Documentation

void sem_destroy ( semaphore_t *  sem  ) 

free semaphore structures.

Function call panic if any thread is waiting on semaphore.

Parameters:
sem - semaphore to be initialized

void sem_down ( semaphore_t *  sem  ) 

Sets down semaphore If the semaphore can not be set down, thread suspendon it.

Parameters:
sem - semaphore to be set down

int sem_get_value ( semaphore_t *  sem  ) 

Get value of the semaphore.

Returns:
Return an actual value of the semaphore.

void sem_init ( semaphore_t *  sem,
const int  value 
)

Initilaization of the semaphore.

This function initiliaze structure for the semaphore.

Parameters:
sem - semaphore to be initialized
value - value to be initialized to

int sem_try_down ( semaphore_t *  sem  ) 

Internal function.

Tryes to set semaphore down

Returns:
-1 if semaphore can not be set down, 0 otherwise.

void sem_up ( semaphore_t *  sem  ) 

Function increment semaphore value, in case some threads are waiting on the semaphore, it \ wakeup one of them.

Parameters:
sem - pointer to semaphore structure.


Generated on Wed Nov 15 17:25:44 2006 for Kalisto by  doxygen 1.4.7