Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / common / simple_spin.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2011 New Dream Network
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software
11  * Foundation.  See file COPYING.
12  *
13  */
14
15 #ifndef CEPH_SIMPLE_SPIN_H
16 #define CEPH_SIMPLE_SPIN_H
17
18 #include <atomic>
19
20 inline void simple_spin_lock(std::atomic_flag& lock)
21 {
22  while(lock.test_and_set(std::memory_order_acquire))
23   ;
24 }
25
26 inline void simple_spin_unlock(std::atomic_flag& lock)
27 {
28  lock.clear(std::memory_order_release);
29 }
30
31 inline void simple_spin_lock(std::atomic_flag *lock)
32 {
33  simple_spin_lock(*lock);
34 }
35
36 inline void simple_spin_unlock(std::atomic_flag *lock)
37 {
38  simple_spin_unlock(*lock);
39 }
40
41 #endif