| Last change
 on this file since 6e93819 was             a5d1fe7, checked in by caparsons <caparson@…>, 4 years ago | 
        
          | 
added mutexStmt benchmarks
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            434 bytes | 
      
      
| Line |  | 
|---|
| 1 | class 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 | }; | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.