From: haodong Date: Fri, 25 Mar 2016 02:18:18 +0000 (-0400) Subject: use atomic compare and swap to avoid mutex lock X-Git-Tag: v11.0.0~639^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F8194%2Fhead;p=ceph.git use atomic compare and swap to avoid mutex lock Signed-off-by: Haodong Tang --- 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