semaphore.hpp
00001 #if !defined(__SYSTEM_L4_SEMAPHORE_HPP__)
00002 #define __SYSTEM_L4_SEMAPHORE_HPP__
00003
00004
00005
00006
00007 #include <l4/semaphore/semaphore.h>
00008
00009
00010
00011
00012 #include "core/util/noncopyable.hpp"
00013
00014
00015
00016
00017 struct semaphore : protected l4semaphore, private noncopyable
00018 {
00019
00020
00021
00022 inline semaphore(void)
00023 : l4semaphore(L4SEMAPHORE_UNLOCKED)
00024 {}
00025
00026
00027 inline semaphore(const l4semaphore &initial_state)
00028 : l4semaphore(initial_state)
00029 {}
00030
00031
00032
00033
00034 inline int operator ()(void) const
00035 {
00036 return counter;
00037 }
00038
00039 inline operator int(void) const
00040 {
00041 return (*this)();
00042 }
00043
00044
00045
00046
00047 inline int down(void)
00048 {
00049 l4semaphore_down(this);
00050 return 0;
00051 }
00052
00053
00054
00055
00056
00057
00058 inline int down(unsigned timeout)
00059 {
00060
00061 return (timeout == ~0u) ? down() : l4semaphore_down_timed(this, timeout / 1000);
00062 }
00063
00064 inline int try_down(void)
00065 {
00066 return l4semaphore_try_down(this);
00067 }
00068
00069 inline void up(void)
00070 {
00071 l4semaphore_up(this);
00072 }
00073
00074
00075
00076
00077 inline semaphore &operator ++(void)
00078 {
00079 up();
00080 return *this;
00081 }
00082
00083 inline semaphore &operator --(void)
00084 {
00085 down();
00086 return *this;
00087 }
00088
00089
00090
00091
00092
00093 inline void operator ++(int)
00094 {
00095 ++*this;
00096 }
00097
00098 inline void operator --(int)
00099 {
00100 --*this;
00101 }
00102 };
00103
00104 #endif
00105
00106
00107