diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-04-05 22:57:45 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-04-05 22:57:45 +0000 |
commit | 0cd6f180701a35abe5da0f4b0272b3047c03e330 (patch) | |
tree | b125489be5670eb775dd43f96236744eaedf9ef3 /plugins/Dbx_kyoto/src/kyotocabinet/kcthread.h | |
parent | 56e1f721234e3f6d1ef3eb8cff2dc3f322c2b831 (diff) |
various speed optimizations
git-svn-id: http://svn.miranda-ng.org/main/trunk@12621 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_kyoto/src/kyotocabinet/kcthread.h')
-rw-r--r-- | plugins/Dbx_kyoto/src/kyotocabinet/kcthread.h | 375 |
1 files changed, 3 insertions, 372 deletions
diff --git a/plugins/Dbx_kyoto/src/kyotocabinet/kcthread.h b/plugins/Dbx_kyoto/src/kyotocabinet/kcthread.h index 7b77bbd909..e570411ec4 100644 --- a/plugins/Dbx_kyoto/src/kyotocabinet/kcthread.h +++ b/plugins/Dbx_kyoto/src/kyotocabinet/kcthread.h @@ -209,373 +209,6 @@ class SlottedMutex { /** - * Lightweight mutual exclusion device. - */ -class SpinLock { - public: - /** - * Default constructor. - */ - explicit SpinLock(); - /** - * Destructor. - */ - ~SpinLock(); - /** - * Get the lock. - */ - void lock(); - /** - * Try to get the lock. - * @return true on success, or false on failure. - */ - bool lock_try(); - /** - * Release the lock. - */ - void unlock(); - private: - /** Dummy constructor to forbid the use. */ - SpinLock(const SpinLock&); - /** Dummy Operator to forbid the use. */ - SpinLock& operator =(const SpinLock&); - /** Opaque pointer. */ - void* opq_; -}; - - -/** - * Scoped spin lock device. - */ -class ScopedSpinLock { - public: - /** - * Constructor. - * @param spinlock a spin lock to lock the block. - */ - explicit ScopedSpinLock(SpinLock* spinlock) : spinlock_(spinlock) { - _assert_(spinlock); - spinlock_->lock(); - } - /** - * Destructor. - */ - ~ScopedSpinLock() { - _assert_(true); - spinlock_->unlock(); - } - private: - /** Dummy constructor to forbid the use. */ - ScopedSpinLock(const ScopedSpinLock&); - /** Dummy Operator to forbid the use. */ - ScopedSpinLock& operator =(const ScopedSpinLock&); - /** The inner device. */ - SpinLock* spinlock_; -}; - - -/** - * Slotted spin lock devices. - */ -class SlottedSpinLock { - public: - /** - * Constructor. - * @param slotnum the number of slots. - */ - explicit SlottedSpinLock(size_t slotnum); - /** - * Destructor. - */ - ~SlottedSpinLock(); - /** - * Get the lock of a slot. - * @param idx the index of a slot. - */ - void lock(size_t idx); - /** - * Release the lock of a slot. - * @param idx the index of a slot. - */ - void unlock(size_t idx); - /** - * Get the locks of all slots. - */ - void lock_all(); - /** - * Release the locks of all slots. - */ - void unlock_all(); - private: - /** Opaque pointer. */ - void* opq_; -}; - - -/** - * Reader-writer locking device. - */ -class RWLock { - public: - /** - * Default constructor. - */ - explicit RWLock(); - /** - * Destructor. - */ - ~RWLock(); - /** - * Get the writer lock. - */ - void lock_writer(); - /** - * Try to get the writer lock. - * @return true on success, or false on failure. - */ - bool lock_writer_try(); - /** - * Get a reader lock. - */ - void lock_reader(); - /** - * Try to get a reader lock. - * @return true on success, or false on failure. - */ - bool lock_reader_try(); - /** - * Release the lock. - */ - void unlock(); - private: - /** Dummy constructor to forbid the use. */ - RWLock(const RWLock&); - /** Dummy Operator to forbid the use. */ - RWLock& operator =(const RWLock&); - /** Opaque pointer. */ - void* opq_; -}; - - -/** - * Scoped reader-writer locking device. - */ -class ScopedRWLock { - public: - /** - * Constructor. - * @param rwlock a rwlock to lock the block. - * @param writer true for writer lock, or false for reader lock. - */ - explicit ScopedRWLock(RWLock* rwlock, bool writer) : rwlock_(rwlock) { - _assert_(rwlock); - if (writer) { - rwlock_->lock_writer(); - } else { - rwlock_->lock_reader(); - } - } - /** - * Destructor. - */ - ~ScopedRWLock() { - _assert_(true); - rwlock_->unlock(); - } - private: - /** Dummy constructor to forbid the use. */ - ScopedRWLock(const ScopedRWLock&); - /** Dummy Operator to forbid the use. */ - ScopedRWLock& operator =(const ScopedRWLock&); - /** The inner device. */ - RWLock* rwlock_; -}; - - -/** - * Slotted reader-writer lock devices. - */ -class SlottedRWLock { - public: - /** - * Constructor. - * @param slotnum the number of slots. - */ - explicit SlottedRWLock(size_t slotnum); - /** - * Destructor. - */ - ~SlottedRWLock(); - /** - * Get the writer lock of a slot. - * @param idx the index of a slot. - */ - void lock_writer(size_t idx); - /** - * Get the reader lock of a slot. - * @param idx the index of a slot. - */ - void lock_reader(size_t idx); - /** - * Release the lock of a slot. - * @param idx the index of a slot. - */ - void unlock(size_t idx); - /** - * Get the writer locks of all slots. - */ - void lock_writer_all(); - /** - * Get the reader locks of all slots. - */ - void lock_reader_all(); - /** - * Release the locks of all slots. - */ - void unlock_all(); - private: - /** Opaque pointer. */ - void* opq_; -}; - - -/** - * Lightweight reader-writer locking device. - */ -class SpinRWLock { - public: - /** - * Default constructor. - */ - explicit SpinRWLock(); - /** - * Destructor. - */ - ~SpinRWLock(); - /** - * Get the writer lock. - */ - void lock_writer(); - /** - * Try to get the writer lock. - * @return true on success, or false on failure. - */ - bool lock_writer_try(); - /** - * Get a reader lock. - */ - void lock_reader(); - /** - * Try to get a reader lock. - * @return true on success, or false on failure. - */ - bool lock_reader_try(); - /** - * Release the lock. - */ - void unlock(); - /** - * Promote a reader lock to the writer lock. - * @return true on success, or false on failure. - */ - bool promote(); - /** - * Demote the writer lock to a reader lock. - */ - void demote(); - private: - /** Dummy constructor to forbid the use. */ - SpinRWLock(const SpinRWLock&); - /** Dummy Operator to forbid the use. */ - SpinRWLock& operator =(const SpinRWLock&); - /** Opaque pointer. */ - void* opq_; -}; - - -/** - * Scoped reader-writer locking device. - */ -class ScopedSpinRWLock { - public: - /** - * Constructor. - * @param srwlock a spin rwlock to lock the block. - * @param writer true for writer lock, or false for reader lock. - */ - explicit ScopedSpinRWLock(SpinRWLock* srwlock, bool writer) : srwlock_(srwlock) { - _assert_(srwlock); - if (writer) { - srwlock_->lock_writer(); - } else { - srwlock_->lock_reader(); - } - } - /** - * Destructor. - */ - ~ScopedSpinRWLock() { - _assert_(true); - srwlock_->unlock(); - } - private: - /** Dummy constructor to forbid the use. */ - ScopedSpinRWLock(const ScopedSpinRWLock&); - /** Dummy Operator to forbid the use. */ - ScopedSpinRWLock& operator =(const ScopedSpinRWLock&); - /** The inner device. */ - SpinRWLock* srwlock_; -}; - - -/** - * Slotted lightweight reader-writer lock devices. - */ -class SlottedSpinRWLock { - public: - /** - * Constructor. - * @param slotnum the number of slots. - */ - explicit SlottedSpinRWLock(size_t slotnum); - /** - * Destructor. - */ - ~SlottedSpinRWLock(); - /** - * Get the writer lock of a slot. - * @param idx the index of a slot. - */ - void lock_writer(size_t idx); - /** - * Get the reader lock of a slot. - * @param idx the index of a slot. - */ - void lock_reader(size_t idx); - /** - * Release the lock of a slot. - * @param idx the index of a slot. - */ - void unlock(size_t idx); - /** - * Get the writer locks of all slots. - */ - void lock_writer_all(); - /** - * Get the reader locks of all slots. - */ - void lock_reader_all(); - /** - * Release the locks of all slots. - */ - void unlock_all(); - private: - /** Opaque pointer. */ - void* opq_; -}; - - -/** * Condition variable. */ class CondVar { @@ -934,21 +567,21 @@ class AtomicInt64 { /** * Default constructor. */ - explicit AtomicInt64() : value_(0), lock_() { + explicit AtomicInt64() : value_(0) { _assert_(true); } /** * Copy constructor. * @param src the source object. */ - AtomicInt64(const AtomicInt64& src) : value_(src.get()), lock_() { + AtomicInt64(const AtomicInt64& src) : value_(src.get()) { _assert_(true); }; /** * Constructor. * @param num the initial value. */ - AtomicInt64(int64_t num) : value_(num), lock_() { + AtomicInt64(int64_t num) : value_(num) { _assert_(true); } /** @@ -1047,8 +680,6 @@ class AtomicInt64 { private: /** The value. */ volatile int64_t value_; - /** The alternative lock. */ - mutable SpinLock lock_; }; |