ADT
ast-experimental
enum
forall-pointer-decay
pthread-emulation
qualifiedEnum
|
Last change
on this file since 3e417bf was eb9c2dc, checked in by caparsons <caparson@…>, 4 years ago |
|
trimmed down includes more
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | #include "bits/algorithm.hfa"
|
|---|
| 2 | #include "bits/defs.hfa"
|
|---|
| 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 | forall(L & | is_lock(L)) {
|
|---|
| 15 |
|
|---|
| 16 | struct __mutex_stmt_lock_guard {
|
|---|
| 17 | L ** lockarr;
|
|---|
| 18 | __lock_size_t count;
|
|---|
| 19 | };
|
|---|
| 20 |
|
|---|
| 21 | static inline void ?{}( __mutex_stmt_lock_guard(L) & this, L * lockarr [], __lock_size_t count ) {
|
|---|
| 22 | this.lockarr = lockarr;
|
|---|
| 23 | this.count = count;
|
|---|
| 24 |
|
|---|
| 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(L) & this ) with(this) {
|
|---|
| 35 | for ( size_t i = count; i > 0; i-- ) {
|
|---|
| 36 | unlock(*lockarr[i - 1]);
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | static inline L * __get_ptr( L & this ) {
|
|---|
| 41 | return &this;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | static inline L __get_type( L & this );
|
|---|
| 45 |
|
|---|
| 46 | static inline L __get_type( L * this );
|
|---|
| 47 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.