X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11concurrency-benchmarks.git;a=blobdiff_plain;f=gdax-orderbook-hpp%2Fdemo%2Fdependencies%2Flibcds-2.3.2%2Fcds%2Furcu%2Fgeneral_buffered.h;fp=gdax-orderbook-hpp%2Fdemo%2Fdependencies%2Flibcds-2.3.2%2Fcds%2Furcu%2Fgeneral_buffered.h;h=63d4db1ca62ad544f4be1a22ccba36725802637c;hp=0000000000000000000000000000000000000000;hb=4223430d9168223029c7639149025c79e69b4f37;hpb=7ea7751a31c0388bf888052517be181a2989b113 diff --git a/gdax-orderbook-hpp/demo/dependencies/libcds-2.3.2/cds/urcu/general_buffered.h b/gdax-orderbook-hpp/demo/dependencies/libcds-2.3.2/cds/urcu/general_buffered.h new file mode 100644 index 0000000..63d4db1 --- /dev/null +++ b/gdax-orderbook-hpp/demo/dependencies/libcds-2.3.2/cds/urcu/general_buffered.h @@ -0,0 +1,191 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef CDSLIB_URCU_GENERAL_BUFFERED_H +#define CDSLIB_URCU_GENERAL_BUFFERED_H + +#include + +namespace cds { namespace urcu { + + /// User-space general-purpose RCU with deferred buffered reclamation + /** @anchor cds_urcu_general_buffered_gc + + This is a wrapper around \p general_buffered class. + + Template arguments: + - \p Buffer - lock-free queue or lock-free bounded queue. + Default is \p cds::container::VyukovMPMCCycleQueue< retired_ptr > + - \p Lock - mutex type, default is \p std::mutex + - \p Backoff - back-off schema, default is \p cds::backoff::Default + */ + template < +#ifdef CDS_DOXGEN_INVOKED + class Buffer = cds::container::VyukovMPMCCycleQueue< retired_ptr > + ,class Lock = std::mutex + ,class Backoff = cds::backoff::Default +#else + class Buffer + ,class Lock + ,class Backoff +#endif + > + class gc< general_buffered< Buffer, Lock, Backoff > >: public details::gc_common + { + public: + typedef general_buffered< Buffer, Lock, Backoff > rcu_implementation ; ///< Wrapped URCU implementation + + typedef typename rcu_implementation::rcu_tag rcu_tag ; ///< URCU tag + typedef typename rcu_implementation::thread_gc thread_gc ; ///< Thread-side RCU part + typedef typename rcu_implementation::scoped_lock scoped_lock ; ///< Access lock class + + using details::gc_common::atomic_marked_ptr; + + public: + /// Creates URCU \p %general_buffered singleton. + gc( size_t nBufferCapacity = 256 ) + { + rcu_implementation::Construct( nBufferCapacity ); + } + + /// Destroys URCU \p %general_instant singleton + ~gc() + { + rcu_implementation::Destruct( true ); + } + + public: + /// Waits to finish a grace period and clears the buffer + /** + After grace period finished the function frees all retired pointer + from internal buffer. + */ + static void synchronize() + { + rcu_implementation::instance()->synchronize(); + } + + /// Places retired pointer <\p p, \p pFunc> to internal buffer + /** + If the buffer is full, \ref synchronize function is invoked. + */ + template + static void retire_ptr( T * p, free_retired_ptr_func pFunc ) + { + retired_ptr rp( p, pFunc ); + retire_ptr( rp ); + } + + /// Places retired pointer \p p with \p Disposer to internal buffer + /** + If the buffer is full, \ref synchronize function is invoked. + */ + template + static void retire_ptr( T * p ) + { + retire_ptr( p, cds::details::static_functor::call ); + } + + /// Places retired pointer \p p to internal buffer + /** + If the buffer is full, \ref synchronize function is invoked. + */ + static void retire_ptr( retired_ptr& p ) + { + rcu_implementation::instance()->retire_ptr(p); + } + + /// Frees chain [ \p itFirst, \p itLast) in one synchronization cycle + template + static void batch_retire( ForwardIterator itFirst, ForwardIterator itLast ) + { + rcu_implementation::instance()->batch_retire( itFirst, itLast ); + } + + /// Retires the pointer chain until \p Func returns \p nullptr retired pointer + template + static void batch_retire( Func e ) + { + rcu_implementation::instance()->batch_retire( e ); + } + + /// Acquires access lock (so called RCU reader-side lock) + /** + For safety reasons, it is better to use \ref scoped_lock class for locking/unlocking + */ + static void access_lock() + { + thread_gc::access_lock(); + } + + /// Releases access lock (so called RCU reader-side lock) + /** + For safety reasons, it is better to use \ref scoped_lock class for locking/unlocking + */ + static void access_unlock() + { + thread_gc::access_unlock(); + } + + /// Returns the threshold of internal buffer + static size_t capacity() + { + return rcu_implementation::instance()->capacity(); + } + + /// Checks if the thread is inside read-side critical section (i.e. the lock is acquired) + /** + Usually, this function is used internally to be convinced + that subsequent remove action is not lead to a deadlock. + */ + static bool is_locked() + { + return thread_gc::is_locked(); + } + + /// Forces retired object removal + /** + This function calls \ref synchronize + */ + static void force_dispose() + { + synchronize(); + } + }; + + //@cond + template<> + class gc< general_buffered_stripped >: public gc< general_buffered<>> + {}; + //@endcond + +}} // namespace cds::urcu + +#endif // #ifndef CDSLIB_URCU_GENERAL_BUFFERED_H