]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
spinlock: move to include/
authorSage Weil <sage@newdream.net>
Thu, 8 Apr 2010 16:51:14 +0000 (09:51 -0700)
committerSage Weil <sage@newdream.net>
Thu, 8 Apr 2010 16:51:14 +0000 (09:51 -0700)
src/Makefile.am
src/common/Spinlock.h [deleted file]
src/include/Spinlock.h [new file with mode: 0644]
src/include/atomic.h
src/include/buffer.h
src/msg/SimpleMessenger.h

index dd78b5315608f467496c7e3326bacc56f047c3b5..bc4e393fee6d605450f0e70b7726142bf3ca3f60 100644 (file)
@@ -474,7 +474,6 @@ noinst_HEADERS = \
         common/Mutex.h\
         common/RWLock.h\
         common/Semaphore.h\
-       common/Spinlock.h\
         common/Thread.h\
         common/Throttle.h\
         common/Timer.h\
@@ -496,6 +495,7 @@ noinst_HEADERS = \
        include/CompatSet.h\
         include/Distribution.h\
        include/LogEntry.h\
+       include/Spinlock.h\
        include/assert.h\
         include/atomic.h\
         include/bitmapper.h\
diff --git a/src/common/Spinlock.h b/src/common/Spinlock.h
deleted file mode 100644 (file)
index d2c2b13..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software 
- * Foundation.  See file COPYING.
- * 
- */
-
-#ifndef __SPINLOCK_H
-#define __SPINLOCK_H
-
-#include <pthread.h>
-#include "include/assert.h"
-
-namespace ceph {
-
-//#define SPINLOCK_LOCKDEP
-
-#ifdef SPINLOCK_LOCKDEP
-# include "lockdep.h"
-#endif
-
-class Spinlock {
-private:
-  pthread_spinlock_t _s;
-  int nlock;
-
-  // don't allow copying.
-  void operator=(Spinlock &M) {}
-  Spinlock( const Spinlock &M ) {}
-
-#ifdef SPINLOCK_LOCKDEP
-  const char *name;
-  int id;
-  bool lockdep;
-  bool backtrace;  // gather backtrace on lock acquisition
-
-  void _register() {
-    if (lockdep && g_lockdep)
-      id = lockdep_register(name);
-  }
-  void _will_lock() { // about to lock
-    if (lockdep && g_lockdep)
-      id = lockdep_will_lock(name, id);
-  }
-  void _locked() {    // just locked
-    if (lockdep && g_lockdep)
-      id = lockdep_locked(name, id, backtrace);
-  }
-  void _will_unlock() {  // about to unlock
-    if (lockdep && g_lockdep)
-      id = lockdep_will_unlock(name, id);
-  }
-#else
-  void _register() {}
-  void _will_lock() {} // about to lock
-  void _locked() {}    // just locked
-  void _will_unlock() {}  // about to unlock
-#endif
-
-public:
-  Spinlock(const char *n, bool ld=true, bool bt=false) :
-    nlock(0)
-#ifdef SPINLOCK_LOCKDEP
-    , name(n), id(-1), lockdep(ld), backtrace(bt)
-#endif
-  {
-    pthread_spin_init(&_s, 0);
-    _register();
-  }
-  ~Spinlock() {
-    assert(nlock == 0);
-    pthread_spin_destroy(&_s); 
-  }
-
-  bool is_locked() {
-    return (nlock > 0);
-  }
-
-  bool try_lock() {
-    int r = pthread_spin_trylock(&_s);
-    if (r == 0) {
-      _locked();
-      nlock++;
-    }
-    return r == 0;
-  }
-
-  void lock() {
-    _will_lock();
-    int r = pthread_spin_lock(&_s);
-    _locked();
-    assert(r == 0);
-    nlock++;
-  }
-
-  void unlock() {
-    assert(nlock > 0);
-    --nlock;
-    _will_unlock();
-    int r = pthread_spin_unlock(&_s);
-    assert(r == 0);
-  }
-
-public:
-  class Locker {
-    Spinlock &spinlock;
-
-  public:
-    Locker(Spinlock& m) : spinlock(m) {
-      spinlock.lock();
-    }
-    ~Locker() {
-      spinlock.unlock();
-    }
-  };
-};
-
-}
-
-#endif
diff --git a/src/include/Spinlock.h b/src/include/Spinlock.h
new file mode 100644 (file)
index 0000000..d2c2b13
--- /dev/null
@@ -0,0 +1,127 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software 
+ * Foundation.  See file COPYING.
+ * 
+ */
+
+#ifndef __SPINLOCK_H
+#define __SPINLOCK_H
+
+#include <pthread.h>
+#include "include/assert.h"
+
+namespace ceph {
+
+//#define SPINLOCK_LOCKDEP
+
+#ifdef SPINLOCK_LOCKDEP
+# include "lockdep.h"
+#endif
+
+class Spinlock {
+private:
+  pthread_spinlock_t _s;
+  int nlock;
+
+  // don't allow copying.
+  void operator=(Spinlock &M) {}
+  Spinlock( const Spinlock &M ) {}
+
+#ifdef SPINLOCK_LOCKDEP
+  const char *name;
+  int id;
+  bool lockdep;
+  bool backtrace;  // gather backtrace on lock acquisition
+
+  void _register() {
+    if (lockdep && g_lockdep)
+      id = lockdep_register(name);
+  }
+  void _will_lock() { // about to lock
+    if (lockdep && g_lockdep)
+      id = lockdep_will_lock(name, id);
+  }
+  void _locked() {    // just locked
+    if (lockdep && g_lockdep)
+      id = lockdep_locked(name, id, backtrace);
+  }
+  void _will_unlock() {  // about to unlock
+    if (lockdep && g_lockdep)
+      id = lockdep_will_unlock(name, id);
+  }
+#else
+  void _register() {}
+  void _will_lock() {} // about to lock
+  void _locked() {}    // just locked
+  void _will_unlock() {}  // about to unlock
+#endif
+
+public:
+  Spinlock(const char *n, bool ld=true, bool bt=false) :
+    nlock(0)
+#ifdef SPINLOCK_LOCKDEP
+    , name(n), id(-1), lockdep(ld), backtrace(bt)
+#endif
+  {
+    pthread_spin_init(&_s, 0);
+    _register();
+  }
+  ~Spinlock() {
+    assert(nlock == 0);
+    pthread_spin_destroy(&_s); 
+  }
+
+  bool is_locked() {
+    return (nlock > 0);
+  }
+
+  bool try_lock() {
+    int r = pthread_spin_trylock(&_s);
+    if (r == 0) {
+      _locked();
+      nlock++;
+    }
+    return r == 0;
+  }
+
+  void lock() {
+    _will_lock();
+    int r = pthread_spin_lock(&_s);
+    _locked();
+    assert(r == 0);
+    nlock++;
+  }
+
+  void unlock() {
+    assert(nlock > 0);
+    --nlock;
+    _will_unlock();
+    int r = pthread_spin_unlock(&_s);
+    assert(r == 0);
+  }
+
+public:
+  class Locker {
+    Spinlock &spinlock;
+
+  public:
+    Locker(Spinlock& m) : spinlock(m) {
+      spinlock.lock();
+    }
+    ~Locker() {
+      spinlock.unlock();
+    }
+  };
+};
+
+}
+
+#endif
index 5cd842e057fd2cd1556d138ac8395a683740abc7..18c10c0e64ab3dce04066d525c76a576819bed94 100644 (file)
@@ -46,7 +46,7 @@ public:
 /*
  * crappy slow implementation that uses a pthreads spinlock.
  */
-#include "common/Spinlock.h"
+#include "Spinlock.h"
 
 namespace ceph {
 
index 4cb888d20233b01e6552bd40adf4dd56b50720a3..0f9f057e67e5ff55b361fe1f6dbd9b2517800d8b 100644 (file)
@@ -65,7 +65,7 @@ using std::string;
 //#define BUFFER_DEBUG
 
 #ifdef BUFFER_DEBUG
-#include "common/Spinlock.h"
+#include "Spinlock.h"
 extern Spinlock buffer_lock;
 # define bdout { buffer_lock.lock(); cout
 # define bendl std::endl; buffer_lock.unlock(); }
index 91f00d75b0cb60b4d83a9c49b02de08dd843f94b..d0a520dcad411efa9a67ae7e8b601b849ed685e7 100644 (file)
@@ -26,7 +26,7 @@ using namespace std;
 using namespace __gnu_cxx;
 
 #include "common/Mutex.h"
-#include "common/Spinlock.h"
+#include "include/Spinlock.h"
 #include "common/Cond.h"
 #include "common/Thread.h"