Changeset ab1b971
- Timestamp:
- Jan 21, 2021, 8:47:31 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- ea561c9
- Parents:
- 7d01186d
- Files:
-
- 4 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/Makefile.am
r7d01186d rab1b971 76 76 stdlib.hfa \ 77 77 time.hfa \ 78 bits/weakso_locks.hfa \ 78 79 containers/maybe.hfa \ 79 80 containers/pair.hfa \ -
libcfa/src/bits/collection.hfa
r7d01186d rab1b971 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/collection.hfa -- PUBLIC 8 // Intrusive singly-linked list 9 // 10 // Author : Colby Alexander Parsons & Peter A. Buhr 11 // Created On : Thu Jan 21 19:46:50 2021 12 // Last Modified By : 13 // Last Modified On : 14 // Update Count : 15 // 16 1 17 #pragma once 2 #include <stdio.h> // REMOVE THIS AFTER DEBUGGING3 4 18 5 19 struct Colable { 6 struct Colable * next;// next node in the list20 // next node in the list 7 21 // invariant: (next != 0) <=> listed() 22 struct Colable * next; 8 23 }; 9 24 #ifdef __cforall … … 53 68 Collection & ?=?( const Collection & ) = void; // no assignment 54 69 55 void ?{}( Collection & collection ) with( collection ) { 70 void ?{}( Collection & collection ) with( collection ) { 56 71 root = 0p; 57 72 } // post: empty() -
libcfa/src/bits/sequence.hfa
r7d01186d rab1b971 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/sequence.hfa -- PUBLIC 8 // Intrusive doubly-linked list 9 // 10 // Author : Colby Alexander Parsons & Peter A. Buhr 11 // Created On : Thu Jan 21 19:46:50 2021 12 // Last Modified By : 13 // Last Modified On : 14 // Update Count : 15 // 16 1 17 #pragma once 2 18 … … 6 22 struct Seqable { 7 23 __cfa_anonymous_object(Colable); 8 struct Seqable * back; // pointer to previous node in the list 24 // pointer to previous node in the list 25 struct Seqable * back; 9 26 }; 10 27 … … 27 44 return sq->back; 28 45 } 29 30 // // wrappers to make Collection have T31 // forall( T & ) {32 // T *& Back( T * n ) {33 // return (T *)Back( (Seqable *)n );34 // }35 // } // distribution36 46 } // distribution 37 47 … … 43 53 // and the back field of the last node points at the first node (circular). 44 54 45 forall( T & | { T *& Back ( T * ); T *& Next ( T * ); }) {55 forall( T & ) { 46 56 struct Sequence { 47 inline Collection; // Plan 9 inheritance 57 // Plan 9 inheritance 58 inline Collection; 48 59 }; 49 60 50 61 static inline { 62 void ?{}( Sequence(T) &, const Sequence(T) & ) = void; // no copy 63 Sequence(T) & ?=?( const Sequence(T) & ) = void; // no assignment 64 65 void ?{}( Sequence(T) & s ) with( s ) { 66 ((Collection &)s){}; 67 } // post: isEmpty() 68 } 69 70 static inline forall(| { T *& Back ( T * ); T *& Next ( T * ); }) { 51 71 // wrappers to make Collection have T 52 72 T & head( Sequence(T) & s ) with( s ) { 53 73 return *(T *)head( (Collection &)s ); 54 74 } // post: empty() & head() == 0 | !empty() & head() in *s 55 56 void ?{}( Sequence(T) &, const Sequence(T) & ) = void; // no copy57 Sequence(T) & ?=?( const Sequence(T) & ) = void; // no assignment58 59 void ?{}( Sequence(T) & s ) with( s ) {60 ((Collection &)s){};61 } // post: isEmpty()62 75 63 76 // Return a pointer to the last sequence element, without removing it. … … 145 158 return n; 146 159 } // post: n->listed() & *n in *s & succ(n) == bef 147 160 148 161 // pre: n->listed() & *n in *s 149 162 T & remove( Sequence(T) & s, T & n ) with( s ) { // O(1) … … 285 298 286 299 static inline { 287 void ?{}( SeqIterRev(T) & si ) with( si ) { 300 void ?{}( SeqIterRev(T) & si ) with( si ) { 288 301 ((ColIter &)si){}; 289 302 seq = 0p; … … 291 304 292 305 // Create a iterator active in sequence s. 293 void ?{}( SeqIterRev(T) & si, Sequence(T) & s ) with( si ) { 306 void ?{}( SeqIterRev(T) & si, Sequence(T) & s ) with( si ) { 294 307 ((ColIter &)si){}; 295 308 seq = &s; … … 297 310 } // post: elts = null 298 311 299 void ?{}( SeqIterRev(T) & si, Sequence(T) & s, T & start ) with( si ) { 312 void ?{}( SeqIterRev(T) & si, Sequence(T) & s, T & start ) with( si ) { 300 313 ((ColIter &)si){}; 301 314 seq = &s; -
libcfa/src/concurrency/locks.cfa
r7d01186d rab1b971 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 // locks.hfa -- LIBCFATHREAD 8 // Runtime locks that used with the runtime thread system. 9 // 10 // Author : Colby Alexander Parsons 11 // Created On : Thu Jan 21 19:46:50 2021 12 // Last Modified By : 13 // Last Modified On : 14 // Update Count : 15 // 16 17 #define __cforall_thread__ 18 1 19 #include "locks.hfa" 2 20 #include "kernel_private.hfa" … … 56 74 57 75 void ^?{}( blocking_lock & this ) {} 58 void ?{}( single_acquisition_lock & this ) {((blocking_lock &)this){ false, false };} 59 void ^?{}( single_acquisition_lock & this ) {} 60 void ?{}( owner_lock & this ) {((blocking_lock &)this){ true, true };} 61 void ^?{}( owner_lock & this ) {} 62 void ?{}( multiple_acquisition_lock & this ) {((blocking_lock &)this){ true, false };} 63 void ^?{}( multiple_acquisition_lock & this ) {} 76 64 77 65 78 void lock( blocking_lock & this ) with( this ) { … … 168 181 unlock( lock ); 169 182 } 170 171 //-----------------------------------------------------------------------------172 // Overloaded routines for traits173 // These routines are temporary until an inheritance bug is fixed174 void lock ( single_acquisition_lock & this ) { lock ( (blocking_lock &)this ); }175 void unlock ( single_acquisition_lock & this ) { unlock ( (blocking_lock &)this ); }176 void on_wait ( single_acquisition_lock & this ) { on_wait( (blocking_lock &)this ); }177 void on_notify ( single_acquisition_lock & this, struct $thread * t ) { on_notify( (blocking_lock &)this, t ); }178 void set_recursion_count( single_acquisition_lock & this, size_t recursion ) { set_recursion_count( (blocking_lock &)this, recursion ); }179 size_t get_recursion_count( single_acquisition_lock & this ) { return get_recursion_count( (blocking_lock &)this ); }180 181 void lock ( owner_lock & this ) { lock ( (blocking_lock &)this ); }182 void unlock ( owner_lock & this ) { unlock ( (blocking_lock &)this ); }183 void on_wait ( owner_lock & this ) { on_wait( (blocking_lock &)this ); }184 void on_notify( owner_lock & this, struct $thread * t ) { on_notify( (blocking_lock &)this, t ); }185 void set_recursion_count( owner_lock & this, size_t recursion ) { set_recursion_count( (blocking_lock &)this, recursion ); }186 size_t get_recursion_count( owner_lock & this ) { return get_recursion_count( (blocking_lock &)this ); }187 188 void lock ( multiple_acquisition_lock & this ) { lock ( (blocking_lock &)this ); }189 void unlock ( multiple_acquisition_lock & this ) { unlock ( (blocking_lock &)this ); }190 void on_wait ( multiple_acquisition_lock & this ) { on_wait( (blocking_lock &)this ); }191 void on_notify( multiple_acquisition_lock & this, struct $thread * t ){ on_notify( (blocking_lock &)this, t ); }192 void set_recursion_count( multiple_acquisition_lock & this, size_t recursion ){ set_recursion_count( (blocking_lock &)this, recursion ); }193 size_t get_recursion_count( multiple_acquisition_lock & this ){ return get_recursion_count( (blocking_lock &)this ); }194 183 195 184 //----------------------------------------------------------------------------- -
libcfa/src/concurrency/locks.hfa
r7d01186d rab1b971 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 // locks.hfa -- PUBLIC 8 // Runtime locks that used with the runtime thread system. 9 // 10 // Author : Colby Alexander Parsons 11 // Created On : Thu Jan 21 19:46:50 2021 12 // Last Modified By : 13 // Last Modified On : 14 // Update Count : 15 // 16 1 17 #pragma once 2 18 3 19 #include <stdbool.h> 4 20 5 #include "bits/locks.hfa" 6 #include "bits/sequence.hfa" 7 8 #include "invoke.h" 21 #include "bits/weakso_locks.hfa" 9 22 10 23 #include "time_t.hfa" 11 24 #include "time.hfa" 25 26 //---------- 27 struct single_acquisition_lock { 28 inline blocking_lock; 29 }; 30 31 static inline void ?{}( single_acquisition_lock & this ) {((blocking_lock &)this){ false, false };} 32 static inline void ^?{}( single_acquisition_lock & this ) {} 33 static inline void lock ( single_acquisition_lock & this ) { lock ( (blocking_lock &)this ); } 34 static inline void unlock ( single_acquisition_lock & this ) { unlock ( (blocking_lock &)this ); } 35 static inline void on_wait ( single_acquisition_lock & this ) { on_wait( (blocking_lock &)this ); } 36 static inline void on_notify ( single_acquisition_lock & this, struct $thread * t ) { on_notify( (blocking_lock &)this, t ); } 37 static inline void set_recursion_count( single_acquisition_lock & this, size_t recursion ) { set_recursion_count( (blocking_lock &)this, recursion ); } 38 static inline size_t get_recursion_count( single_acquisition_lock & this ) { return get_recursion_count( (blocking_lock &)this ); } 39 40 //---------- 41 struct owner_lock { 42 inline blocking_lock; 43 }; 44 45 static inline void ?{}( owner_lock & this ) {((blocking_lock &)this){ true, true };} 46 static inline void ^?{}( owner_lock & this ) {} 47 static inline void lock ( owner_lock & this ) { lock ( (blocking_lock &)this ); } 48 static inline void unlock ( owner_lock & this ) { unlock ( (blocking_lock &)this ); } 49 static inline void on_wait ( owner_lock & this ) { on_wait( (blocking_lock &)this ); } 50 static inline void on_notify( owner_lock & this, struct $thread * t ) { on_notify( (blocking_lock &)this, t ); } 51 static inline void set_recursion_count( owner_lock & this, size_t recursion ) { set_recursion_count( (blocking_lock &)this, recursion ); } 52 static inline size_t get_recursion_count( owner_lock & this ) { return get_recursion_count( (blocking_lock &)this ); } 12 53 13 54 //----------------------------------------------------------------------------- … … 38 79 info_thread(L) *& Next( info_thread(L) * this ); 39 80 } 40 41 //-----------------------------------------------------------------------------42 // Blocking Locks43 struct blocking_lock {44 // Spin lock used for mutual exclusion45 __spinlock_t lock;46 47 // List of blocked threads48 Sequence( $thread ) blocked_threads;49 50 // Count of current blocked threads51 size_t wait_count;52 53 // Flag if the lock allows multiple acquisition54 bool multi_acquisition;55 56 // Flag if lock can be released by non owner57 bool strict_owner;58 59 // Current thread owning the lock60 struct $thread * owner;61 62 // Number of recursion level63 size_t recursion_count;64 };65 66 struct single_acquisition_lock {67 inline blocking_lock;68 };69 70 struct owner_lock {71 inline blocking_lock;72 };73 74 struct multiple_acquisition_lock {75 inline blocking_lock;76 };77 78 void ?{}( blocking_lock & this, bool multi_acquisition, bool strict_owner );79 void ^?{}( blocking_lock & this );80 81 void ?{}( single_acquisition_lock & this );82 void ^?{}( single_acquisition_lock & this );83 84 void ?{}( owner_lock & this );85 void ^?{}( owner_lock & this );86 87 void ?{}( multiple_acquisition_lock & this );88 void ^?{}( multiple_acquisition_lock & this );89 90 void lock( blocking_lock & this );91 bool try_lock( blocking_lock & this );92 void unlock( blocking_lock & this );93 void on_notify( blocking_lock & this, struct $thread * t );94 void on_wait( blocking_lock & this );95 size_t wait_count( blocking_lock & this );96 void set_recursion_count( blocking_lock & this, size_t recursion );97 size_t get_recursion_count( blocking_lock & this );98 99 void lock( single_acquisition_lock & this );100 void unlock( single_acquisition_lock & this );101 void on_notify( single_acquisition_lock & this, struct $thread * t );102 void on_wait( single_acquisition_lock & this );103 void set_recursion_count( single_acquisition_lock & this, size_t recursion );104 size_t get_recursion_count( single_acquisition_lock & this );105 106 void lock( owner_lock & this );107 void unlock( owner_lock & this );108 void on_notify( owner_lock & this, struct $thread * t );109 void on_wait( owner_lock & this );110 void set_recursion_count( owner_lock & this, size_t recursion );111 size_t get_recursion_count( owner_lock & this );112 113 void lock( multiple_acquisition_lock & this );114 void unlock( multiple_acquisition_lock & this );115 void on_notify( multiple_acquisition_lock & this, struct $thread * t );116 void on_wait( multiple_acquisition_lock & this );117 void set_recursion_count( multiple_acquisition_lock & this, size_t recursion );118 size_t get_recursion_count( multiple_acquisition_lock & this );119 81 120 82 //-----------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.