You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2017/03/01 23:35:11 UTC

[06/21] geode-native git commit: GEODE-2494: Adds spinlock_mutex.

GEODE-2494: Adds spinlock_mutex.


Project: http://git-wip-us.apache.org/repos/asf/geode-native/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode-native/commit/12eb5313
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/12eb5313
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/12eb5313

Branch: refs/heads/develop
Commit: 12eb5313c766afa85120dfd76d687f730372ba19
Parents: 8fcb741
Author: Jacob Barrett <jb...@pivotal.io>
Authored: Wed Feb 15 22:29:09 2017 -0800
Committer: Jacob Barrett <jb...@pivotal.io>
Committed: Wed Mar 1 15:10:42 2017 -0800

----------------------------------------------------------------------
 .../src/util/concurrent/spinlock_mutex.hpp      | 51 ++++++++++++++++++++
 1 file changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode-native/blob/12eb5313/src/cppcache/src/util/concurrent/spinlock_mutex.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/util/concurrent/spinlock_mutex.hpp b/src/cppcache/src/util/concurrent/spinlock_mutex.hpp
new file mode 100644
index 0000000..ab59159
--- /dev/null
+++ b/src/cppcache/src/util/concurrent/spinlock_mutex.hpp
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#ifndef GEODE_UTIL_CONCURRENT_SPINLOCK_MUTEX_H_
+#define GEODE_UTIL_CONCURRENT_SPINLOCK_MUTEX_H_
+
+#include <atomic>
+
+namespace apache {
+namespace geode {
+namespace util {
+namespace concurrent {
+
+class spinlock_mutex final {
+ private:
+  std::atomic_flag flag = ATOMIC_FLAG_INIT;
+
+ public:
+  void lock() {
+    while (flag.test_and_set(std::memory_order_acquire)) continue;
+  }
+
+  void unlock() { flag.clear(std::memory_order_release); }
+
+  spinlock_mutex() = default;
+  spinlock_mutex(const spinlock_mutex &) = delete;
+  spinlock_mutex &operator=(const spinlock_mutex &) = delete;
+};
+
+} /* namespace concurrent */
+} /* namespace util */
+} /* namespace geode */
+} /* namespace apache */
+
+#endif /* GEODE_UTIL_CONCURRENT_SPINLOCK_MUTEX_H_ */