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

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

add #pragma once to .h and .hfa files

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[5e4a830]1#pragma once
2
[1b97976c]3#include "bits/algorithm.hfa"
[eb9c2dc]4#include "bits/defs.hfa"
[1b97976c]5
6//-----------------------------------------------------------------------------
7// is_lock
[dd3576b]8forall(L & | sized(L))
9trait is_lock {
[1b97976c]10        // For acquiring a lock
11        void lock( L & );
12
13        // For releasing a lock
14        void unlock( L & );
15};
16
17
[0d4f954]18struct __mutex_stmt_lock_guard {
19    void ** lockarr;
20    __lock_size_t count;
21};
[1b97976c]22
[0d4f954]23static inline void ?{}( __mutex_stmt_lock_guard & this, void * lockarr [], __lock_size_t count  ) {
24    this.lockarr = lockarr;
25    this.count = count;
[1b97976c]26
[0d4f954]27    // Sort locks based on address
28    __libcfa_small_sort(this.lockarr, count);
29
30    // acquire locks in order
31    // for ( size_t i = 0; i < count; i++ ) {
32    //     lock(*this.lockarr[i]);
33    // }
34}
35
36static inline void ^?{}( __mutex_stmt_lock_guard & this ) with(this) {
37    // for ( size_t i = count; i > 0; i-- ) {
38    //     unlock(*lockarr[i - 1]);
39    // }
40}
41
42forall(L & | is_lock(L)) {
[a8367eb]43
[c1d8cde]44    struct scoped_lock {
45        L * internal_lock;
46    };
47
48    static inline void ?{}( scoped_lock(L) & this, L & internal_lock ) {
49        this.internal_lock = &internal_lock;
50        lock(internal_lock);
51    }
52   
53    static inline void ^?{}( scoped_lock(L) & this ) with(this) {
54        unlock(*internal_lock);
55    }
56
[0d4f954]57    static inline void * __get_mutexstmt_lock_ptr( L & this ) {
[a8367eb]58        return &this;
59    }
60
[0d4f954]61    static inline L __get_mutexstmt_lock_type( L & this );
[a8367eb]62
[0d4f954]63    static inline L __get_mutexstmt_lock_type( L * this );
[dd3576b]64}
Note: See TracBrowser for help on using the repository browser.