source: libcfa/src/bits/weakso_locks.hfa @ ea561c9

arm-ehjacob/cs343-translationnew-ast-unique-expr
Last change on this file since ea561c9 was ab1b971, checked in by Thierry Delisle <tdelisle@…>, 11 months ago

blocking_lock & multiple_acquisition_lock can now be used without libcfa-thread.
Doing so will have all functions be no-ops for these locks.
If libcfa-thread is linked in, these locks will behave as proper user-level locking.

  • Property mode set to 100644
File size: 2.7 KB
Line 
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
18#include "bits/locks.hfa"
19#include "bits/sequence.hfa"
20#include "bits/containers.hfa"
21
22struct $thread;
23
24//-----------------------------------------------------------------------------
25// Blocking Locks
26struct blocking_lock {
27        // Spin lock used for mutual exclusion
28        __spinlock_t lock;
29
30        // List of blocked threads
31        Sequence( $thread ) blocked_threads;
32
33        // Count of current blocked threads
34        size_t wait_count;
35
36        // Flag if the lock allows multiple acquisition
37        bool multi_acquisition;
38
39        // Flag if lock can be released by non owner
40        bool strict_owner;
41
42        // Current thread owning the lock
43        struct $thread * owner;
44
45        // Number of recursion level
46        size_t recursion_count;
47};
48
49void  ?{}( blocking_lock & this, bool multi_acquisition, bool strict_owner ) OPTIONAL_THREAD;
50void ^?{}( blocking_lock & this ) OPTIONAL_THREAD;
51
52void lock( blocking_lock & this ) OPTIONAL_THREAD;
53bool try_lock( blocking_lock & this ) OPTIONAL_THREAD;
54void unlock( blocking_lock & this ) OPTIONAL_THREAD;
55void on_notify( blocking_lock & this, struct $thread * t ) OPTIONAL_THREAD;
56void on_wait( blocking_lock & this ) OPTIONAL_THREAD;
57size_t wait_count( blocking_lock & this ) OPTIONAL_THREAD;
58void set_recursion_count( blocking_lock & this, size_t recursion ) OPTIONAL_THREAD;
59size_t get_recursion_count( blocking_lock & this ) OPTIONAL_THREAD;
60
61//----------
62struct multiple_acquisition_lock {
63        inline blocking_lock;
64};
65
66
67static inline void  ?{}( multiple_acquisition_lock & this ) {((blocking_lock &)this){ true, false };}
68static inline void ^?{}( multiple_acquisition_lock & this ) {}
69static inline void   lock     ( multiple_acquisition_lock & this ) { lock   ( (blocking_lock &)this ); }
70static inline void   unlock   ( multiple_acquisition_lock & this ) { unlock ( (blocking_lock &)this ); }
71static inline void   on_wait  ( multiple_acquisition_lock & this ) { on_wait( (blocking_lock &)this ); }
72static inline void   on_notify( multiple_acquisition_lock & this, struct $thread * t ){ on_notify( (blocking_lock &)this, t ); }
73static inline void   set_recursion_count( multiple_acquisition_lock & this, size_t recursion ){ set_recursion_count( (blocking_lock &)this, recursion ); }
74static inline size_t get_recursion_count( multiple_acquisition_lock & this ){ return get_recursion_count( (blocking_lock &)this ); }
Note: See TracBrowser for help on using the repository browser.