mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-17 01:16:52 +01:00
Support for MacOS
Split semaphore classes into Semaphore and NamedSemaphore Semaphore is implemented with Grand Central Dispatch NamedSemaphore uses the spin lock approach like in boost for sem_timedwait sem_getvalue is not supported on MacOS and therefore was removed Fixed bug (*gatewayaddress_len > 0) in MQTTSNSearchClient.c Signed-off-by: Jochen Wilhelmy <jochen.wilhelmy@gmail.com>
This commit is contained in:
@@ -19,6 +19,9 @@
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#ifdef __APPLE__
|
||||
#include <dispatch/dispatch.h>
|
||||
#endif
|
||||
#include "MQTTSNGWDefines.h"
|
||||
|
||||
namespace MQTTSNGW
|
||||
@@ -52,17 +55,34 @@ private:
|
||||
class Semaphore
|
||||
{
|
||||
public:
|
||||
Semaphore();
|
||||
Semaphore(unsigned int val);
|
||||
Semaphore(const char* name, unsigned int val);
|
||||
Semaphore(unsigned int val = 0);
|
||||
~Semaphore();
|
||||
void post(void);
|
||||
void wait(void);
|
||||
void timedwait(uint16_t millsec);
|
||||
|
||||
private:
|
||||
#ifdef __APPLE__
|
||||
dispatch_semaphore_t _sem;
|
||||
#else
|
||||
sem_t _sem;
|
||||
#endif
|
||||
};
|
||||
|
||||
/*=====================================
|
||||
Class NamedSemaphore
|
||||
====================================*/
|
||||
class NamedSemaphore
|
||||
{
|
||||
public:
|
||||
NamedSemaphore(const char* name, unsigned int val);
|
||||
~NamedSemaphore();
|
||||
void post(void);
|
||||
void wait(void);
|
||||
void timedwait(uint16_t millsec);
|
||||
|
||||
private:
|
||||
sem_t* _psem;
|
||||
sem_t _sem;
|
||||
char* _name;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user