From 76b6b11c3a197c01659f3f60627cc83157192e04 Mon Sep 17 00:00:00 2001 From: haodong Date: Thu, 24 Mar 2016 22:18:18 -0400 Subject: [PATCH] use atomic compare and swap to avoid mutex lock Signed-off-by: Haodong Tang --- src/os/bluestore/KernelDevice.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/os/bluestore/KernelDevice.cc b/src/os/bluestore/KernelDevice.cc index 6a226f97a7d..c0a344cc070 100644 --- a/src/os/bluestore/KernelDevice.cc +++ b/src/os/bluestore/KernelDevice.cc @@ -176,15 +176,12 @@ void KernelDevice::close() int KernelDevice::flush() { - // serialize flushers, so that we can avoid weird io_since_flush - // races (w/ multipler flushers). - Mutex::Locker l(flush_lock); - if (io_since_flush.read() == 0) { + bool ret = io_since_flush.compare_and_swap(1, 0); + if (!ret) { dout(10) << __func__ << " no-op (no ios since last flush)" << dendl; return 0; } dout(10) << __func__ << " start" << dendl; - io_since_flush.set(0); if (g_conf->bdev_inject_crash) { ++injecting_crash; // sleep for a moment to give other threads a chance to submit or -- 2.47.3