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
semaphore.cpp
00001 /** 00002 * code from Igor Skochinsky 00003 * taken from http://mbed.org/forum/mbed/post/799/ 00004 */ 00005 00006 #include "semaphore.h" 00007 00008 Semaphore::Semaphore(): s(SemFree) {}; 00009 bool Semaphore::_abort=false; 00010 00011 bool Semaphore::take(bool block) { 00012 if (_abort) 00013 block=false; 00014 int oldval; 00015 /* 00016 #if defined(TARGET_LPC1768) // on Cortex-M3 we can use ldrex/strex 00017 do { 00018 // read the semaphore value 00019 oldval = __ldrex(&s); 00020 // loop again if it is locked and we are blocking 00021 // or setting it with strex failed 00022 } while ( (block && oldval == SemTaken) || __strex(SemTaken, &s) != 0 ); 00023 if ( !block ) __clrex(); // clear exclusive lock set by ldrex 00024 #else // on arm7 there's only swp 00025 00026 do { 00027 // swp sets the pointed data to the given value and returns the previous one 00028 oldval = __swp(SemTaken, &s); 00029 // if blocking, loop until the previous value becomes 0 00030 // which would mean we have successfully taken the lock 00031 } while (block && oldval == SemTaken); 00032 //#endif 00033 00034 return oldval == SemFree; 00035 */ 00036 return true; 00037 } 00038 00039 // release the semaphore 00040 void Semaphore::release() { 00041 s = SemFree; 00042 }
Generated on Tue Jul 12 2022 20:32:52 by
1.7.2
