Example #1
0
File: rthreads.c Project: ieei/rlib
void
r_cond_broadcast (RCond * cond)
{
#if defined (R_OS_WIN32)
  WakeAllConditionVariable ((PCONDITION_VARIABLE)*cond);
#elif defined (HAVE_PTHREAD_H)
  pthread_cond_broadcast ((pthread_cond_t*)*cond);
#else
  (void) cond;
#endif
}
Example #2
0
void os_cond_broadcast(struct OsCond *cond, struct OsMutex *locked_mutex) {
#if defined(GENESIS_OS_WINDOWS)
    if (locked_mutex) {
        WakeAllConditionVariable(&cond->id);
    } else {
        EnterCriticalSection(&cond->default_cs_id);
        WakeAllConditionVariable(&cond->id);
        LeaveCriticalSection(&cond->default_cs_id);
    }
#elif defined(GENESIS_OS_KQUEUE)
#error unimplemented
#else
    if (locked_mutex) {
        assert_no_err(pthread_cond_broadcast(&cond->id));
    } else {
        assert_no_err(pthread_mutex_lock(&cond->default_mutex_id));
        assert_no_err(pthread_cond_broadcast(&cond->id));
        assert_no_err(pthread_mutex_unlock(&cond->default_mutex_id));
    }
#endif
}
Example #3
0
EXEC_RETURN condition_WakeAllThread(CONDITION* condition){
#if defined(WIN32) || defined(_WIN64)
	WakeAllConditionVariable(condition);
	return EXEC_SUCCESS;
#else
	int res = pthread_cond_broadcast(condition);
	if(res){
		errno = res;
		return EXEC_ERROR;
	}
	return EXEC_SUCCESS;
#endif
}
void NzConditionVariableImpl::SignalAll()
{
	#if NAZARA_CORE_WINDOWS_VISTA
	WakeAllConditionVariable(&m_cv);
	#else
	// Avoid race conditions.
	EnterCriticalSection(&m_countLock);
	bool haveWaiters = (m_count > 0);
	LeaveCriticalSection (&m_countLock);

	if (haveWaiters)
		SetEvent(m_events[BROADCAST]);
	#endif
}
void ThreadGate::Open(void)
{
#if defined(OVR_CAPTURE_POSIX)
    pthread_mutex_lock(&m_mutex);
    m_open = true;
    pthread_cond_broadcast(&m_cond);
    pthread_mutex_unlock(&m_mutex);
#elif defined(OVR_CAPTURE_WINDOWS)
    EnterCriticalSection(&m_cs);
    m_open = true;
    WakeAllConditionVariable(&m_cond);
    LeaveCriticalSection(&m_cs);
#endif
}
Example #6
0
void StopProcessing() {

   if (!g_fShutdown) {
      // Ask all threads to end
      InterlockedExchange(&g_fShutdown, TRUE);

      // Free all threads waiting on condition variables
      WakeAllConditionVariable(&g_cvReadyToConsume);
      WakeAllConditionVariable(&g_cvReadyToProduce);

      // Wait for all the threads to terminate & then clean up
      WaitForMultipleObjects(g_nNumThreads, g_hThreads, TRUE, INFINITE);

      // Don't forget to clean up kernel resources
      // Note: This is not really mandatory since the process is exiting
      while (g_nNumThreads--)
         CloseHandle(g_hThreads[g_nNumThreads]);

      // Close each list box
      AddText(GetDlgItem(g_hWnd, IDC_SERVERS), TEXT("---------------------"));
      AddText(GetDlgItem(g_hWnd, IDC_CLIENTS), TEXT("---------------------"));
   }
}
Example #7
0
void vlc_mutex_unlock (vlc_mutex_t *p_mutex)
{
    if (!p_mutex->dynamic)
    {   /* static mutexes */
        EnterCriticalSection(&super_mutex);
        assert (p_mutex->locked);
        p_mutex->locked = false;
        if (p_mutex->contention)
            WakeAllConditionVariable(&super_variable);
        LeaveCriticalSection(&super_mutex);
        return;
    }

    LeaveCriticalSection (&p_mutex->mutex);
}
Example #8
0
void barrier_wait(barrier_t *barrier)
{
    EnterCriticalSection(&barrier->mutex);

    barrier->counter++;
    if(barrier->counter == barrier->value) {
        barrier->counter = 0;
        WakeAllConditionVariable(&barrier->cond);
    }
    else {
        SleepConditionVariableCS(&barrier->cond, &barrier->mutex, INFINITE);
    }

    LeaveCriticalSection(&barrier->mutex);
}
extern "C" void __cdecl _Init_thread_notify()
{
#if _CRT_NTDDI_MIN < NTDDI_VISTA
    if (!__scrt_is_event_api_used(_Tss_event))
    {
        __crt_fast_decode_pointer(encoded_wake_all_condition_variable)(&_Tss_cv);
    }
    else
    {
        SetEvent(_Tss_event);
        ResetEvent(_Tss_event);
    }
#else
	WakeAllConditionVariable(&_Tss_cv);
#endif
}
Example #10
0
static void resize_slot_table(
    IN nfs41_slot_table *table,
    IN uint32_t target_highest_slotid)
{
    if (target_highest_slotid >= NFS41_MAX_NUM_SLOTS)
        target_highest_slotid = NFS41_MAX_NUM_SLOTS - 1;

    if (table->max_slots != target_highest_slotid + 1) {
        dprintf(2, "updated max_slots %u to %u\n",
            table->max_slots, target_highest_slotid + 1);
        table->max_slots = target_highest_slotid + 1;

        if (slot_table_avail(table))
            WakeAllConditionVariable(&table->cond);
    }
}
Example #11
0
/* session slot mechanism */
static void init_slot_table(nfs41_slot_table *table) 
{
    uint32_t i;
    EnterCriticalSection(&table->lock);
    table->max_slots = NFS41_MAX_NUM_SLOTS;
    for (i = 0; i < NFS41_MAX_NUM_SLOTS; i++) {
        table->seq_nums[i] = 1;
        table->used_slots[i] = 0;
    }
    table->highest_used = table->num_used = 0;
    table->target_delay = 0;

    /* wake any threads waiting on a slot */
    if (slot_table_avail(table))
        WakeAllConditionVariable(&table->cond);
    LeaveCriticalSection(&table->lock);
}
Example #12
0
int main(int argc, char **argv)
{
	int i = 0;
	int sum = 0;
	struct data_info d_info;

	DWORD dwThreadArray[THREAD_NUM];
	HANDLE hThreadArray[THREAD_NUM];

	InitializeCriticalSection(&CSLock);
	InitializeConditionVariable(&CalcReady);

	data_array = (int *)malloc(sizeof(int)*ARRAY_SIZE);

	//4개의 쓰래드를 만든다. 
	for (i = 0; i < THREAD_NUM; i++)
	{
		d_info.d_point = data_array;
		d_info.idx = i;
		hThreadArray[i] = CreateThread(NULL, 0, t_func, (void *)&d_info, 0, &dwThreadArray[i]);
		Sleep(10);
	}
	//계산할 100개으 ㅣ데이터르 ㄹ만든다.
	for (i = 0; i < ARRAY_SIZE; i++)
	{
		*data_array = i;
		*data_array++;
	}
	//데이터를 모두 만들었으면 모든 워커 스레드를 깨운다.
	WakeAllConditionVariable(&CalcReady);

	//모든 워커 스레드가 연산을 끝내고 종료하길 기다린다
	WaitForMultipleObjects(THREAD_NUM, hThreadArray, TRUE, INFINITE);

	//워커 스레드들의 연산 결과를 더해서 최종 결과를 출력한다.
	for (i = 0; i < THREAD_NUM; i++)
	{
		CloseHandle(hThreadArray[i]);
		sum += sum_array[i];
	}
	return 0;
}
Example #13
0
// Destructor
drwnThreadPool::~drwnThreadPool()
{
#ifdef DRWN_USE_PTHREADS
    // tell threads to stop
    if (!_bQuit) {
        _bQuit = true;
        pthread_mutex_lock(&_mutex);
        pthread_cond_broadcast(&_cond);
        pthread_mutex_unlock(&_mutex);

        // wait for them to finish
        for (unsigned i = 0; i < _nThreads; i++) {
            pthread_join(_threads[i], NULL);
        }
    }

    pthread_mutex_destroy(&_mutex);
    pthread_cond_destroy(&_cond);
    if (_threads != NULL) delete[] _threads;
    if (_args != NULL) delete[] _args;
#endif

#ifdef DRWN_USE_WIN32THREADS
    // tell threads to stop
    if (!_bQuit) {
        _bQuit = true;
        WakeAllConditionVariable(&_cond);

        // wait for them to finish
        for (unsigned i = 0; i < _nThreads; i++) {
            WaitForSingleObject(_threads[i], INFINITE);
            CloseHandle(_threads[i]);
        }
    }

    if (_threads != NULL) delete[] _threads;
    if (_args != NULL) delete[] _args;
#endif
}
Example #14
0
    void doSizedSend(size_t size, Args...args)
    {
        ULONG head = mHead.load();
        while(1)
        {
            ULONG rem_size = sQueueSize - head;
            if(rem_size < size)
            {
                if(rem_size >= sizeof(CommandSkip))
                {
                    doSizedSend<CommandSkip>(rem_size, rem_size);
                    head = mHead.load();
                    rem_size = sQueueSize - head;
                }
                else do {
                    doSizedSend<CommandNoOp>(sizeof(CommandNoOp));
                    head = mHead.load();
                    rem_size = sQueueSize - head;
                } while(rem_size < size);
            }
            if(((mTail-head-1)&sQueueMask) >= size)
                break;

            EnterCriticalSection(&mLock);
            WakeAllConditionVariable(&mCondVar);
            SleepConditionVariableCS(&mCondVar, &mLock, INFINITE);
            LeaveCriticalSection(&mLock);
            head = mHead.load();
        }

        Command *cmd = new(&mQueueData[head]) T(args...);
        TRACE("Sending %p\n", cmd);

        head += size;
        mHead.store(head&sQueueMask);
    }
Example #15
0
	bool signal() {
		AcquireSRWLockExclusive( &lock );
		if( waiting() ) WakeAllConditionVariable( &condition );
		ReleaseSRWLockExclusive( &lock );
		return true;
	}
Example #16
0
void
IceUtil::Cond::broadcast()
{
    WakeAllConditionVariable(&_cond);
}
//==============================================================================
void ConditionVariable::notifyAll()
{
	CONDITION_VARIABLE* cond = reinterpret_cast<CONDITION_VARIABLE*>(m_impl);
	WakeAllConditionVariable(cond);
}
Example #18
0
 __forceinline void broadcast() {
   WakeAllConditionVariable(&cond);
 }
Example #19
0
 void ConditionSys::broadcast() { WakeAllConditionVariable((CONDITION_VARIABLE*)cond); }
int pthread_cond_broadcast(pthread_cond_t *cond)
{
	WakeAllConditionVariable(cond);
	
	return 0;
}
Example #21
0
File: tutil.c Project: myaut/tsload
PLATAPI void plat_cv_notify_all(plat_thread_cv_t* cv) {
	WakeAllConditionVariable(&cv->tcv_cond_var);
}
Example #22
0
void nn_condvar_broadcast (nn_condvar_t *cond)
{
    WakeAllConditionVariable (&cond->cv);
}
Example #23
0
void gpr_cv_broadcast(gpr_cv *cv) { WakeAllConditionVariable(cv); }
inline void
ConditionBroadcast (Condition* condition)
{
    WakeAllConditionVariable(condition);
}
Example #25
0
int alcnd_broadcast(alcnd_t *cond)
{
    WakeAllConditionVariable(cond);
    return althrd_success;
}
Example #26
0
/* Broadcasts a condition
 * The of this function must be locked by the same mutex as used to wait
 * This is necessary for the WINAPI pre Vista (0x0600) implementation
 * Returns 1 if successful or -1 on error
 */
int libcthreads_condition_broadcast(
     libcthreads_condition_t *condition,
     libcerror_error_t **error )
{
	libcthreads_internal_condition_t *internal_condition = NULL;
	static char *function                                = "libcthreads_condition_broadcast";

#if defined( WINAPI ) && ( WINVER < 0x0600 )
	DWORD error_code                                     = 0;
	DWORD wait_status                                    = 0;
	BOOL result                                          = 1;
	int number_of_waiting_threads                        = 0;

#elif defined( HAVE_PTHREAD_H ) && !defined( WINAPI )
	int pthread_result                                   = 0;
#endif

	if( condition == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid condition.",
		 function );

		return( -1 );
	}
	internal_condition = (libcthreads_internal_condition_t *) condition;

#if defined( WINAPI ) && ( WINVER >= 0x0600 )
	WakeAllConditionVariable(
	 &( internal_condition->condition_variable ) );

#elif defined( WINAPI )
	EnterCriticalSection(
	 &( internal_condition->wait_critical_section ) );

	number_of_waiting_threads = internal_condition->number_of_waiting_threads;

	if( number_of_waiting_threads > 0 )
	{
		internal_condition->signal_is_broadcast = 1;

		result = ReleaseSemaphore(
		          internal_condition->signal_semaphore_handle,
		          number_of_waiting_threads,
		          0 );

		if( result == 0 )
		{
			error_code = GetLastError();

			internal_condition->signal_is_broadcast = 0;
		}
	}
	LeaveCriticalSection(
	 &( internal_condition->wait_critical_section ) );

	if( result == 0 )
	{
		libcerror_system_set_error(
		 error,
		 error_code,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
		 "%s: unable to release signal semaphore handle.",
		 function );

		return( -1 );
	}
	if( number_of_waiting_threads > 0 )
	{
		wait_status = WaitForSingleObject(
		               internal_condition->signal_event_handle,
		               INFINITE );

		if( wait_status == WAIT_FAILED )
		{
			error_code = GetLastError();

			internal_condition->signal_is_broadcast = 0;

			libcerror_system_set_error(
			 error,
			 error_code,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: wait for no read event handle failed.",
			 function );

			return( -1 );
		}
		internal_condition->signal_is_broadcast = 0;
	}

#elif defined( HAVE_PTHREAD_H )
	pthread_result = pthread_cond_broadcast(
	                  &( internal_condition->condition ) );

	if( pthread_result != 0 )
	{
		libcerror_system_set_error(
		 error,
		 pthread_result,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
		 "%s: unable to broadcast condition.",
		 function );

		return( -1 );
	}
#endif
	return( 1 );
}
Example #27
0
	void notify()
	{
		WakeAllConditionVariable(&cv);
	}
Example #28
0
void	CondVarWindows::broadcast()
{
  WakeAllConditionVariable(&this->_condvar);
}
Example #29
0
int tMPI_Thread_barrier_wait(tMPI_Thread_barrier_t *barrier)
{
    int    cycle;
    BOOL    rc=FALSE;
    int     ret=0;
    /*tMPI_Thread_pthread_barrier_t *p;*/

    /* check whether the barrier is initialized */
    if (tMPI_Atomic_get( &(barrier->initialized)  ) == 0)
    {
        tMPI_Thread_barrier_init_once(barrier,barrier->threshold);        
    }

#if 0
    EnterCriticalSection( &(barrier->barrierp->cs)  );
#else
    tMPI_Thread_mutex_lock( &(barrier->barrierp->cs) );
#endif



    cycle = barrier->cycle;

    /* Decrement the count atomically and check if it is zero.
     * This will only be true for the last thread calling us.
     */
    if( --(barrier->count) <= 0 )
    { 
        barrier->cycle = !barrier->cycle;
        barrier->count = barrier->threshold;
#if 0
        WakeAllConditionVariable( &(barrier->barrierp->cv) );
#else
        tMPI_Thread_cond_broadcast( &(barrier->barrierp->cv) );
#endif
    }
    else
    {
        while(cycle == barrier->cycle)
        {
#if 0
            rc=SleepConditionVariableCS (&(barrier->barrierp->cv), 
                                         &(barrier->barrierp->cs), 
                                         INFINITE);
            if(!rc) 
            {
                ret=-1;
                break;
            }
#else
            rc = tMPI_Thread_cond_wait(&barrier->barrierp->cv,
                                       &barrier->barrierp->cs);
            if(rc != 0) break;
#endif
        }
    }
#if 0
    LeaveCriticalSection( &(barrier->barrierp->cs)  );
#else
    tMPI_Thread_mutex_unlock( &(barrier->barrierp->cs) );
#endif
    return ret;
}
Example #30
0
 inline void CondBroadcast(ConditionVariable* var)
 {
   WakeAllConditionVariable(&var->m_Impl);
 }