source:
libcfa/src/concurrency/mutex_stmt.hfa
@
ce9f9d4
Last change on this file since ce9f9d4 was bbe3719, checked in by , 3 years ago | |
---|---|
|
|
File size: 1.0 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 | } |
Note: See TracBrowser
for help on using the repository browser.