Display text on LCD displays (even on multiple ones). Allow to create windows (frames) on display, and to combine them (split, add, duplicate, scroll). See http://mbed.org/users/hlipka/notebook/lcdwindow/ for more information.
Diff: semaphore.cpp
- Revision:
- 3:e5d5e2fe4bf6
- Child:
- 9:2fe93daa2106
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/semaphore.cpp Sun Nov 28 22:09:54 2010 +0000 @@ -0,0 +1,39 @@ +/** + * code from Igor Skochinsky + * taken from http://mbed.org/forum/mbed/post/799/ +*/ + +#include "semaphore.h" + + Semaphore::Semaphore(): s(SemFree) {}; + + bool Semaphore::take(bool block) + { + int oldval; +#if defined(TARGET_LPC1768) // on Cortex-M3 we can use ldrex/strex + do { + // read the semaphore value + oldval = __ldrex(&s); + // loop again if it is locked and we are blocking + // or setting it with strex failed + } + while ( (block && oldval == SemTaken) || __strex(SemTaken, &s) != 0 ); + if ( !block ) __clrex(); // clear exclusive lock set by ldrex +#else // on arm7 there's only swp + do { + // swp sets the pointed data to the given value and returns the previous one + oldval = __swp(SemTaken, &s); + // if blocking, loop until the previous value becomes 0 + // which would mean we have successfully taken the lock + } + while (block && oldval == SemTaken); +#endif + return oldval == SemFree; + } + + // release the semaphore + void Semaphore::release() + { + s = SemFree; + } + \ No newline at end of file