forked RemoteIR
Fork of RemoteIR by
Diff: Semaphore.h
- Revision:
- 10:c54fb1204d1e
- Parent:
- 9:dcfdac59ef74
- Child:
- 11:268cc2ab63bd
--- a/Semaphore.h Fri Sep 17 20:22:38 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -#ifndef _SEMAPHORE_H_ -#define _SEMAPHORE_H_ - -/* - * http://mbed.org/forum/mbed/topic/181/#comment-799 - */ - -class Semaphore { -public: - Semaphore(): s(SemFree) {} - - bool take(bool block = true) { - int oldval; - do { - oldval = __ldrex(&s); - } while ((block && oldval == SemTaken) || __strex(SemTaken, &s) != 0); - if (!block) { - __clrex(); - } - return (oldval == SemFree); - } - - void release() { - s = SemFree; - } - -private: - enum { SemFree, SemTaken }; - volatile int s; -}; - -#endif \ No newline at end of file