Commit c44bb620 authored by Giuseppe Ottaviano's avatar Giuseppe Ottaviano Committed by Facebook Github Bot

Additional changes to MicroLock

Summary:
Changes discussed on the initial MicroLock diff, but that were
accidentally lost before commit.

Reviewed By: luciang, yfeldblum

Differential Revision: D3010789

fbshipit-source-id: 9538ebd1383d1561dd2ce210a2d05e342c6863e6
parent 9d2c7aa0
...@@ -26,7 +26,7 @@ void MicroLockCore::lockSlowPath(uint32_t oldWord, ...@@ -26,7 +26,7 @@ void MicroLockCore::lockSlowPath(uint32_t oldWord,
uint32_t slotHeldBit, uint32_t slotHeldBit,
unsigned maxSpins, unsigned maxSpins,
unsigned maxYields) { unsigned maxYields) {
unsigned newWord; uint32_t newWord;
unsigned spins = 0; unsigned spins = 0;
uint32_t slotWaitBit = slotHeldBit << 1; uint32_t slotWaitBit = slotHeldBit << 1;
......
...@@ -54,10 +54,10 @@ namespace folly { ...@@ -54,10 +54,10 @@ namespace folly {
* aliasing rules, character types may alias anything.) * aliasing rules, character types may alias anything.)
* *
* MicroLock uses a dirty trick: it actually operates on the full * MicroLock uses a dirty trick: it actually operates on the full
* word-size, word-aligned bit of memory into which it is embedded. * 32-bit, four-byte-aligned bit of memory into which it is embedded.
* It never modifies bits outside the ones it's defined to modify, but * It never modifies bits outside the ones it's defined to modify, but
* it _accesses_ all the bits in the word for purposes of * it _accesses_ all the bits in the 32-bit memory location for
* futex management. * purposes of futex management.
* *
* The MaxSpins template parameter controls the number of times we * The MaxSpins template parameter controls the number of times we
* spin trying to acquire the lock. MaxYields controls the number of * spin trying to acquire the lock. MaxYields controls the number of
...@@ -86,9 +86,12 @@ namespace folly { ...@@ -86,9 +86,12 @@ namespace folly {
* *
* (The virtual dispatch benchmark is provided for scale.) * (The virtual dispatch benchmark is provided for scale.)
* *
* The contended case for MicroLock is likely to be worse compared to * While the uncontended case for MicroLock is competitive with the
* std::mutex than the contended case is. Make sure to benchmark your * glibc 2.2.0 implementation of std::mutex, std::mutex is likely to be
* particular workload. * faster in the contended case, because we need to wake up all waiters
* when we release.
*
* Make sure to benchmark your particular workload.
* *
*/ */
...@@ -100,7 +103,7 @@ class MicroLockCore { ...@@ -100,7 +103,7 @@ class MicroLockCore {
#else #else
uint8_t lock_; uint8_t lock_;
#endif #endif
inline detail::Futex<>* word() const; inline detail::Futex<>* word() const; // Well, halfword on 64-bit systems
inline uint32_t baseShift(unsigned slot) const; inline uint32_t baseShift(unsigned slot) const;
inline uint32_t heldBit(unsigned slot) const; inline uint32_t heldBit(unsigned slot) const;
inline uint32_t waitBit(unsigned slot) const; inline uint32_t waitBit(unsigned slot) const;
...@@ -128,9 +131,8 @@ inline unsigned MicroLockCore::baseShift(unsigned slot) const { ...@@ -128,9 +131,8 @@ inline unsigned MicroLockCore::baseShift(unsigned slot) const {
unsigned offset_bytes = (unsigned)((uintptr_t)&lock_ - (uintptr_t)word()); unsigned offset_bytes = (unsigned)((uintptr_t)&lock_ - (uintptr_t)word());
return kIsLittleEndian return (
? offset_bytes * CHAR_BIT + slot * 2 unsigned)(kIsLittleEndian ? offset_bytes * CHAR_BIT + slot * 2 : CHAR_BIT * (sizeof(uint32_t) - offset_bytes - 1) + slot * 2);
: CHAR_BIT * (sizeof(uint32_t) - offset_bytes - 1) + slot * 2;
} }
inline uint32_t MicroLockCore::heldBit(unsigned slot) const { inline uint32_t MicroLockCore::heldBit(unsigned slot) const {
......
...@@ -59,7 +59,7 @@ struct VirtualBase { ...@@ -59,7 +59,7 @@ struct VirtualBase {
}; };
struct VirtualImpl : VirtualBase { struct VirtualImpl : VirtualBase {
virtual void foo() { /* noop */ void foo() override { /* noop */
} }
virtual ~VirtualImpl() {} virtual ~VirtualImpl() {}
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment