Changeset c90db2d for libcfa/src/concurrency
- Timestamp:
- Jan 14, 2022, 7:01:21 PM (2 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- a2a4566
- Parents:
- 145dcd5 (diff), 9ee3f54 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- libcfa/src/concurrency
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/clib/cfathread.cfa
r145dcd5 rc90db2d 22 22 #include "thread.hfa" 23 23 #include "time.hfa" 24 #include "stdlib.hfa" 24 25 25 26 #include "cfathread.h" … … 195 196 eevent.data.u64 = (uint64_t)active_thread(); 196 197 197 int id = thread_rand() % poller_cnt;198 int id = prng() % poller_cnt; 198 199 if(0 != epoll_ctl(poller_fds[id], EPOLL_CTL_ADD, fd, &eevent)) 199 200 { -
libcfa/src/concurrency/kernel/fwd.hfa
r145dcd5 rc90db2d 79 79 return 80 80 #if defined(__SIZEOF_INT128__) 81 __lehmer64( kernelTLS().rand_seed );81 lehmer64( kernelTLS().rand_seed ); 82 82 #else 83 __xorshift64( kernelTLS().rand_seed );83 xorshift_13_7_17( kernelTLS().rand_seed ); 84 84 #endif 85 85 } 86 86 87 #define M (1_l64u << 48_l64u)88 #define A (25214903917_l64u)89 #define AI (18446708753438544741_l64u)90 #define C (11_l64u)91 #define D (16_l64u)92 93 87 static inline unsigned __tls_rand_fwd() { 94 kernelTLS().ready_rng.fwd_seed = (A * kernelTLS().ready_rng.fwd_seed + C) & (M - 1); 95 return kernelTLS().ready_rng.fwd_seed >> D; 88 return LCGBI_fwd( kernelTLS().ready_rng.fwd_seed ); 96 89 } 97 90 98 91 static inline unsigned __tls_rand_bck() { 99 unsigned int r = kernelTLS().ready_rng.bck_seed >> D; 100 kernelTLS().ready_rng.bck_seed = AI * (kernelTLS().ready_rng.bck_seed - C) & (M - 1); 101 return r; 102 } 103 104 #undef M 105 #undef A 106 #undef AI 107 #undef C 108 #undef D 92 return LCGBI_bck( kernelTLS().ready_rng.bck_seed ); 93 } 109 94 110 95 static inline void __tls_rand_advance_bck(void) { … … 140 125 } 141 126 } 142 143 extern uint64_t thread_rand();144 127 145 128 // Semaphore which only supports a single thread -
libcfa/src/concurrency/kernel/startup.cfa
r145dcd5 rc90db2d 102 102 extern void __wake_proc(processor *); 103 103 extern int cfa_main_returned; // from interpose.cfa 104 extern uint32_t __global_random_seed; 104 105 105 106 //----------------------------------------------------------------------------- … … 175 176 this.context = &storage_mainThreadCtx; 176 177 } 177 178 178 179 179 … … 490 490 preferred = ready_queue_new_preferred(); 491 491 last_proc = 0p; 492 random_state = __global_random_seed; 492 493 #if defined( __CFA_WITH_VERIFY__ ) 493 494 canary = 0x0D15EA5E0D15EA5Ep; -
libcfa/src/concurrency/thread.cfa
r145dcd5 rc90db2d 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jan 10 17:05:35 202213 // Update Count : 2812 // Last Modified On : Thu Jan 13 20:11:55 2022 13 // Update Count : 42 14 14 // 15 15 … … 25 25 #include "invoke.h" 26 26 27 uint64_t thread_rand(); 28 29 extern uint32_t __thread_seed; // global thread seed 27 extern uint32_t __global_random_seed; 30 28 31 29 //----------------------------------------------------------------------------- … … 41 39 self_mon.owner = &this; 42 40 self_mon.recursion = 1; 43 random_state = __thread_seed;44 41 self_mon_p = &self_mon; 45 42 curr_cluster = &cl; … … 48 45 preferred = ready_queue_new_preferred(); 49 46 last_proc = 0p; 47 random_state = __global_random_seed; 50 48 #if defined( __CFA_WITH_VERIFY__ ) 51 49 canary = 0x0D15EA5E0D15EA5Ep; … … 174 172 } 175 173 176 uint64_t thread_rand() { 177 disable_interrupts(); 178 uint64_t ret = __tls_rand(); 179 enable_interrupts(); 180 return ret; 181 } 182 174 //----------------------------------------------------------------------------- 183 175 #define GENERATOR LCG 184 176 185 inline uint32_t MarsagliaXor( uint32_t & state ) { 186 state ^= state << 6; 187 state ^= state >> 21; 188 state ^= state << 7; 189 return state; 190 } // MarsagliaXor 191 192 inline uint32_t LCG( uint32_t & state ) { // linear congruential generator 193 return state = 36969 * (state & 65535) + (state >> 16); // 36969 is NOT prime! 194 } // LCG 195 196 void set_seed( uint32_t seed ) { active_thread()->random_state = seed; __thread_seed = seed; } 177 void set_seed( uint32_t seed ) { 178 active_thread()->random_state = __global_random_seed = seed; 179 GENERATOR( active_thread()->random_state ); 180 } // set_seed 197 181 uint32_t prng( void ) { return GENERATOR( active_thread()->random_state ); } // [0,UINT_MAX] 198 182
Note: See TracChangeset
for help on using the changeset viewer.