ADT
        ast-experimental
        enum
        forall-pointer-decay
        pthread-emulation
        qualifiedEnum
      
      
        
          | Last change
 on this file since 321a1b15 was             a8367eb, checked in by caparsons <caparson@…>, 4 years ago | 
        
          | 
fixed mutexStmt bug related to pointers/references
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.2 KB | 
      
      
| Rev | Line |  | 
|---|
| [1b97976c] | 1 | #include "bits/algorithm.hfa" | 
|---|
|  | 2 | #include <assert.h> | 
|---|
|  | 3 | #include "invoke.h" | 
|---|
|  | 4 | #include "stdlib.hfa" | 
|---|
|  | 5 | #include <stdio.h> | 
|---|
|  | 6 |  | 
|---|
|  | 7 | //----------------------------------------------------------------------------- | 
|---|
|  | 8 | // is_lock | 
|---|
|  | 9 | trait is_lock(L & | sized(L)) { | 
|---|
|  | 10 | // For acquiring a lock | 
|---|
|  | 11 | void lock( L & ); | 
|---|
|  | 12 |  | 
|---|
|  | 13 | // For releasing a lock | 
|---|
|  | 14 | void unlock( L & ); | 
|---|
|  | 15 | }; | 
|---|
|  | 16 |  | 
|---|
|  | 17 | forall(L & | is_lock(L)) { | 
|---|
|  | 18 |  | 
|---|
|  | 19 | struct __mutex_stmt_lock_guard { | 
|---|
|  | 20 | L ** lockarr; | 
|---|
|  | 21 | __lock_size_t count; | 
|---|
|  | 22 | }; | 
|---|
|  | 23 |  | 
|---|
|  | 24 | static inline void ?{}( __mutex_stmt_lock_guard(L) & this, L * lockarr [], __lock_size_t count  ) { | 
|---|
|  | 25 | this.lockarr = lockarr; | 
|---|
|  | 26 | this.count = count; | 
|---|
|  | 27 |  | 
|---|
|  | 28 | // Sort locks based on address | 
|---|
|  | 29 | __libcfa_small_sort(this.lockarr, count); | 
|---|
|  | 30 |  | 
|---|
|  | 31 | // acquire locks in order | 
|---|
|  | 32 | for ( size_t i = 0; i < count; i++ ) { | 
|---|
|  | 33 | lock(*this.lockarr[i]); | 
|---|
|  | 34 | } | 
|---|
|  | 35 | } | 
|---|
|  | 36 |  | 
|---|
|  | 37 | static inline void ^?{}( __mutex_stmt_lock_guard(L) & this ) with(this) { | 
|---|
|  | 38 | for ( size_t i = count; i > 0; i-- ) { | 
|---|
|  | 39 | unlock(*lockarr[i - 1]); | 
|---|
|  | 40 | } | 
|---|
|  | 41 | } | 
|---|
| [a8367eb] | 42 |  | 
|---|
|  | 43 | static inline L * __get_ptr( L & this ) { | 
|---|
|  | 44 | return &this; | 
|---|
|  | 45 | } | 
|---|
|  | 46 |  | 
|---|
|  | 47 | static inline L __get_type( L & this ); | 
|---|
|  | 48 |  | 
|---|
|  | 49 | static inline L __get_type( L * this ); | 
|---|
| [1b97976c] | 50 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.