- Timestamp:
- Oct 1, 2020, 3:54:39 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:
- 91131689
- Parents:
- ebec8ed (diff), dd53f75 (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:
- doc/theses/thierry_delisle_PhD/code/readQ_example
- Files:
-
- 6 added
- 1 deleted
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/thierry_delisle_PhD/code/readQ_example/proto-gui/main.cpp
rebec8ed r615767b 1 #include "thrdlib/thread.h "1 #include "thrdlib/thread.hpp" 2 2 3 3 #include <cassert> … … 5 5 #include <algorithm> 6 6 #include <atomic> 7 #include <iostream> 7 8 #include <memory> 8 9 #include <vector> 9 10 10 11 #include <getopt.h> 12 using thrdlib::thread_t; 13 14 15 extern __attribute__((aligned(128))) thread_local struct { 16 void * volatile this_thread; 17 void * volatile this_processor; 18 void * volatile this_stats; 19 20 struct { 21 volatile unsigned short disable_count; 22 volatile bool enabled; 23 volatile bool in_progress; 24 } preemption_state; 25 26 #if defined(__SIZEOF_INT128__) 27 __uint128_t rand_seed; 28 #else 29 uint64_t rand_seed; 30 #endif 31 struct { 32 uint64_t fwd_seed; 33 uint64_t bck_seed; 34 } ready_rng; 35 } kernelTLS __attribute__ ((tls_model ( "initial-exec" ))); 11 36 12 37 //-------------------- … … 36 61 assert( expected == reset ); 37 62 if( std::atomic_compare_exchange_strong( &state, &expected, self) ) { 38 thrdlib _park( self );63 thrdlib::park( self ); 39 64 ret = true; 40 65 goto END; … … 54 79 if( got == reset ) return false; 55 80 56 thrdlib _unpark( got );81 thrdlib::unpark( got ); 57 82 return true; 58 83 } … … 109 134 the_stats_thread = self; 110 135 fence(); 111 thrdlib _park( self );136 thrdlib::park( self ); 112 137 113 138 std::vector<bool> seen; … … 115 140 116 141 while(last_produced < nproduce) { 117 thrdlib _yield();142 thrdlib::yield(); 118 143 thrd_stats.stats.ran++; 119 144 if( last_produced > 0 ) seen.at(last_produced - 1) = true; … … 147 172 148 173 void Renderer( thread_t self ) { 149 thrdlib _unpark( the_stats_thread );174 thrdlib::unpark( the_stats_thread ); 150 175 for(unsigned i = 0; i < nproduce; i++) { 151 176 auto & frame = frames[i % nframes]; … … 178 203 fsize = 1000; 179 204 nproduce = 60; 205 206 const char * framework; 180 207 181 208 for(;;) { … … 196 223 case -1: 197 224 /* paranoid */ assert(optind <= argc); 225 if( optind == argc ) { 226 std::cerr << "Must specify a framework" << std::endl; 227 goto usage; 228 229 } 230 framework = argv[optind]; 198 231 goto run; 199 232 case 'b': … … 228 261 std::cerr << opt << std::endl; 229 262 usage: 230 std::cerr << "Usage: " << argv[0] << " [options] " << std::endl;263 std::cerr << "Usage: " << argv[0] << " [options] framework" << std::endl; 231 264 std::cerr << std::endl; 232 265 std::cerr << " -b, --buff=COUNT Number of frames to buffer" << std::endl; … … 237 270 } 238 271 run: 272 assert( framework ); 239 273 240 274 frames.reset(new Frame[nframes]); … … 246 280 std::cout << "(Buffering " << nframes << ")" << std::endl; 247 281 248 thrdlib _setproccnt(2 );249 250 thread_t stats = thrdlib _create( Stats);282 thrdlib::init( framework, 2 ); 283 284 thread_t stats = thrdlib::create( Stats ); 251 285 std::cout << "Created Stats Thread" << std::endl; 252 while( the_stats_thread == nullptr ) thrdlib_yield(); 286 while( the_stats_thread == nullptr ) thrdlib::yield(); 287 253 288 std::cout << "Creating Main Threads" << std::endl; 254 thread_t renderer = thrdlib_create( Renderer ); 255 // while(true); 256 thread_t simulator = thrdlib_create( Simulator ); 289 thread_t renderer = thrdlib::create( Renderer ); 290 thread_t simulator = thrdlib::create( Simulator ); 257 291 258 292 std::cout << "Running" << std::endl; 259 293 260 thrdlib_join( simulator ); 261 thrdlib_join( renderer ); 262 thrdlib_join( stats ); 294 thrdlib::join( simulator ); 295 thrdlib::join( renderer ); 296 thrdlib::join( stats ); 297 298 thrdlib::clean(); 263 299 264 300 std::cout << "----------" << std::endl; -
doc/theses/thierry_delisle_PhD/code/readQ_example/thrdlib/pthread.cpp
rebec8ed r615767b 1 #pragma once2 3 1 #include <pthread.h> 4 2 #include <errno.h> … … 56 54 #undef CHECKED 57 55 58 #if defined(__cforall) || defined(__cpluplus) 56 //-------------------- 57 // Basic types 58 struct pthread_runner_t { 59 pthread_t handle; 60 __bin_sem_t sem; 61 }; 62 typedef pthread_runner_t * thread_t; 63 64 static_assert(sizeof(thread_t) == sizeof(void*), "thread_t musst be of same size as void*"); 65 59 66 extern "C" { 60 #endif61 //--------------------62 // Basic types63 struct pthread_runner_t {64 pthread_t handle;65 __bin_sem_t sem;66 };67 typedef pthread_runner_t * thread_t;68 69 67 //-------------------- 70 68 // Basic thread support … … 98 96 //-------------------- 99 97 // Basic kernel features 100 void thrdlib_setproccnt( int ) { 101 102 } 103 104 105 #if defined(__cforall) || defined(__cpluplus) 98 void thrdlib_init( int ) {} 106 99 } 107 #endif
Note: See TracChangeset
for help on using the changeset viewer.