]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore/StupidAllocator: use std::mutex
authorSage Weil <sage@redhat.com>
Wed, 27 Jan 2016 18:43:06 +0000 (13:43 -0500)
committerSage Weil <sage@redhat.com>
Wed, 27 Jan 2016 18:55:41 +0000 (13:55 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/StupidAllocator.cc
src/os/bluestore/StupidAllocator.h

index a8f70a3ec7e050db512ec8fa6b5b814ffa7283ea..4d8c5f1359c3c9b5f18648ef2e5e57c84057df23 100755 (executable)
@@ -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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> l(lock);
   return num_free;
 }
 
 void StupidAllocator::dump(ostream& out)
 {
-  Mutex::Locker l(lock);
+  std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> l(lock);
   dout(10) << __func__ << " " << offset << "~" << length << dendl;
   btree_interval_set<uint64_t> rm;
   rm.insert(offset, length);
@@ -281,7 +280,7 @@ void StupidAllocator::shutdown()
 
 void StupidAllocator::commit_start()
 {
-  Mutex::Locker l(lock);
+  std::lock_guard<std::mutex> 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<std::mutex> l(lock);
   dout(10) << __func__ << " released " << num_committing
           << " in extents " << committing.num_intervals() << dendl;
   for (auto p = committing.begin();
index e5cf17d1006694d4cb11d3c30c4d03c3e3b133b3..1b09ace2dc9de8620490fe4ef91b5b4951347992 100644 (file)
@@ -4,12 +4,13 @@
 #ifndef CEPH_OS_BLUESTORE_STUPIDALLOCATOR_H
 #define CEPH_OS_BLUESTORE_STUPIDALLOCATOR_H
 
+#include <mutex>
+
 #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;