- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.hfa
r4aeaee5 rac5816d 3 3 #include <stdbool.h> 4 4 5 #include "bits/algorithm.hfa"6 5 #include "bits/locks.hfa" 7 6 #include "bits/sequence.hfa" 8 #include "bits/containers.hfa"9 7 10 8 #include "invoke.h" … … 12 10 #include "time_t.hfa" 13 11 #include "time.hfa" 14 #include <sys/time.h>15 #include "alarm.hfa"16 12 17 /////////////////////////////////////////////////////////////////// 18 //// is_blocking_lock 19 /////////////////////////////////////////////////////////////////// 13 //----------------------------------------------------------------------------- 14 // is_blocking_lock 15 trait is_blocking_lock(dtype L | sized(L)) { 16 // For synchronization locks to use when acquiring 17 void on_notify( L &, struct $thread * ); 20 18 21 trait is_blocking_lock(dtype L | sized(L)) { 22 void add_( L &, struct $thread * ); // For synchronization locks to use when acquiring 23 void remove_( L & ); // For synchronization locks to use when releasing 24 size_t get_recursion_count( L & ); // to get recursion count for cond lock to reset after waking 25 void set_recursion_count( L &, size_t recursion ); // to set recursion count after getting signalled; 19 // For synchronization locks to use when releasing 20 void on_wait( L & ); 21 22 // to get recursion count for cond lock to reset after waking 23 size_t get_recursion_count( L & ); 24 25 // to set recursion count after getting signalled; 26 void set_recursion_count( L &, size_t recursion ); 26 27 }; 27 28 28 /////////////////////////////////////////////////////////////////// 29 //// info_thread 30 /////////////////////////////////////////////////////////////////// 29 //----------------------------------------------------------------------------- 30 // info_thread 31 // the info thread is a wrapper around a thread used 32 // to store extra data for use in the condition variable 33 forall(dtype L | is_blocking_lock(L)) { 34 struct info_thread; 31 35 32 forall(dtype L | is_blocking_lock(L)) { 33 struct info_thread { 34 inline Seqable; 35 struct $thread * t; 36 uintptr_t info; 37 L * lock; 38 bool listed; // true if info_thread is on queue, false otherwise; 39 }; 40 41 42 void ?{}( info_thread(L) & this, $thread * t ); 43 void ?{}( info_thread(L) & this, $thread * t, uintptr_t info ); 44 void ^?{}( info_thread(L) & this ); 36 // for use by sequence 37 info_thread(L) *& Back( info_thread(L) * this ); 38 info_thread(L) *& Next( info_thread(L) * this ); 45 39 } 46 40 47 /////////////////////////////////////////////////////////////////// 48 //// Blocking Locks 49 /////////////////////////////////////////////////////////////////// 50 51 // struct lock_thread { 52 // struct $thread * t; 53 // lock_thread * next; 54 // }; 55 56 // void ?{}( lock_thread & this, struct $thread * thd ); 57 // void ^?{}( lock_thread & this ); 58 59 // lock_thread *& get_next( lock_thread & ); 60 41 //----------------------------------------------------------------------------- 42 // Blocking Locks 61 43 struct blocking_lock { 62 44 // Spin lock used for mutual exclusion … … 64 46 65 47 // List of blocked threads 66 __queue_t( $thread ) blocked_threads;48 Sequence( $thread ) blocked_threads; 67 49 68 50 // Count of current blocked threads … … 94 76 }; 95 77 96 void ?{}( blocking_lock & this, bool multi_acquisition, bool strict_owner );78 void ?{}( blocking_lock & this, bool multi_acquisition, bool strict_owner ); 97 79 void ^?{}( blocking_lock & this ); 98 80 99 void ?{}( single_acquisition_lock & this );81 void ?{}( single_acquisition_lock & this ); 100 82 void ^?{}( single_acquisition_lock & this ); 101 83 102 void ?{}( owner_lock & this );84 void ?{}( owner_lock & this ); 103 85 void ^?{}( owner_lock & this ); 104 86 105 void ?{}( multiple_acquisition_lock & this );87 void ?{}( multiple_acquisition_lock & this ); 106 88 void ^?{}( multiple_acquisition_lock & this ); 107 89 … … 109 91 bool try_lock( blocking_lock & this ); 110 92 void unlock( blocking_lock & this ); 111 void add_( blocking_lock & this, struct $thread * t );112 void remove_( blocking_lock & this );93 void on_notify( blocking_lock & this, struct $thread * t ); 94 void on_wait( blocking_lock & this ); 113 95 size_t wait_count( blocking_lock & this ); 114 96 void set_recursion_count( blocking_lock & this, size_t recursion ); … … 117 99 void lock( single_acquisition_lock & this ); 118 100 void unlock( single_acquisition_lock & this ); 119 void add_( single_acquisition_lock & this, struct $thread * t );120 void remove_( single_acquisition_lock & this );101 void on_notify( single_acquisition_lock & this, struct $thread * t ); 102 void on_wait( single_acquisition_lock & this ); 121 103 void set_recursion_count( single_acquisition_lock & this, size_t recursion ); 122 104 size_t get_recursion_count( single_acquisition_lock & this ); … … 124 106 void lock( owner_lock & this ); 125 107 void unlock( owner_lock & this ); 126 void add_( owner_lock & this, struct $thread * t );127 void remove_( owner_lock & this );108 void on_notify( owner_lock & this, struct $thread * t ); 109 void on_wait( owner_lock & this ); 128 110 void set_recursion_count( owner_lock & this, size_t recursion ); 129 111 size_t get_recursion_count( owner_lock & this ); … … 131 113 void lock( multiple_acquisition_lock & this ); 132 114 void unlock( multiple_acquisition_lock & this ); 133 void add_( multiple_acquisition_lock & this, struct $thread * t );134 void remove_( multiple_acquisition_lock & this );115 void on_notify( multiple_acquisition_lock & this, struct $thread * t ); 116 void on_wait( multiple_acquisition_lock & this ); 135 117 void set_recursion_count( multiple_acquisition_lock & this, size_t recursion ); 136 118 size_t get_recursion_count( multiple_acquisition_lock & this ); 137 119 138 /////////////////////////////////////////////////////////////////// 139 //// Synchronization Locks 140 /////////////////////////////////////////////////////////////////// 120 //----------------------------------------------------------------------------- 121 // Synchronization Locks 141 122 forall(dtype L | is_blocking_lock(L)) { 142 123 struct condition_variable { 143 124 // Spin lock used for mutual exclusion 144 125 __spinlock_t lock; 145 146 info_thread(L) * last_thread;147 126 148 127 // List of blocked threads … … 153 132 }; 154 133 155 void ?{}( condition_variable(L) & this );134 void ?{}( condition_variable(L) & this ); 156 135 void ^?{}( condition_variable(L) & this ); 157 158 struct alarm_node_wrap {159 alarm_node_t alarm_node;160 161 condition_variable(L) * cond;162 163 info_thread(L) * i;164 };165 166 void ?{}( alarm_node_wrap(L) & this, Time alarm, Duration period, Alarm_Callback callback );167 void ^?{}( alarm_node_wrap(L) & this );168 169 void alarm_node_callback( alarm_node_wrap(L) & this );170 171 void alarm_node_wrap_cast( alarm_node_t & a );172 136 173 137 bool notify_one( condition_variable(L) & this ); … … 176 140 uintptr_t front( condition_variable(L) & this ); 177 141 178 bool empty ( condition_variable(L) & this );179 int counter( condition_variable(L) & this );142 bool empty ( condition_variable(L) & this ); 143 int counter( condition_variable(L) & this ); 180 144 181 // TODO: look into changing timout routines to return bool showing if signalled or woken by kernel182 145 void wait( condition_variable(L) & this ); 183 146 void wait( condition_variable(L) & this, uintptr_t info ); 184 voidwait( condition_variable(L) & this, Duration duration );185 voidwait( condition_variable(L) & this, uintptr_t info, Duration duration );186 voidwait( condition_variable(L) & this, Time time );187 voidwait( condition_variable(L) & this, uintptr_t info, Time time );147 bool wait( condition_variable(L) & this, Duration duration ); 148 bool wait( condition_variable(L) & this, uintptr_t info, Duration duration ); 149 bool wait( condition_variable(L) & this, Time time ); 150 bool wait( condition_variable(L) & this, uintptr_t info, Time time ); 188 151 189 152 void wait( condition_variable(L) & this, L & l ); 190 153 void wait( condition_variable(L) & this, L & l, uintptr_t info ); 191 voidwait( condition_variable(L) & this, L & l, Duration duration );192 voidwait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration );193 voidwait( condition_variable(L) & this, L & l, Time time );194 voidwait( condition_variable(L) & this, L & l, uintptr_t info, Time time );154 bool wait( condition_variable(L) & this, L & l, Duration duration ); 155 bool wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ); 156 bool wait( condition_variable(L) & this, L & l, Time time ); 157 bool wait( condition_variable(L) & this, L & l, uintptr_t info, Time time ); 195 158 }
Note: See TracChangeset
for help on using the changeset viewer.