From: Kefu Chai Date: Sat, 19 Sep 2020 03:00:22 +0000 (+0800) Subject: crimson/osd/object_context: add helper for acquiring locks X-Git-Tag: v16.1.0~1019^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f7e9664fd49099777fb96d3d6586f3daae54a9e6;p=ceph.git crimson/osd/object_context: add helper for acquiring locks Signed-off-by: Kefu Chai --- diff --git a/src/crimson/osd/object_context.h b/src/crimson/osd/object_context.h index a75863258af..4815a28529b 100644 --- a/src/crimson/osd/object_context.h +++ b/src/crimson/osd/object_context.h @@ -112,6 +112,32 @@ private: } public: + template + auto with_lock(RWState::State type, Func&& func) { + switch (type) { + case RWState::RWWRITE: + return seastar::with_lock(lock.for_write(), std::forward(func)); + case RWState::RWREAD: + return seastar::with_lock(lock.for_read(), std::forward(func)); + case RWState::RWEXCL: + return seastar::with_lock(lock.for_excl(), std::forward(func)); + default: + assert(0 == "noop"); + } + } + template + auto with_promoted_lock(RWState::State type, Func&& func) { + switch (type) { + case RWState::RWWRITE: + return seastar::with_lock(lock.excl_from_write(), std::forward(func)); + case RWState::RWREAD: + return seastar::with_lock(lock.excl_from_read(), std::forward(func)); + case RWState::RWEXCL: + return seastar::with_lock(lock.excl_from_excl(), std::forward(func)); + default: + assert(0 == "noop"); + } + } seastar::future<> get_lock_type(Operation *op, RWState::State type) { switch (type) { case RWState::RWWRITE: