mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-24 09:23:03 +01:00
Mac port - use dispatch semaphores
This commit is contained in:
parent
7a69886c3b
commit
ef56abd46e
@ -33,23 +33,18 @@ namespace Firebird {
|
|||||||
|
|
||||||
#ifdef COMMON_CLASSES_SEMAPHORE_MACH
|
#ifdef COMMON_CLASSES_SEMAPHORE_MACH
|
||||||
|
|
||||||
void SignalSafeSemaphore::machErrorCheck(kern_return_t rc, const char* fun)
|
|
||||||
{
|
|
||||||
if (rc != KERN_SUCCESS)
|
|
||||||
{
|
|
||||||
(Arg::Gds(isc_sys_request) << fun << Arg::Mach(static_cast<ISC_STATUS>(rc))).raise();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SignalSafeSemaphore::init()
|
void SignalSafeSemaphore::init()
|
||||||
{
|
{
|
||||||
machErrorCheck(semaphore_create(mach_task_self(), &sem, SYNC_POLICY_FIFO, 0),
|
semaphore = dispatch_semaphore_create(0);
|
||||||
"semaphore_create");
|
if (!semaphore) // With const zero parameter this means OOM
|
||||||
|
{
|
||||||
|
BadAlloc::raise();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SignalSafeSemaphore::~SignalSafeSemaphore()
|
SignalSafeSemaphore::~SignalSafeSemaphore()
|
||||||
{
|
{
|
||||||
machErrorCheck(semaphore_destroy(mach_task_self(), sem), "semaphore_destroy");
|
dispatch_release(semaphore);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // COMMON_CLASSES_SEMAPHORE_MACH
|
#endif // COMMON_CLASSES_SEMAPHORE_MACH
|
||||||
|
@ -93,9 +93,7 @@ public:
|
|||||||
|
|
||||||
// Mach semaphore
|
// Mach semaphore
|
||||||
#define COMMON_CLASSES_SEMAPHORE_MACH
|
#define COMMON_CLASSES_SEMAPHORE_MACH
|
||||||
#include <mach/mach.h>
|
#include <dispatch/dispatch.h>
|
||||||
#include <mach/semaphore.h>
|
|
||||||
#include <mach/task.h>
|
|
||||||
|
|
||||||
namespace Firebird
|
namespace Firebird
|
||||||
{
|
{
|
||||||
@ -105,9 +103,8 @@ class MemoryPool;
|
|||||||
class SignalSafeSemaphore
|
class SignalSafeSemaphore
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
semaphore_t sem;
|
dispatch_semaphore_t semaphore;
|
||||||
|
|
||||||
static void machErrorCheck(kern_return_t rc, const char* function);
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -118,7 +115,7 @@ public:
|
|||||||
|
|
||||||
void enter()
|
void enter()
|
||||||
{
|
{
|
||||||
machErrorCheck(semaphore_wait(sem), "semaphore_wait");
|
dispatch_semaphore_wait(semaphore);
|
||||||
}
|
}
|
||||||
|
|
||||||
void release(SLONG count = 1)
|
void release(SLONG count = 1)
|
||||||
@ -126,7 +123,7 @@ public:
|
|||||||
fb_assert(count >= 0);
|
fb_assert(count >= 0);
|
||||||
while (count--)
|
while (count--)
|
||||||
{
|
{
|
||||||
machErrorCheck(semaphore_signal(sem), "semaphore_signal");
|
dispatch_semaphore_signal(semaphore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user