00001 /* header file for core/ipc/sem.cpp */ 00002 00003 #ifndef _CORE_IPC_SEM_HPP 00004 #define _CORE_IPC_SEM_HPP 00005 00006 #include "src/common/blist.hpp" 00007 // #include "src/thread/thread.hpp" 00008 00009 // extern class blist_t named_sems; 00010 00011 struct thread_t; 00012 00013 // namespace IPC { 00014 // namespace Sem { 00015 00016 //sem flags 00017 const uint32 SF_OPEN = 1; //when the sem is open 00018 00019 // info on a waiting thread 00020 struct thwait_t 00021 { 00022 struct thread_t *thread; 00023 uint64 timestamp; //when the thread was added to the waiting queue 00024 }; 00025 00026 // a single semaphore 00027 struct sem_t 00028 { 00029 class blist_t wait_queue; // threads which happen to request the sem when it's non-vacant will be put here. 00030 class IPC::Lock::lock_t lock_sem; //we still need a lock for the val 00031 int volatile val; //tha boss. he tells you what ya'll do 00032 00033 uint32 flags; //custom flags 00034 00035 const char *name; // purrrely debugical. has to be const char* 00036 }; 00037 00038 int sem_init(sem_t *sem, unsigned int value, const char *name); 00039 int sem_destroy(sem_t *sem); 00040 int sem_getvalue(sem_t *sem, int *sval); 00041 int sem_wait(sem_t *sem); 00042 int sem_trywait(sem_t *sem); 00043 int sem_post(sem_t *sem); 00044 00045 00046 // }; /*namespace Sem*/ 00047 // }; /*naemespace IPC*/ 00048 00049 00050 #endif