// a simple semaphore class // // October 1995 // Bastiaan Sch\"onhage include <hush/source.h> include <net/thread/thread.h> include <net/thread/semaphore.h> include <hush/flags.h> ifdef THREADS include <synch.h> endif ifndef THREADS semaphore::semaphore(int, int ) { else semaphore::semaphore(int count, int process) { sp = new sema_t; if (process) sema_init((sema_t*) sp, count, USYNC_PROCESS, 0); else sema_init((sema_t*) sp, count, USYNC_THREAD, 0); endif } semaphore::~semaphore() { ifdef THREADS sema_destroy((sema_t*)sp); delete (sema_t*)sp; endif } void semaphore::up() { ifdef THREADS sema_post((sema_t*) sp); endif } void semaphore::down() { ifdef THREADS sema_wait((sema_t*) sp); endif } int semaphore::trydown() { ifdef THREADS if( sema_trywait((sema_t*) sp) == 0) return 1; else return 0; else return 0; endif }
Hush Online Technology
hush@cs.vu.nl
09/09/98 |
![]() |
![]() |