Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LcdWindow by
Diff: semaphore.cpp
- Revision:
- 9:2fe93daa2106
- Parent:
- 3:e5d5e2fe4bf6
- Child:
- 10:d40c70908bf0
--- a/semaphore.cpp Mon Jan 10 22:57:59 2011 +0000
+++ b/semaphore.cpp Tue Feb 22 22:57:44 2011 +0000
@@ -5,35 +5,33 @@
#include "semaphore.h"
- Semaphore::Semaphore(): s(SemFree) {};
-
- bool Semaphore::take(bool block)
- {
+Semaphore::Semaphore(): s(SemFree) {};
+bool Semaphore::_abort=false;
+
+bool Semaphore::take(bool block) {
+ if (_abort)
+ block=false;
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 );
+ // 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);
+ // 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()
- {
+}
+
+// release the semaphore
+void Semaphore::release() {
s = SemFree;
- }
-
\ No newline at end of file
+}
