ADT
ast-experimental
Last change
on this file since 99fb52c was dd3576b, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago |
update from old to new trait syntax using forall
|
-
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
|
---|
[dd3576b] | 6 | forall(L & | sized(L))
|
---|
| 7 | trait is_lock {
|
---|
[1b97976c] | 8 | // For acquiring a lock
|
---|
| 9 | void lock( L & );
|
---|
| 10 |
|
---|
| 11 | // For releasing a lock
|
---|
| 12 | void unlock( L & );
|
---|
| 13 | };
|
---|
| 14 |
|
---|
| 15 |
|
---|
[0d4f954] | 16 | struct __mutex_stmt_lock_guard {
|
---|
| 17 | void ** lockarr;
|
---|
| 18 | __lock_size_t count;
|
---|
| 19 | };
|
---|
[1b97976c] | 20 |
|
---|
[0d4f954] | 21 | static inline void ?{}( __mutex_stmt_lock_guard & this, void * lockarr [], __lock_size_t count ) {
|
---|
| 22 | this.lockarr = lockarr;
|
---|
| 23 | this.count = count;
|
---|
[1b97976c] | 24 |
|
---|
[0d4f954] | 25 | // Sort locks based on address
|
---|
| 26 | __libcfa_small_sort(this.lockarr, count);
|
---|
| 27 |
|
---|
| 28 | // acquire locks in order
|
---|
| 29 | // for ( size_t i = 0; i < count; i++ ) {
|
---|
| 30 | // lock(*this.lockarr[i]);
|
---|
| 31 | // }
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | static inline void ^?{}( __mutex_stmt_lock_guard & this ) with(this) {
|
---|
| 35 | // for ( size_t i = count; i > 0; i-- ) {
|
---|
| 36 | // unlock(*lockarr[i - 1]);
|
---|
| 37 | // }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | forall(L & | is_lock(L)) {
|
---|
[a8367eb] | 41 |
|
---|
[c1d8cde] | 42 | struct scoped_lock {
|
---|
| 43 | L * internal_lock;
|
---|
| 44 | };
|
---|
| 45 |
|
---|
| 46 | static inline void ?{}( scoped_lock(L) & this, L & internal_lock ) {
|
---|
| 47 | this.internal_lock = &internal_lock;
|
---|
| 48 | lock(internal_lock);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | static inline void ^?{}( scoped_lock(L) & this ) with(this) {
|
---|
| 52 | unlock(*internal_lock);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[0d4f954] | 55 | static inline void * __get_mutexstmt_lock_ptr( L & this ) {
|
---|
[a8367eb] | 56 | return &this;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[0d4f954] | 59 | static inline L __get_mutexstmt_lock_type( L & this );
|
---|
[a8367eb] | 60 |
|
---|
[0d4f954] | 61 | static inline L __get_mutexstmt_lock_type( L * this );
|
---|
[dd3576b] | 62 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.