本文整理汇总了C++中boost::atomic::compare_exchange_strong方法的典型用法代码示例。如果您正苦于以下问题:C++ atomic::compare_exchange_strong方法的具体用法?C++ atomic::compare_exchange_strong怎么用?C++ atomic::compare_exchange_strong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::atomic
的用法示例。
在下文中一共展示了atomic::compare_exchange_strong方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compare_exchange
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;
}
示例2: default_executor
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();
}
示例3: push_back
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);
}
示例4: setIfEquals
/** 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); }