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