Exemple #1
0
long	atomic32::operator*=(long val)
{
	long pre = value_;
	while (compare_exchange(pre * val, pre) != pre)
	{
		pre = value_;
	}

	return pre * val;
}
Exemple #2
0
void call_once(void (*func)(), once_flag& flag)
{
#if defined(BOOST_HAS_WINTHREADS)
    if (compare_exchange(&flag, 1, 1) == 0)
    {
#if defined(BOOST_NO_STRINGSTREAM)
        std::ostrstream strm;
        strm << "2AC1A572DB6944B0A65C38C4140AF2F4" 
             << std::hex
             << GetCurrentProcessId() 
             << &flag 
             << std::ends;
        unfreezer unfreeze(strm);
#   if defined (BOOST_NO_ANSI_APIS)
        USES_CONVERSION;
        HANDLE mutex = CreateMutexW(NULL, FALSE, A2CW(strm.str()));
#   else
        HANDLE mutex = CreateMutexA(NULL, FALSE, strm.str());
#   endif
#else
#   if defined (BOOST_NO_ANSI_APIS)
        std::wostringstream strm;
        strm << L"2AC1A572DB6944B0A65C38C4140AF2F4" 
             << std::hex
             << GetCurrentProcessId() 
             << &flag;
        HANDLE mutex = CreateMutexW(NULL, FALSE, strm.str().c_str());
#   else
        std::ostringstream strm;
        strm << "2AC1A572DB6944B0A65C38C4140AF2F4" 
             << std::hex
             << GetCurrentProcessId() 
             << &flag;
        HANDLE mutex = CreateMutexA(NULL, FALSE, strm.str().c_str());
#   endif
#endif
        assert(mutex != NULL);

        int res = 0;
        res = WaitForSingleObject(mutex, INFINITE);
        assert(res == WAIT_OBJECT_0);

        if (compare_exchange(&flag, 1, 1) == 0)
        {
            try
            {
                func();
            }
            catch (...)
            {
                res = ReleaseMutex(mutex);
                assert(res);
                res = CloseHandle(mutex);
                assert(res);
                throw;
            }
            InterlockedExchange(&flag, 1);
        }

        res = ReleaseMutex(mutex);
        assert(res);
        res = CloseHandle(mutex);
        assert(res);
    }
#elif defined(BOOST_HAS_PTHREADS)
    pthread_once(&once, &key_init);
    pthread_setspecific(key, &func);
    pthread_once(&flag, do_once);
#elif defined(BOOST_HAS_MPTASKS)
    if(flag == false)
    {
        // all we do here is make a remote call to blue, as blue is not
        // reentrant.
        std::pair<void (*)(), once_flag *> sData(func, &flag);
        MPRemoteCall(remote_call_proxy, &sData, kMPOwningProcessRemoteContext);
        assert(flag == true);
    }
#endif
}
Exemple #3
0
 bool clearIfEqual( const shared_ptr<T> &curvalue ) {
     shared_ptr<T> newvalue(nullptr);
     return compare_exchange(curvalue, newvalue);
 }
Exemple #4
0
 bool updatetIfNull( shared_ptr<T> newvalue ) {
     shared_ptr<T> oldvalue(nullptr);
     return compare_exchange(oldvalue, newvalue);
 }
Exemple #5
0
 bool resetIfNull( T *ptr = nullptr ) {
     shared_ptr<T> newvalue(ptr);
     shared_ptr<T> oldvalue(nullptr);
     return compare_exchange(oldvalue, newvalue);
 }
Exemple #6
0
 RL_INLINE
 bool compare_exchange_strong(T& cmp, T xchg, memory_order mo, debug_info_param info, memory_order failure_mo, debug_info_param)
 {
     return compare_exchange(bool_t<false>(), cmp, xchg, mo, failure_mo, info);
 }
Exemple #7
0
 RL_INLINE
 bool compare_exchange_weak(T& cmp, T xchg, memory_order mo, debug_info_param info)
 {
     return compare_exchange(bool_t<true>(), cmp, xchg, mo, info);
 }