[ab1b971] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2021 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // bits/weakso_locks.hfa -- PUBLIC |
---|
| 8 | // Runtime locks that are compiled out when used without linking the runtime |
---|
| 9 | // thread system. |
---|
| 10 | // |
---|
| 11 | // Author : Thierry Delisle |
---|
| 12 | // Created On : Thu Jan 21 19:46:50 2021 |
---|
| 13 | // Last Modified By : |
---|
| 14 | // Last Modified On : |
---|
| 15 | // Update Count : |
---|
| 16 | // |
---|
| 17 | |
---|
[352cbc2] | 18 | #pragma once |
---|
| 19 | |
---|
[ab1b971] | 20 | #include "bits/locks.hfa" |
---|
| 21 | #include "bits/sequence.hfa" |
---|
| 22 | #include "bits/containers.hfa" |
---|
[82f4063] | 23 | #include "containers/list.hfa" |
---|
[ab1b971] | 24 | |
---|
[73bf7ddc] | 25 | struct select_node; |
---|
[ab1b971] | 26 | |
---|
| 27 | //----------------------------------------------------------------------------- |
---|
| 28 | // Blocking Locks |
---|
| 29 | struct blocking_lock { |
---|
| 30 | // Spin lock used for mutual exclusion |
---|
| 31 | __spinlock_t lock; |
---|
| 32 | |
---|
| 33 | // List of blocked threads |
---|
[73bf7ddc] | 34 | dlist( select_node ) blocked_threads; |
---|
[ab1b971] | 35 | |
---|
| 36 | // Count of current blocked threads |
---|
| 37 | size_t wait_count; |
---|
| 38 | |
---|
| 39 | // Flag if the lock allows multiple acquisition |
---|
| 40 | bool multi_acquisition; |
---|
| 41 | |
---|
| 42 | // Flag if lock can be released by non owner |
---|
| 43 | bool strict_owner; |
---|
| 44 | |
---|
| 45 | // Current thread owning the lock |
---|
[e84ab3d] | 46 | struct thread$ * owner; |
---|
[ab1b971] | 47 | |
---|
| 48 | // Number of recursion level |
---|
| 49 | size_t recursion_count; |
---|
| 50 | }; |
---|
| 51 | |
---|
| 52 | void ?{}( blocking_lock & this, bool multi_acquisition, bool strict_owner ) OPTIONAL_THREAD; |
---|
| 53 | void ^?{}( blocking_lock & this ) OPTIONAL_THREAD; |
---|
| 54 | |
---|
| 55 | void lock( blocking_lock & this ) OPTIONAL_THREAD; |
---|
| 56 | bool try_lock( blocking_lock & this ) OPTIONAL_THREAD; |
---|
| 57 | void unlock( blocking_lock & this ) OPTIONAL_THREAD; |
---|
[e84ab3d] | 58 | void on_notify( blocking_lock & this, struct thread$ * t ) OPTIONAL_THREAD; |
---|
[22b7579] | 59 | size_t on_wait( blocking_lock & this ) OPTIONAL_THREAD; |
---|
| 60 | void on_wakeup( blocking_lock & this, size_t ) OPTIONAL_THREAD; |
---|
[ab1b971] | 61 | size_t wait_count( blocking_lock & this ) OPTIONAL_THREAD; |
---|
[73bf7ddc] | 62 | bool register_select( blocking_lock & this, select_node & node ) OPTIONAL_THREAD; |
---|
| 63 | bool unregister_select( blocking_lock & this, select_node & node ) OPTIONAL_THREAD; |
---|
| 64 | bool on_selected( blocking_lock & this, select_node & node ) OPTIONAL_THREAD; |
---|
[ab1b971] | 65 | |
---|
| 66 | //---------- |
---|
| 67 | struct multiple_acquisition_lock { |
---|
| 68 | inline blocking_lock; |
---|
| 69 | }; |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | static inline void ?{}( multiple_acquisition_lock & this ) {((blocking_lock &)this){ true, false };} |
---|
| 73 | static inline void ^?{}( multiple_acquisition_lock & this ) {} |
---|
[f19497c] | 74 | static inline void lock ( multiple_acquisition_lock & this ) { lock ( (blocking_lock &)this ); } |
---|
[d27b6be] | 75 | static inline bool try_lock ( multiple_acquisition_lock & this ) { return try_lock( (blocking_lock &)this ); } |
---|
[f19497c] | 76 | static inline void unlock ( multiple_acquisition_lock & this ) { unlock ( (blocking_lock &)this ); } |
---|
[22b7579] | 77 | static inline size_t on_wait ( multiple_acquisition_lock & this ) { return on_wait ( (blocking_lock &)this ); } |
---|
| 78 | static inline void on_wakeup( multiple_acquisition_lock & this, size_t v ) { on_wakeup ( (blocking_lock &)this, v ); } |
---|
[b2f3880] | 79 | static inline void on_notify( multiple_acquisition_lock & this, struct thread$ * t ){ on_notify( (blocking_lock &)this, t ); } |
---|
[73bf7ddc] | 80 | static inline bool register_select( multiple_acquisition_lock & this, select_node & node ) { return register_select( (blocking_lock &)this, node ); } |
---|
| 81 | static inline bool unregister_select( multiple_acquisition_lock & this, select_node & node ) { return unregister_select( (blocking_lock &)this, node ); } |
---|
| 82 | static inline bool on_selected( multiple_acquisition_lock & this, select_node & node ) { return on_selected( (blocking_lock &)this, node ); } |
---|