From: Sage Weil Date: Wed, 27 Jan 2016 18:43:06 +0000 (-0500) Subject: os/bluestore/StupidAllocator: use std::mutex X-Git-Tag: v10.0.4~101^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8e5fbea4c29a3ceea4230cf0ad8f6f5a75a8a22c;p=ceph.git os/bluestore/StupidAllocator: use std::mutex Signed-off-by: Sage Weil --- diff --git a/src/os/bluestore/StupidAllocator.cc b/src/os/bluestore/StupidAllocator.cc index a8f70a3ec7e..4d8c5f1359c 100755 --- a/src/os/bluestore/StupidAllocator.cc +++ b/src/os/bluestore/StupidAllocator.cc @@ -10,8 +10,7 @@ #define dout_prefix *_dout << "stupidalloc " StupidAllocator::StupidAllocator() - : lock("StupicAllocator::lock"), - num_free(0), + : num_free(0), num_uncommitted(0), num_committing(0), num_reserved(0), @@ -54,7 +53,7 @@ void StupidAllocator::_insert_free(uint64_t off, uint64_t len) int StupidAllocator::reserve(uint64_t need) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " need " << need << " num_free " << num_free << " num_reserved " << num_reserved << dendl; if ((int64_t)need > num_free - num_reserved) @@ -65,7 +64,7 @@ int StupidAllocator::reserve(uint64_t need) void StupidAllocator::unreserve(uint64_t unused) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " unused " << unused << " num_free " << num_free << " num_reserved " << num_reserved << dendl; assert(num_reserved >= (int64_t)unused); @@ -89,7 +88,7 @@ int StupidAllocator::allocate( uint64_t need_size, uint64_t alloc_unit, int64_t hint, uint64_t *offset, uint32_t *length) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " need_size " << need_size << " alloc_unit " << alloc_unit << " hint " << hint @@ -204,7 +203,7 @@ int StupidAllocator::allocate( int StupidAllocator::release( uint64_t offset, uint64_t length) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " " << offset << "~" << length << dendl; uncommitted.insert(offset, length); num_uncommitted += length; @@ -213,13 +212,13 @@ int StupidAllocator::release( uint64_t StupidAllocator::get_free() { - Mutex::Locker l(lock); + std::lock_guard l(lock); return num_free; } void StupidAllocator::dump(ostream& out) { - Mutex::Locker l(lock); + std::lock_guard l(lock); for (unsigned bin = 0; bin < free.size(); ++bin) { dout(30) << __func__ << " free bin " << bin << ": " << free[bin].num_intervals() << " extents" << dendl; @@ -247,7 +246,7 @@ void StupidAllocator::dump(ostream& out) void StupidAllocator::init_add_free(uint64_t offset, uint64_t length) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " " << offset << "~" << length << dendl; _insert_free(offset, length); num_free += length; @@ -255,7 +254,7 @@ void StupidAllocator::init_add_free(uint64_t offset, uint64_t length) void StupidAllocator::init_rm_free(uint64_t offset, uint64_t length) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " " << offset << "~" << length << dendl; btree_interval_set rm; rm.insert(offset, length); @@ -281,7 +280,7 @@ void StupidAllocator::shutdown() void StupidAllocator::commit_start() { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " releasing " << num_uncommitted << " in extents " << uncommitted.num_intervals() << dendl; assert(committing.empty()); @@ -292,7 +291,7 @@ void StupidAllocator::commit_start() void StupidAllocator::commit_finish() { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " released " << num_committing << " in extents " << committing.num_intervals() << dendl; for (auto p = committing.begin(); diff --git a/src/os/bluestore/StupidAllocator.h b/src/os/bluestore/StupidAllocator.h index e5cf17d1006..1b09ace2dc9 100644 --- a/src/os/bluestore/StupidAllocator.h +++ b/src/os/bluestore/StupidAllocator.h @@ -4,12 +4,13 @@ #ifndef CEPH_OS_BLUESTORE_STUPIDALLOCATOR_H #define CEPH_OS_BLUESTORE_STUPIDALLOCATOR_H +#include + #include "Allocator.h" #include "include/btree_interval_set.h" -#include "common/Mutex.h" class StupidAllocator : public Allocator { - Mutex lock; + std::mutex lock; int64_t num_free; ///< total bytes in freelist int64_t num_uncommitted;