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 PicoTCP by
Diff: include/PicoCondition.h
- Revision:
- 5:445d2fc04784
- Child:
- 13:c6662adea07d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/PicoCondition.h Fri May 31 11:34:03 2013 +0000 @@ -0,0 +1,44 @@ +#ifndef __PICOMUTEX__ +#define __PICOMUTEX__ +/* +* Cross-Threading Mutex Class +*/ + +#include "mbed.h" +#include "rtos.h" +#include "Queue.h" + +class PicoCondition +{ + private: + Queue <int,1> * queue; + public: + PicoCondition() + { + queue = new Queue<int,1>(); + } + + ~PicoCondition() + { + if(queue) + { + delete queue; + queue = NULL; + } + } + + bool unlock(uint32_t millisec=0,int * ptr=NULL) + { + osStatus status = queue->put(ptr, millisec); + return (status == osEventMessage || status == osOK); + } + + bool lock(uint32_t millisec=osWaitForever) + { + osEvent event = queue->get(millisec); + return (event.status == osEventMessage || event.status == osOK); + } +}; + + +#endif \ No newline at end of file