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/07 01:36:44 UTC

[04/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/42b1749a
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/42b1749a
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/42b1749a

Branch: refs/heads/feature/GEODE-2602
Commit: 42b1749a3af5cff6481dc01f6d10ea363393e04c
Parents: 5d9e713
Author: Jacob Barrett <jb...@pivotal.io>
Authored: Wed Feb 15 22:29:09 2017 -0800
Committer: Jacob Barrett <jb...@pivotal.io>
Committed: Mon Mar 6 17:32:10 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/42b1749a/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_ */