bool compare_exchange(T* expected, T* desired, T** old = NULL) {
		bool success = ptr.compare_exchange_strong(expected, desired);
		if(success && expected != desired) {
			intrusive_ptr_add_ref(desired);
			intrusive_ptr_release(expected);
		}
		if(old)
			*old = expected;
		return success;
	}
Exemple #2
0
 inline bool interlocked_bit_test_and_set(boost::atomic<T>& x, long bit)
 {
     T const value = 1u << bit;
     boost::uint32_t old = x.load(boost::memory_order_acquire);
     do {
         boost::uint32_t tmp = old;
         if (x.compare_exchange_strong(tmp, T(old | value)))
             break;
         old = tmp;
     } while(true);
     return (old & value) != 0;
 }
Exemple #3
0
    scheduled_executor default_executor()
    {
        if (!default_executor_instance.load())
        {
            scheduled_executor& default_exec =
                scheduled_executor::default_executor();
            scheduled_executor empty_exec;

            default_executor_instance.compare_exchange_strong(
                empty_exec, default_exec);
        }
        return default_executor_instance.load();
    }
Exemple #4
0
	void push_back(T elem) {
		// Construct an element to hold it
		synclist_item<T>* itm = new synclist_item<T>();
		itm->value = elem;
		itm->prev.store(m_last.load(boost::memory_order_release), boost::memory_order_acquire);
		itm->next.store(NULL, boost::memory_order_acquire);

		// Insert the element in the list
		synclist_item<T>* tmpItm = itm;
		synclist_item<T>* prevLast = m_last.exchange(tmpItm, boost::memory_order_consume);
		tmpItm = itm;
		synclist_item<T>* null = NULL;
		m_first.compare_exchange_strong(null, tmpItm, boost::memory_order_consume, boost::memory_order_acquire);
		if(prevLast != NULL) {
			prevLast->next.store(itm, boost::memory_order_consume);
		}
		m_length.fetch_add(1, boost::memory_order_consume);
	}
Exemple #5
0
 /** If value is testValue, replace it with setValue.
  * \return true if swap was performed
  */
 bool setIfEquals(T testValue, T setValue)
 { return _value.compare_exchange_strong(testValue, setValue); }