Skip to content
Permalink
Browse files
MDEV-17441 - InnoDB transition to C++11 atomics
Trivial buf_tmp_buffer_t::reserved transition.

Relaxed memory order looks suspicious when used by methods that have
acquire()/release() names. Especially if intention is to transfer some
variable or memory region from one thread to another. Or is memory
ordering guaranteed by something else, e.g. some mutex that protects
broader range of acquire/release functionality?
  • Loading branch information
Sergey Vojtovich committed Dec 27, 2018
1 parent 6a150e2 commit e976c7d
Showing 1 changed file with 6 additions and 9 deletions.
@@ -1439,10 +1439,9 @@ buf_page_encrypt_before_write(
NOTE! The definition appears here only for other modules of this
directory (buf) to see it. Do not use from outside! */

typedef struct {
private:
int32 reserved; /*!< true if this slot is reserved
*/
class buf_tmp_buffer_t {
/** whether this slot is reserved */
std::atomic<bool> reserved;
public:
byte* crypt_buf; /*!< for encryption the data needs to be
copied to a separate buffer before it's
@@ -1458,18 +1457,16 @@ typedef struct {
/** Release the slot */
void release()
{
my_atomic_store32_explicit(&reserved, false,
MY_MEMORY_ORDER_RELAXED);
reserved.store(false, std::memory_order_relaxed);
}

/** Acquire the slot
@return whether the slot was acquired */
bool acquire()
{
return !my_atomic_fas32_explicit(&reserved, true,
MY_MEMORY_ORDER_RELAXED);
return !reserved.exchange(true, std::memory_order_relaxed);
}
} buf_tmp_buffer_t;
};

/** The common buffer control block structure
for compressed and uncompressed frames */

0 comments on commit e976c7d

Please sign in to comment.