ADT
        ast-experimental
      
      
        
          | 
            Last change
 on this file since dbae916 was             5e4a830, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago           | 
        
        
          | 
             
add #pragma once to .h and .hfa files 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            1.4 KB
           | 
        
      
      
| Line |   | 
|---|
| 1 | #pragma once
 | 
|---|
| 2 | 
 | 
|---|
| 3 | #include "bits/algorithm.hfa"
 | 
|---|
| 4 | #include "bits/defs.hfa"
 | 
|---|
| 5 | 
 | 
|---|
| 6 | //-----------------------------------------------------------------------------
 | 
|---|
| 7 | // is_lock
 | 
|---|
| 8 | forall(L & | sized(L))
 | 
|---|
| 9 | trait is_lock {
 | 
|---|
| 10 |         // For acquiring a lock
 | 
|---|
| 11 |         void lock( L & );
 | 
|---|
| 12 | 
 | 
|---|
| 13 |         // For releasing a lock
 | 
|---|
| 14 |         void unlock( L & );
 | 
|---|
| 15 | };
 | 
|---|
| 16 | 
 | 
|---|
| 17 | 
 | 
|---|
| 18 | struct __mutex_stmt_lock_guard {
 | 
|---|
| 19 |     void ** lockarr;
 | 
|---|
| 20 |     __lock_size_t count;
 | 
|---|
| 21 | };
 | 
|---|
| 22 | 
 | 
|---|
| 23 | static inline void ?{}( __mutex_stmt_lock_guard & this, void * lockarr [], __lock_size_t count  ) {
 | 
|---|
| 24 |     this.lockarr = lockarr;
 | 
|---|
| 25 |     this.count = count;
 | 
|---|
| 26 | 
 | 
|---|
| 27 |     // Sort locks based on address
 | 
|---|
| 28 |     __libcfa_small_sort(this.lockarr, count);
 | 
|---|
| 29 | 
 | 
|---|
| 30 |     // acquire locks in order
 | 
|---|
| 31 |     // for ( size_t i = 0; i < count; i++ ) {
 | 
|---|
| 32 |     //     lock(*this.lockarr[i]);
 | 
|---|
| 33 |     // }
 | 
|---|
| 34 | }
 | 
|---|
| 35 | 
 | 
|---|
| 36 | static inline void ^?{}( __mutex_stmt_lock_guard & this ) with(this) {
 | 
|---|
| 37 |     // for ( size_t i = count; i > 0; i-- ) {
 | 
|---|
| 38 |     //     unlock(*lockarr[i - 1]);
 | 
|---|
| 39 |     // }
 | 
|---|
| 40 | }
 | 
|---|
| 41 | 
 | 
|---|
| 42 | forall(L & | is_lock(L)) {
 | 
|---|
| 43 | 
 | 
|---|
| 44 |     struct scoped_lock {
 | 
|---|
| 45 |         L * internal_lock;
 | 
|---|
| 46 |     };
 | 
|---|
| 47 | 
 | 
|---|
| 48 |     static inline void ?{}( scoped_lock(L) & this, L & internal_lock ) {
 | 
|---|
| 49 |         this.internal_lock = &internal_lock;
 | 
|---|
| 50 |         lock(internal_lock);
 | 
|---|
| 51 |     }
 | 
|---|
| 52 |     
 | 
|---|
| 53 |     static inline void ^?{}( scoped_lock(L) & this ) with(this) {
 | 
|---|
| 54 |         unlock(*internal_lock);
 | 
|---|
| 55 |     }
 | 
|---|
| 56 | 
 | 
|---|
| 57 |     static inline void * __get_mutexstmt_lock_ptr( L & this ) {
 | 
|---|
| 58 |         return &this;
 | 
|---|
| 59 |     }
 | 
|---|
| 60 | 
 | 
|---|
| 61 |     static inline L __get_mutexstmt_lock_type( L & this );
 | 
|---|
| 62 | 
 | 
|---|
| 63 |     static inline L __get_mutexstmt_lock_type( L * this );
 | 
|---|
| 64 | }
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.