Changes in / [a953c2e3:6ff08d8]
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.hfa
ra953c2e3 r6ff08d8 276 276 static inline void ?{}( linear_backoff_then_block_lock & this ) { this{4, 1024, 16, 0}; } 277 277 static inline void ^?{}( linear_backoff_then_block_lock & this ) {} 278 static inline void ?{}( linear_backoff_then_block_lock & this, linear_backoff_then_block_lock this2 ) = void; 279 static inline void ?=?( linear_backoff_then_block_lock & this, linear_backoff_then_block_lock this2 ) = void; 278 280 279 281 static inline bool internal_try_lock(linear_backoff_then_block_lock & this, size_t & compare_val) with(this) { -
tests/unified_locking/fast.cfa
ra953c2e3 r6ff08d8 1 #include <fstream.hfa>2 1 #include <locks.hfa> 3 #include <thread.hfa>4 2 5 const unsigned int num_times = 50; 6 7 struct MutexObj { 8 fast_lock l; 9 thread$ * id; 10 uint32_t sum; 11 }; 12 13 MutexObj mo; 14 15 void trash() { 16 unsigned t[100]; 17 for(i; 100) { 18 t[i] = 0xDEADBEEF; 19 } 20 } 21 22 uint32_t cs() { 23 thread$ * me = active_thread(); 24 uint32_t value; 25 lock(mo.l); 26 { 27 uint32_t tsum = mo.sum; 28 mo.id = me; 29 yield(random(5)); 30 value = ((uint32_t)random()) ^ ((uint32_t)me); 31 if(mo.id != me) sout | "Intruder!"; 32 mo.sum = tsum + value; 33 } 34 unlock(mo.l); 35 return value; 36 } 37 38 thread LockCheck { 39 uint32_t sum; 40 }; 41 42 void main(LockCheck & this) { 43 this.sum = 0; 44 for(num_times) { 45 trash(); 46 this.sum += cs(); 47 trash(); 48 yield(random(10)); 49 } 50 } 3 #define LOCK fast_lock 4 #include "mutex_test.hfa" 51 5 52 6 int main() { 53 uint32_t sum = -32; 54 mo.sum = -32; 55 processor p[2]; 56 sout | "Starting"; 57 { 58 LockCheck checkers[13]; 59 for(i;13) { 60 sum += join(checkers[i]).sum; 61 } 62 } 63 sout | "Done!"; 64 if(sum == mo.sum) sout | "Match!"; 65 else sout | "No Match!" | sum | "vs" | mo.sum; 7 test(); 66 8 } -
tests/unified_locking/thread_test.cfa
ra953c2e3 r6ff08d8 8 8 static unsigned int threadCount = 2; 9 9 static unsigned int lockCount = 1; 10 static unsigned int num_times = 10000; 10 static unsigned int total_times = 320000; 11 static unsigned int num_times; 11 12 static const int workBufferSize = 16; 12 13 static unsigned int work_unlocked = 10000; … … 25 26 thread worker { 26 27 linear_backoff_then_block_lock * locks; 28 bool improved; 27 29 }; 28 30 29 void ?{}( worker & w, linear_backoff_then_block_lock * locks ) {31 void ?{}( worker & w, linear_backoff_then_block_lock * locks, bool improved ) { 30 32 w.locks = locks; 33 w.improved = improved; 31 34 } 32 35 33 linear_backoff_then_block_lock norm_lock;34 36 35 37 void main( worker & this ) with(this) { … … 37 39 for (int i = 0; i < workBufferSize; i += 1) buffer[i] = rand() % 1024; 38 40 unsigned int lck = rand() % lockCount; 39 linear_backoff_then_block_lock * curr_lock = locks;//[lck];41 linear_backoff_then_block_lock * curr_lock = &locks[lck]; 40 42 for (unsigned int i = 0; i < num_times; i++) { 41 43 dowork(buffer, work_unlocked); 42 lock(*curr_lock); 43 //printf("lock: %d %p ENTER\n", i, &curr_lock); 44 //lock(norm_lock); 44 if (improved) lock_improved(*curr_lock); 45 else lock(*curr_lock); 45 46 dowork(buffer, work_locked); 46 //printf("lock: %d %p LEAVE\n", i, &curr_lock);47 47 unlock(*curr_lock); 48 //unlock(norm_lock);49 48 lck = rand() % lockCount; 50 //curr_lock =locks[lck];49 curr_lock = &locks[lck]; 51 50 } 52 51 } 53 52 53 54 54 int main(int argc, char* argv[]) { 55 55 switch (argc) { 56 case 7: 57 work_unlocked = atoi(argv[5]); 58 case 6: 59 work_locked = atoi(argv[5]); 56 60 case 5: 57 61 num_times = atoi(argv[4]); … … 68 72 } 69 73 processor p[threadCount]; 70 linear_backoff_then_block_lock locks;//[lockCount]; 71 printf("lock allocation address: %p \n", &locks); 74 linear_backoff_then_block_lock locks[lockCount]; 72 75 worker * worker_arr[taskCount]; 76 num_times = total_times / taskCount; 73 77 74 printf("Start Test: martin lock simple\n");78 //printf("Start Test: martin lock simple\n"); 75 79 clock_t begin = clock(); 76 80 for (unsigned int i = 0; i < taskCount; i++) { 77 worker_arr[i] = new( &locks);81 worker_arr[i] = new( locks, false ); 78 82 } 79 83 for (unsigned int i = 0; i < taskCount; i++) { 80 free( worker_arr[i] );84 delete( worker_arr[i] ); 81 85 } 82 86 clock_t end = clock(); 83 87 double time_spent = (double)(end - begin) / CLOCKS_PER_SEC; 84 printf("Done Test, time: %f\n", time_spent); 88 printf("norm: %f\n", time_spent); 89 90 //printf("Start Test: martin lock improved\n"); 91 begin = clock(); 92 for (unsigned int i = 0; i < taskCount; i++) { 93 worker_arr[i] = new( locks, true ); 94 } 95 for (unsigned int i = 0; i < taskCount; i++) { 96 delete( worker_arr[i] ); 97 } 98 end = clock(); 99 time_spent = (double)(end - begin) / CLOCKS_PER_SEC; 100 printf("improved: %f\n", time_spent); 85 101 }
Note: See TracChangeset
for help on using the changeset viewer.