source: libcfa/src/concurrency/mutex_stmt.hfa @ dd3576b

ADTast-experimental
Last change on this file since dd3576b was dd3576b, checked in by Peter A. Buhr <pabuhr@…>, 17 months ago

update from old to new trait syntax using forall

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#include "bits/algorithm.hfa"
2#include "bits/defs.hfa"
3
4//-----------------------------------------------------------------------------
5// is_lock
6forall(L & | sized(L))
7trait is_lock {
8        // For acquiring a lock
9        void lock( L & );
10
11        // For releasing a lock
12        void unlock( L & );
13};
14
15
16struct __mutex_stmt_lock_guard {
17    void ** lockarr;
18    __lock_size_t count;
19};
20
21static inline void ?{}( __mutex_stmt_lock_guard & this, void * 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
34static 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
40forall(L & | is_lock(L)) {
41
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
55    static inline void * __get_mutexstmt_lock_ptr( L & this ) {
56        return &this;
57    }
58
59    static inline L __get_mutexstmt_lock_type( L & this );
60
61    static inline L __get_mutexstmt_lock_type( L * this );
62}
Note: See TracBrowser for help on using the repository browser.