Changes in / [6ff08d8:a953c2e3]
- Files:
-
- 2 deleted
- 3 edited
-
libcfa/src/concurrency/locks.hfa (modified) (1 diff)
-
tests/unified_locking/fast.cfa (modified) (1 diff)
-
tests/unified_locking/lin_backoff.cfa (deleted)
-
tests/unified_locking/mutex_test.hfa (deleted)
-
tests/unified_locking/thread_test.cfa (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.hfa
r6ff08d8 ra953c2e3 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;280 278 281 279 static inline bool internal_try_lock(linear_backoff_then_block_lock & this, size_t & compare_val) with(this) { -
tests/unified_locking/fast.cfa
r6ff08d8 ra953c2e3 1 #include <fstream.hfa> 1 2 #include <locks.hfa> 3 #include <thread.hfa> 2 4 3 #define LOCK fast_lock 4 #include "mutex_test.hfa" 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 } 5 51 6 52 int main() { 7 test(); 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; 8 66 } -
tests/unified_locking/thread_test.cfa
r6ff08d8 ra953c2e3 8 8 static unsigned int threadCount = 2; 9 9 static unsigned int lockCount = 1; 10 static unsigned int total_times = 320000; 11 static unsigned int num_times; 10 static unsigned int num_times = 10000; 12 11 static const int workBufferSize = 16; 13 12 static unsigned int work_unlocked = 10000; … … 26 25 thread worker { 27 26 linear_backoff_then_block_lock * locks; 28 bool improved;29 27 }; 30 28 31 void ?{}( worker & w, linear_backoff_then_block_lock * locks , bool improved) {29 void ?{}( worker & w, linear_backoff_then_block_lock * locks ) { 32 30 w.locks = locks; 33 w.improved = improved;34 31 } 35 32 33 linear_backoff_then_block_lock norm_lock; 36 34 37 35 void main( worker & this ) with(this) { … … 39 37 for (int i = 0; i < workBufferSize; i += 1) buffer[i] = rand() % 1024; 40 38 unsigned int lck = rand() % lockCount; 41 linear_backoff_then_block_lock * curr_lock = &locks[lck];39 linear_backoff_then_block_lock * curr_lock = locks;//[lck]; 42 40 for (unsigned int i = 0; i < num_times; i++) { 43 41 dowork(buffer, work_unlocked); 44 if (improved) lock_improved(*curr_lock); 45 else lock(*curr_lock); 42 lock(*curr_lock); 43 //printf("lock: %d %p ENTER\n", i, &curr_lock); 44 //lock(norm_lock); 46 45 dowork(buffer, work_locked); 46 //printf("lock: %d %p LEAVE\n", i, &curr_lock); 47 47 unlock(*curr_lock); 48 //unlock(norm_lock); 48 49 lck = rand() % lockCount; 49 curr_lock = &locks[lck];50 //curr_lock = locks[lck]; 50 51 } 51 52 } 52 53 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]);60 56 case 5: 61 57 num_times = atoi(argv[4]); … … 72 68 } 73 69 processor p[threadCount]; 74 linear_backoff_then_block_lock locks[lockCount]; 70 linear_backoff_then_block_lock locks;//[lockCount]; 71 printf("lock allocation address: %p \n", &locks); 75 72 worker * worker_arr[taskCount]; 76 num_times = total_times / taskCount;77 73 78 //printf("Start Test: martin lock simple\n");74 printf("Start Test: martin lock simple\n"); 79 75 clock_t begin = clock(); 80 76 for (unsigned int i = 0; i < taskCount; i++) { 81 worker_arr[i] = new( locks, false);77 worker_arr[i] = new( &locks ); 82 78 } 83 79 for (unsigned int i = 0; i < taskCount; i++) { 84 delete( worker_arr[i] );80 free( worker_arr[i] ); 85 81 } 86 82 clock_t end = clock(); 87 83 double time_spent = (double)(end - begin) / CLOCKS_PER_SEC; 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); 84 printf("Done Test, time: %f\n", time_spent); 101 85 }
Note:
See TracChangeset
for help on using the changeset viewer.