source: libcfa/src/concurrency/mutex_stmt.hfa@ 0ca15b7

ADT ast-experimental enum pthread-emulation qualifiedEnum
Last change on this file since 0ca15b7 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
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
9trait 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
17forall(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_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 );
50}
Note: See TracBrowser for help on using the repository browser.