Example #1
0
void hsThread::Start()
{
    if (fThreadH == nil)
    {
        fQuitSemaH = ::CreateSemaphore(nil, 0, kPosInfinity32, nil);
        if (fQuitSemaH == nil)
            throw hsOSException(-1);
        WinThreadParam* wtp = new WinThreadParam(this, fQuitSemaH);
        fThreadH = (HANDLE)_beginthreadex(nil, fStackSize, gEntryPointBT, wtp, 0, (unsigned int*)&fThreadId);
        if (fThreadH == nil)
            throw hsOSException(-1);
    }
}
Example #2
0
hsGlobalSemaphore::hsGlobalSemaphore(int initialValue, const char* name)
{
#ifdef USE_SEMA
    fPSema = nil;
    if ((fNamed = (name != nil))) {
        /* Named semaphore shared between processes */
        fPSema = sem_open(name, O_CREAT, 0666, initialValue);
        if (fPSema == SEM_FAILED)
        {
            hsAssert(0, "hsOSException");
            throw hsOSException(errno);
        }
    } else {
        /* Anonymous semaphore shared between threads */
        int shared = 0; // 1 if sharing between processes
        fPSema = new sem_t;
        int status = sem_init(fPSema, shared, initialValue);
        hsThrowIfOSErr(status);
    }
#else
    int status = ::pthread_mutex_init(&fPMutex, nil);
    hsThrowIfOSErr(status);

    status = ::pthread_cond_init(&fPCond, nil);
    hsThrowIfOSErr(status);

    fCounter = initialValue;
#endif
}
Example #3
0
hsGlobalSemaphore::hsGlobalSemaphore(int initialValue, const char *name)
{
    fSemaH = ::CreateSemaphore(nil, initialValue, kPosInfinity32, name);
    if (fSemaH == nil)
        throw hsOSException(-1);
}
Example #4
0
hsEvent::hsEvent()
{
    fEvent = ::CreateEvent(nil,true,false,nil);
    if (fEvent == nil)
        throw hsOSException(-1);
}
Example #5
0
hsMutex::hsMutex()
{
    fMutexH = ::CreateMutex(nil, false, nil);
    if (fMutexH == nil)
        throw hsOSException(-1);
}