proxygen
Hazptr.h File Reference

Go to the source code of this file.

Functions

*U get_config (V v)
 
***void update_config (Config *new_config)
 
**Optimized Holders **The template hazptr_array< M > provides most of the functionality *of M hazptr_holder s but with faster construction destruction *for at the cost of restrictions (on move and swap).*-The template hazptr_local< M > provides greater speed even when *M
 
**Optimized Holders **The template hazptr_array< M > provides most of the functionality *of M hazptr_holder s but with faster construction destruction *for at the cost of if then it *can be faster (by~3 ns.) to use *hazptr_local< 1 > h
 

Variables

***std::atomic< Config * > config_
 
**Optimized Holders **The template hazptr_array< M > provides most of the functionality *of M hazptr_holder s but with faster construction destruction *for M
 
*Config * ptr = h[0].get_protected(config_)
 
*than *hazptr_holder h
 

Function Documentation

* * Optimized Holders* * The template hazptr_array<M> provides most of the functionality* of M hazptr_holder s but with faster construction destruction* for at the cost of if then it* can be faster ( by~3  ns.)
***U get_config ( v)

Hazard pointers is a safe reclamation method. It protects objects from being reclaimed while being accessed by one or more threads, but allows objects to be removed concurrently while being accessed.

What is a Hazard Pointer?

A hazard pointer is a single-writer multi-reader pointer that can be owned by at most one thread at a time. To protect an object A from being reclaimed while in use, a thread X sets one of its owned hazard pointers, P, to the address of A. If P is set to &A before A is removed (i.e., it becomes unreachable) then A will not be reclaimed as long as P continues to hold the value &A.

Why use hazard pointers?

  • Speed and scalability.
  • Can be used while blocking.

When not to use hazard pointers?

  • When thread local data is not supported efficiently.

Basic Interface

  • In the hazptr library, raw hazard pointers are not exposed to users. Instead, each instance of the class hazptr_holder owns and manages at most one hazard pointer.
  • Typically classes of objects protected by hazard pointers are derived from a class template hazptr_obj_base that provides a member function retire(). When an object A is removed, A.retire() is called to pass responsibility for reclaiming A to the hazptr library. A will be reclaimed only after it is not protected by hazard pointers.
  • The essential components of the hazptr API are: o hazptr_holder: Class that owns and manages a hazard pointer. o get_protected: Mmember function of hazptr_holder. Protects an object pointed to by an atomic source (if not null). T* get_protected(const atomic<T*>& src); o hazptr_obj_base<T>: Base class for protected objects. o retire: Member function of hazptr_obj_base that automatically reclaims the object when safe. void retire();

Default Domain and Default Deleters

  • Most uses do not need to specify custom domains and custom deleters, and by default use the default domain and default deleters.

Simple usage example

class Config : public hazptr_obj_base<Config> { /* ... details ...

Definition at line 85 of file Hazptr.h.

* * Optimized Holders* * The template hazptr_array<M> provides most of the functionality* of M hazptr_holder s but with faster construction destruction* for at the cost of restrictions ( on move and  swap)
* * * void update_config ( Config *  new_config)

Definition at line 95 of file Hazptr.h.

Variable Documentation

* * * std::atomic<Config*> config_
* than* hazptr_holder h

Definition at line 116 of file Hazptr.h.

Referenced by folly::hazptr_domain< DeterministicAtomic >::acquire_new_hprec(), proxygen::QueueTest::addTransaction(), array_test(), folly::test::atomic_notify_one(), auto_retire_test(), folly::coro::detail::InlineTaskPromiseBase::FinalAwaiter::await_suspend(), basic_holders_test(), basic_protection_test(), wangle::ServerBootstrap< DefaultPipeline >::childHandler(), cleanup_test(), folly::cUnescape(), proxygen::HTTPMessage::describe(), folly::detail::ConcurrentHashMapSegment< KeyType, ValueType, ShardBits, HashFn, KeyEqual, Allocator, Atom, Mutex >::erase_internal(), folly::detail::ConcurrentHashMapSegment< KeyType, ValueType, ShardBits, HashFn, KeyEqual, Allocator, Atom, Mutex >::find(), folly::IOThreadPoolExecutor::getEventBase(), folly::detail::MemoryIdler::getVariationTimeout(), folly::io::test::DataHolder::hash(), folly::dynamic::hash(), folly::hash::hash_combine_generic(), folly::io::test::hashIOBuf(), folly::hazptr_array< 3, Atom >::hazptr_array(), folly::hazptr_local< M, Atom >::hazptr_local(), holder_bench(), folly::symbolizer::ElfFile::init(), folly::detail::ConcurrentHashMapSegment< KeyType, ValueType, ShardBits, HashFn, KeyEqual, Allocator, Atom, Mutex >::insert_internal(), folly::AtomicUnorderedInsertMap< Key, Value, Hash, KeyEqual, SkipKeyValueDeletion, Atom, IndexType, Allocator >::keyToSlotIdx(), folly::IndexedMemPool< T, NumLocalLists_, LocalListLimit_, Atom, Traits >::localPop(), folly::IndexedMemPool< T, NumLocalLists_, LocalListLimit_, Atom, Traits >::localPush(), folly::LogCategoryConfig::LogCategoryConfig(), folly::makeExpected(), folly::makePromiseContract(), testing::gmock_generated_function_mockers_test::MockFoo::MockFoo(), proxygen::HTTPServerAcceptor::newHandler(), proxygen::RejectConnectFilterFactory::onRequest(), proxygen::ZlibServerFilterFactory::onRequest(), hash< folly::Optional< T > >::operator()(), proxygen::operator<<(), folly::hazptr_array< 3, Atom >::operator=(), folly::hazptr_array< 3, Atom >::operator[](), folly::hazptr_local< M, Atom >::operator[](), folly::ConcurrentHashMap< KeyType, ValueType, HashFn, KeyEqual, Allocator, ShardBits, Atom, Mutex >::pickSegment(), folly::HazptrLockFreeLIFO< T, Atom >::pop(), proxygen::compress::prepareHeaders(), folly::UnboundedQueue< T, false, 6 >::reclaimRemainingSegments(), folly::netops::recvfrom(), folly::netops::recvmsg(), folly::detail::ConcurrentHashMapSegment< KeyType, ValueType, ShardBits, HashFn, KeyEqual, Allocator, Atom, Mutex >::rehash(), folly::hazptr_domain< DeterministicAtomic >::relaxed_cleanup(), folly::Getcpu::resolveVdsoFunc(), folly::netops::sendmsg(), proxygen::HTTP2PriorityQueue::setMaxVirtualNodes(), folly::AsyncServerSocket::setShutdownSocketSet(), folly::detail::SkipListNode< T >::setSkip(), folly::detail::LifoSemBase< BatonType, Atom >::shutdown(), FooLongSleep::start(), TEST(), TEST_F(), TestDeltas(), wangle::ServerWorkerPool::threadStarted(), folly::PicoSpinLock< uintptr_t >::try_lock(), folly::PicoSpinLock< uintptr_t >::unlock(), folly::detail::LifoSemBase< BatonType, Atom >::valueGuess(), testing::gmock_generated_function_mockers_test::FooInterface::~FooInterface(), folly::hazptr_array< 3, Atom >::~hazptr_array(), and folly::hazptr_local< M, Atom >::~hazptr_local().

* * Optimized Holders* * The template hazptr_array<M> provides most of the functionality* of M hazptr_holder s but with faster construction destruction* for M

Definition at line 104 of file Hazptr.h.

Referenced by array_dtor_full_tc_test(), folly::BasicFixedString< Char, N >::assign(), folly::BasicFixedString< Char, N >::BasicFixedString(), testing::internal::MatcherCastImpl< T, M >::Cast(), testing::internal::MatcherCastImpl< T, Matcher< T > >::Cast(), testing::SafeMatcherCastImpl< T >::Cast(), folly::constexpr_add_overflow_clamped(), folly::constexpr_sub_overflow_clamped(), folly::get_default(), folly::hazptr_array< 3, Atom >::hazptr_array(), folly::hazptr_local< M, Atom >::hazptr_local(), IntArray< M >::IntArray(), folly::invoke(), folly::lock(), testing::internal::BoundSecondMatcher< Tuple2Matcher, Second >::Impl< T >::MatchAndExplain(), folly::LockedPtr< SynchronizedType, LockPolicy >::moveFromWriteToRead(), testing::internal::ContainsMatcher< M >::operator Matcher< Container >(), testing::internal::EachMatcher< M >::operator Matcher< Container >(), testing::internal::KeyMatcher< M >::operator Matcher< PairType >(), std::hash< TestStruct >::operator()(), testing::internal::MatcherAsPredicate< M >::operator()(), testing::internal::PredicateFormatterFromMatcher< M >::operator()(), folly::F14VectorMap< Key, Mapped, Hasher, KeyEqual, Alloc >::operator=(), folly::hazptr_array< 3, Atom >::operator=(), folly::BasicFixedString< Char, N >::operator=(), folly::hazptr_array< 3, Atom >::operator[](), folly::hazptr_local< M, Atom >::operator[](), wangle::ByteToMessageDecoder< T >::read(), folly::rlock(), folly::test::run_test(), runSingleInsert(), runVisitContiguousRangesTest(), folly::SharedPromise< folly::folly::Unit >::setValue(), folly::Promise< folly::folly::Unit >::setValue(), TEST(), TEST_F(), TestInitGoogleMock(), folly::ulock(), folly::hazptr_array< 3, Atom >::~hazptr_array(), and folly::hazptr_local< M, Atom >::~hazptr_local().

* Config* ptr = h[0].get_protected(config_)

Definition at line 114 of file Hazptr.h.