当前位置: 首页>>代码示例>>C++>>正文


C++ atomic::exchange方法代码示例

本文整理汇总了C++中boost::atomic::exchange方法的典型用法代码示例。如果您正苦于以下问题:C++ atomic::exchange方法的具体用法?C++ atomic::exchange怎么用?C++ atomic::exchange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost::atomic的用法示例。


在下文中一共展示了atomic::exchange方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: lock

		void lock()
		{
			while (state_.exchange(Locked, boost::memory_order_acquire) == Locked)
			{
				/* busy-wait */
			}
		}
开发者ID:Corpse89Grinder,项目名称:hostess_robot,代码行数:7,代码来源:pan_controller.hpp

示例2: overlay_initialized

/**
 * The environment should be initialised exactly once during shared library initialisation.
 * Prior to that, all operations work in pass-through mode.
 * To overcome undefined global initialisation order, we use a local static variable.
 * This variable is accesd by a single writer (lib (de)initialisation), and multiple readers (exported operations).
 * Writer: toggle == true (toggles is_initialised)
 * Reader: toggle == false (returns the current value of is_initialised)
 *
 * NOTE: pthread_once initialisation for the overlay leads to a deadlock due to a re-entry situation:
 * - environment ctor is called the first time via pthread_once
 * - which leads a write somewhere (probably to a socket during client initialisation)
 * - which then enters the pthread_once initialisation mechanism again and blocks deadlocks
 */
bool overlay_initialized(bool toggle /* defaults to: false */) {
  static boost::atomic<bool> is_initilized(false);

  // writer
  if(toggle) {
    return is_initilized.exchange(!is_initilized.load());
  }

  // reader
  return is_initilized.load();
}
开发者ID:2510,项目名称:xtreemfs,代码行数:24,代码来源:preload.cpp

示例3: unlock

            /// Attempts to acquire ownership of the \a recursive_mutex.
            /// Suspends the current HPX-thread until \a timeout if ownership cannot
            /// be obtained immediately.
            ///
            /// \returns \a true if ownership was acquired; otherwise, \a false.
            ///
            /// \throws Throws \a hpx#bad_parameter if an error occurs while
            ///         suspending. Throws \a hpx#yield_aborted if the mutex is
            ///         destroyed while suspended. Throws \a hpx#null_thread_id if
            ///         called outside of a HPX-thread.
//             template<typename Duration>
//             bool timed_lock(Duration const& timeout)
//             {
//                 return timed_lock(boost::get_system_time() + timeout);
//             }
//
//             bool timed_lock(boost::xtime const& timeout)
//             {
//                 return timed_lock(boost::posix_time::ptime(timeout));
//             }
//
            /// Release ownership of the \a recursive_mutex.
            ///
            /// \throws Throws \a hpx#bad_parameter if an error occurs while
            ///         releasing the mutex. Throws \a hpx#null_thread_id if called
            ///         outside of a HPX-thread.
            void unlock()
            {
                util::unregister_lock(this);
                if (0 == --recursion_count)
                {
                    locking_thread_id.exchange(thread_id_from_mutex<Mutex>
                        ::invalid_id());
                    util::reset_ignored(&mtx);
                    mtx.unlock();
                }
            }
开发者ID:HadrienG2,项目名称:hpx,代码行数:37,代码来源:recursive_mutex.hpp

示例4: try_basic_lock

 bool try_basic_lock(thread_id_type current_thread_id)
 {
     if (mtx.try_lock())
     {
         locking_thread_id.exchange(current_thread_id);
         util::ignore_lock(&mtx);
         util::register_lock(this);
         recursion_count.store(1);
         return true;
     }
     return false;
 }
开发者ID:HadrienG2,项目名称:hpx,代码行数:12,代码来源:recursive_mutex.hpp

示例5: lock

            /// Acquires ownership of the \a recursive_mutex. Suspends the
            /// current HPX-thread if ownership cannot be obtained immediately.
            ///
            /// \throws Throws \a hpx#bad_parameter if an error occurs while
            ///         suspending. Throws \a hpx#yield_aborted if the mutex is
            ///         destroyed while suspended. Throws \a hpx#null_thread_id if
            ///         called outside of a HPX-thread.
            void lock()
            {
                thread_id_type const id = thread_id_from_mutex<Mutex>::call();
                HPX_ASSERT(id != thread_id_from_mutex<Mutex>::invalid_id());

                if (!try_recursive_lock(id))
                {
                    mtx.lock();
                    locking_thread_id.exchange(id);
                    util::ignore_lock(&mtx);
                    util::register_lock(this);
                    recursion_count.store(1);
                }
            }
开发者ID:HadrienG2,项目名称:hpx,代码行数:21,代码来源:recursive_mutex.hpp

示例6: 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);
	}
开发者ID:atomiccheese,项目名称:wikimap,代码行数:18,代码来源:linklist.hpp

示例7: swap

	IntrusivePtr& swap(IntrusivePtr&& other) {
		T* old = ptr.exchange(other.ptr);
		other.ptr = old;
		return other;
	}
开发者ID:HikaruLim,项目名称:music-player-core,代码行数:5,代码来源:IntrusivePtr.hpp

示例8:

	~IntrusivePtr() {
		T* _p = ptr.exchange(NULL);
		if(_p)
			intrusive_ptr_release(_p);
	}
开发者ID:HikaruLim,项目名称:music-player-core,代码行数:5,代码来源:IntrusivePtr.hpp

示例9: swap

void swap( boost::atomic<T>& lhs, boost::atomic<T>& rhs )
{
    lhs.store(rhs.exchange(lhs.load()));
}
开发者ID:frederikaalund,项目名称:sfj,代码行数:4,代码来源:boost_atomic_extensions.hpp

示例10: swap

 /** Swap the atomic value with value.
  * \return the previously held value
  */
 T swap(T value)
 { return _value.exchange(value); }
开发者ID:bsautron,项目名称:libqi,代码行数:5,代码来源:atomic.hpp


注:本文中的boost::atomic::exchange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。