ADT
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        pthread-emulation
        qualifiedEnum
      
      
        
          | Last change
 on this file since d8db0af was             1b97976c, checked in by caparsons <caparson@…>, 4 years ago | 
        
          | 
added in file I forgot and added test expect for locks
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.1 KB | 
      
      
| Line |  | 
|---|
| 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 | } | 
|---|
| 42 |  | 
|---|
| 43 | static inline L * __get_pointer( L & lock ) { | 
|---|
| 44 | return &lock; | 
|---|
| 45 | } | 
|---|
| 46 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.