Summary: These classes are likely to be used as static variables and can
easily be constructed with constexpr.
One that we really ought to fix is SpinLock. Sadly we have a bunch of
implementations of it some of which need initialization.
Reviewed By: @meyering
Differential Revision:
D2459355
#include <stdint.h>
#include <atomic>
#include <stdint.h>
#include <atomic>
-#include <boost/noncopyable.hpp>
#include <errno.h>
#include <assert.h>
#include <errno.h>
#include <assert.h>
/// a much more restrictive lifecycle we can also add a bunch of assertions
/// that can help to catch race conditions ahead of time.
template <template<typename> class Atom = std::atomic>
/// a much more restrictive lifecycle we can also add a bunch of assertions
/// that can help to catch race conditions ahead of time.
template <template<typename> class Atom = std::atomic>
-struct Baton : boost::noncopyable {
- Baton() : state_(INIT) {}
+struct Baton {
+ constexpr Baton() : state_(INIT) {}
+
+ Baton(Baton const&) = delete;
+ Baton& operator=(Baton const&) = delete;
/// It is an error to destroy a Baton on which a thread is currently
/// wait()ing. In practice this means that the waiter usually takes
/// It is an error to destroy a Baton on which a thread is currently
/// wait()ing. In practice this means that the waiter usually takes
/// See LifoSemNode for more information on how to make your own.
template <typename Handoff,
template<typename> class Atom = std::atomic>
/// See LifoSemNode for more information on how to make your own.
template <typename Handoff,
template<typename> class Atom = std::atomic>
-struct LifoSemBase : boost::noncopyable {
- explicit LifoSemBase(uint32_t initialValue = 0)
+ constexpr explicit LifoSemBase(uint32_t initialValue = 0)
: head_(LifoSemHead::fresh(initialValue)) {}
: head_(LifoSemHead::fresh(initialValue)) {}
+ LifoSemBase(LifoSemBase const&) = delete;
+ LifoSemBase& operator=(LifoSemBase const&) = delete;
+
/// Silently saturates if value is already 2^32-1
void post() {
auto idx = incrOrPop(1);
/// Silently saturates if value is already 2^32-1
void post() {
auto idx = incrOrPop(1);
template <template<typename> class Atom, class BatonType>
struct LifoSemImpl : public detail::LifoSemBase<BatonType, Atom> {
template <template<typename> class Atom, class BatonType>
struct LifoSemImpl : public detail::LifoSemBase<BatonType, Atom> {
- explicit LifoSemImpl(uint32_t v = 0)
+ constexpr explicit LifoSemImpl(uint32_t v = 0)
: detail::LifoSemBase<BatonType, Atom>(v) {}
};
: detail::LifoSemBase<BatonType, Atom>(v) {}
};
#include <atomic>
#include <string>
#include <algorithm>
#include <atomic>
#include <string>
#include <algorithm>
-#include <boost/noncopyable.hpp>
#include <sched.h>
#include <glog/logging.h>
#include <sched.h>
#include <glog/logging.h>
* UpgradeLockable concepts except the TimedLockable related locking/unlocking
* interfaces.
*/
* UpgradeLockable concepts except the TimedLockable related locking/unlocking
* interfaces.
*/
-class RWSpinLock : boost::noncopyable {
enum : int32_t { READER = 4, UPGRADED = 2, WRITER = 1 };
public:
enum : int32_t { READER = 4, UPGRADED = 2, WRITER = 1 };
public:
- RWSpinLock() : bits_(0) {}
+ constexpr RWSpinLock() : bits_(0) {}
+
+ RWSpinLock(RWSpinLock const&) = delete;
+ RWSpinLock& operator=(RWSpinLock const&) = delete;
// Lockable Concept
void lock() {
// Lockable Concept
void lock() {
template<size_t kBitWidth, bool kFavorWriter=false>
template<size_t kBitWidth, bool kFavorWriter=false>
-class RWTicketSpinLockT : boost::noncopyable {
+class RWTicketSpinLockT {
typedef detail::RWTicketIntTrait<kBitWidth> IntTraitType;
typedef typename detail::RWTicketIntTrait<kBitWidth>::FullInt FullInt;
typedef typename detail::RWTicketIntTrait<kBitWidth>::HalfInt HalfInt;
typedef detail::RWTicketIntTrait<kBitWidth> IntTraitType;
typedef typename detail::RWTicketIntTrait<kBitWidth>::FullInt FullInt;
typedef typename detail::RWTicketIntTrait<kBitWidth>::HalfInt HalfInt;
QuarterInt;
union RWTicket {
QuarterInt;
union RWTicket {
+ constexpr RWTicket() : whole(0) {}
FullInt whole;
HalfInt readWrite;
__extension__ struct {
FullInt whole;
HalfInt readWrite;
__extension__ struct {
- RWTicketSpinLockT() {
- store_release(&ticket.whole, FullInt(0));
- }
+ constexpr RWTicketSpinLockT() {}
+
+ RWTicketSpinLockT(RWTicketSpinLockT const&) = delete;
+ RWTicketSpinLockT& operator=(RWTicketSpinLockT const&) = delete;
void lock() {
if (kFavorWriter) {
void lock() {
if (kFavorWriter) {
class UpgradeHolder;
class WriteHolder;
class UpgradeHolder;
class WriteHolder;
- SharedMutexImpl() : state_(0) {}
+ constexpr SharedMutexImpl() : state_(0) {}
SharedMutexImpl(const SharedMutexImpl&) = delete;
SharedMutexImpl(SharedMutexImpl&&) = delete;
SharedMutexImpl(const SharedMutexImpl&) = delete;
SharedMutexImpl(SharedMutexImpl&&) = delete;