source: doc/theses/colby_parsons_MMAth/benchmarks/mutex_stmt/cpp/cppLock.hpp @ 75d874a

ADTast-experimental
Last change on this file since 75d874a was 119e6c8, checked in by caparsons <caparson@…>, 20 months ago

updated mutex stmt run script and header for cpp variant

  • Property mode set to 100644
File size: 1.5 KB
Line 
1class cpp_test_spinlock {
2        volatile bool lockBool = 0;
3
4  public:
5        inline void lock() {
6                for ( ;; ) {
7                        if ( (this->lockBool == 0) && (__atomic_test_and_set( &this->lockBool, __ATOMIC_ACQUIRE ) == 0) ) break;
8                }
9        }
10
11        inline bool try_lock() {
12                return (this->lockBool == 0) && (__atomic_test_and_set( &this->lockBool, __ATOMIC_ACQUIRE ) == 0);
13        }
14
15        inline void unlock() {
16                __atomic_clear( &this->lockBool, __ATOMIC_RELEASE );
17        }
18};
19
20inline void lock( cpp_test_spinlock &a, cpp_test_spinlock &b ) {
21    a.lock(); b.lock();
22}
23inline void lock( cpp_test_spinlock &a, cpp_test_spinlock &b, cpp_test_spinlock &c, cpp_test_spinlock &d ) {
24    a.lock(); b.lock(); c.lock(); d.lock();
25}
26inline void lock( cpp_test_spinlock &a, cpp_test_spinlock &b, cpp_test_spinlock &c, cpp_test_spinlock &d, cpp_test_spinlock &e, cpp_test_spinlock &f, cpp_test_spinlock &g, cpp_test_spinlock &h ) {
27    a.lock(); b.lock(); c.lock(); d.lock(); e.lock(); f.lock(); g.lock(); h.lock();
28}
29inline void unlock( cpp_test_spinlock &a, cpp_test_spinlock &b ) {
30    a.unlock(); b.unlock();
31}
32inline void unlock( cpp_test_spinlock &a, cpp_test_spinlock &b, cpp_test_spinlock &c, cpp_test_spinlock &d ) {
33    a.unlock(); b.unlock(); c.unlock(); d.unlock();
34}
35inline void unlock( cpp_test_spinlock &a, cpp_test_spinlock &b, cpp_test_spinlock &c, cpp_test_spinlock &d, cpp_test_spinlock &e, cpp_test_spinlock &f, cpp_test_spinlock &g, cpp_test_spinlock &h ) {
36    a.unlock(); b.unlock(); c.unlock(); d.unlock(); e.unlock(); f.unlock(); g.unlock(); h.unlock();
37}
Note: See TracBrowser for help on using the repository browser.