Esempio n. 1
0
/*
 * Signal a condition variable, waking up all threads waiting for it.
 */
int       
pthread_cond_broadcast(pthread_cond_t *cond)
{
	kern_return_t kern_res;
	if (cond->sig == _PTHREAD_COND_SIG_init)
	{
		int res;
		if (res = pthread_cond_init(cond, NULL))
			return (res);
	}
	if (cond->sig == _PTHREAD_COND_SIG)
	{ 
		LOCK(cond->lock);
		if (cond->waiters == 0)
		{ /* Avoid kernel call since there are no waiters... */
			UNLOCK(cond->lock);	
			return (ESUCCESS);
		}
		UNLOCK(cond->lock);
		MACH_CALL(semaphore_signal(cond->sem), kern_res);
		MACH_CALL(semaphore_signal_all(cond->sem), kern_res);
		if (kern_res == KERN_SUCCESS)
		{
			return (ESUCCESS);
		} else
		{
			return (EINVAL);
		}
	} else
		return (EINVAL); /* Not a condition variable */
}
Esempio n. 2
0
void am_agent_instance_init_unlock() {
#if defined(_WIN32)
    ReleaseSemaphore(ic_sem, 1, NULL);
#elif defined(__APPLE__)
    semaphore_signal_all(ic_sem);
#else
    sem_post(ic_sem);
#endif 
}
Esempio n. 3
0
void Semaphore::close()
{
    if (mValid)
    {
        mValid = false;
        OSMemoryBarrier();
        semaphore_signal_all(mInternal);
    }
}
Esempio n. 4
0
bool Semaphore::SignalAll()
{
	kern_return_t result = semaphore_signal_all(mSemaphore);

	if(KERN_SUCCESS != result) {
		LOGGER_WARNING("org.sbooth.AudioEngine.Semaphore", "Couldn't signal the semaphore: " << mach_error_string(result));
		return false;
	}

	return true;
}
Esempio n. 5
0
int
main(void)
{
    pthread_t     pthread1, pthread2, pthread3;
    semaphore_t*   sem = g_sem;
    kern_return_t kr;

    setbuf(stdout, NULL);

    kr = semaphore_create(mach_task_self(), &sem[0], SYNC_POLICY_FIFO, 0);
    OUT_ON_MACH_ERROR("semaphore_create", kr);

    kr = semaphore_create(mach_task_self(), &sem[1], SYNC_POLICY_FIFO, 0);
    OUT_ON_MACH_ERROR("semaphore_create", kr);

    (void)pthread_create(&pthread1, (const pthread_attr_t *)0,
                         start_routine, (void *) 0);
    printf("created thread1=%lx\n", 0);

    (void)pthread_create(&pthread2, (const pthread_attr_t *)0,
                         start_routine, (void *) 1);
    printf("created thread2=%lx\n", 1);

    (void)pthread_create(&pthread3, (const pthread_attr_t *)0,
                         start_routine, (void *) 2);
    printf("created thread3=%lx\n", 2);

    // wait until all three threads are ready
    SEMAPHORE_WAIT(sem[1], 3);

//    printf("main: about to signal thread3\n");
//    semaphore_signal_thread(sem[0], pthread_mach_thread_np(pthread3));

    // wait for thread3 to sem_signal()
//    semaphore_wait(sem[1]);

    sleep(1);
    printf("main: about to signal all threads\n");
    semaphore_signal_all(sem[0]);

    // wait for thread1 and thread2 to sem_signal()
    SEMAPHORE_WAIT(sem[1], 3);

out:
    if (sem[0])
        semaphore_destroy(mach_task_self(), sem[0]);
    if (sem[1])
        semaphore_destroy(mach_task_self(), sem[1]);

    exit(kr);
}
bool JackMachSemaphore::SignalAll()
{
    if (!fSemaphore) {
        jack_error("JackMachSemaphore::SignalAll name = %s already deallocated!!", fName);
        return false;
    }

    if (fFlush) {
        return true;
    }

    kern_return_t res;
    // When signaled several times, do not accumulate signals...
    if ((res = semaphore_signal_all(fSemaphore)) != KERN_SUCCESS) {
        jack_error("JackMachSemaphore::SignalAll name = %s err = %s", fName, mach_error_string(res));
    }
    return (res == KERN_SUCCESS);
}