Changes in / [a953c2e3:6ff08d8]


Ignore:
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/locks.hfa

    ra953c2e3 r6ff08d8  
    276276static inline void  ?{}( linear_backoff_then_block_lock & this ) { this{4, 1024, 16, 0}; }
    277277static inline void ^?{}( linear_backoff_then_block_lock & this ) {}
     278static inline void ?{}( linear_backoff_then_block_lock & this, linear_backoff_then_block_lock this2 ) = void;
     279static inline void ?=?( linear_backoff_then_block_lock & this, linear_backoff_then_block_lock this2 ) = void;
    278280
    279281static 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>
    21#include <locks.hfa>
    3 #include <thread.hfa>
    42
    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"
    515
    526int 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();
    668}
  • tests/unified_locking/thread_test.cfa

    ra953c2e3 r6ff08d8  
    88static unsigned int threadCount = 2;
    99static unsigned int lockCount = 1;
    10 static unsigned int num_times = 10000;
     10static unsigned int total_times = 320000;
     11static unsigned int num_times;
    1112static const int workBufferSize = 16;
    1213static unsigned int work_unlocked = 10000;
     
    2526thread worker {
    2627    linear_backoff_then_block_lock * locks;
     28    bool improved;
    2729};
    2830
    29 void ?{}( worker & w, linear_backoff_then_block_lock * locks ) {
     31void ?{}( worker & w, linear_backoff_then_block_lock * locks, bool improved ) {
    3032        w.locks = locks;
     33    w.improved = improved;
    3134}
    3235
    33 linear_backoff_then_block_lock norm_lock;
    3436
    3537void main( worker & this ) with(this) {
     
    3739    for (int i = 0; i < workBufferSize; i += 1) buffer[i] = rand() % 1024;
    3840    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];
    4042    for (unsigned int i = 0; i < num_times; i++) {
    4143        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);
    4546        dowork(buffer, work_locked);
    46         //printf("lock: %d %p LEAVE\n", i, &curr_lock);
    4747        unlock(*curr_lock);
    48         //unlock(norm_lock);
    4948        lck = rand() % lockCount;
    50         //curr_lock = locks[lck];
     49        curr_lock = &locks[lck];
    5150    }
    5251}
    5352
     53
    5454int main(int argc, char* argv[]) {
    5555    switch (argc) {
     56        case 7:
     57            work_unlocked = atoi(argv[5]);
     58        case 6:
     59            work_locked = atoi(argv[5]);
    5660        case 5:
    5761            num_times = atoi(argv[4]);
     
    6872    }
    6973        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];
    7275    worker * worker_arr[taskCount];
     76    num_times = total_times  / taskCount;
    7377
    74         printf("Start Test: martin lock simple\n");
     78        //printf("Start Test: martin lock simple\n");
    7579        clock_t begin = clock();
    7680        for (unsigned int i = 0; i < taskCount; i++) {
    77         worker_arr[i] = new( &locks );
     81        worker_arr[i] = new( locks, false );
    7882    }
    7983    for (unsigned int i = 0; i < taskCount; i++) {
    80         free( worker_arr[i] );
     84        delete( worker_arr[i] );
    8185    }
    8286        clock_t end = clock();
    8387        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);
    85101}
Note: See TracChangeset for help on using the changeset viewer.