8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-24 01:23:03 +01:00

Mac port - use dispatch semaphores

This commit is contained in:
alexpeshkoff 2010-06-08 13:18:45 +00:00
parent 7a69886c3b
commit ef56abd46e
2 changed files with 10 additions and 18 deletions

View File

@ -33,23 +33,18 @@ namespace Firebird {
#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()
{
machErrorCheck(semaphore_create(mach_task_self(), &sem, SYNC_POLICY_FIFO, 0),
"semaphore_create");
semaphore = dispatch_semaphore_create(0);
if (!semaphore) // With const zero parameter this means OOM
{
BadAlloc::raise();
}
}
SignalSafeSemaphore::~SignalSafeSemaphore()
{
machErrorCheck(semaphore_destroy(mach_task_self(), sem), "semaphore_destroy");
dispatch_release(semaphore);
}
#endif // COMMON_CLASSES_SEMAPHORE_MACH

View File

@ -93,9 +93,7 @@ public:
// Mach semaphore
#define COMMON_CLASSES_SEMAPHORE_MACH
#include <mach/mach.h>
#include <mach/semaphore.h>
#include <mach/task.h>
#include <dispatch/dispatch.h>
namespace Firebird
{
@ -105,9 +103,8 @@ class MemoryPool;
class SignalSafeSemaphore
{
private:
semaphore_t sem;
dispatch_semaphore_t semaphore;
static void machErrorCheck(kern_return_t rc, const char* function);
void init();
public:
@ -118,7 +115,7 @@ public:
void enter()
{
machErrorCheck(semaphore_wait(sem), "semaphore_wait");
dispatch_semaphore_wait(semaphore);
}
void release(SLONG count = 1)
@ -126,7 +123,7 @@ public:
fb_assert(count >= 0);
while (count--)
{
machErrorCheck(semaphore_signal(sem), "semaphore_signal");
dispatch_semaphore_signal(semaphore);
}
}
};