Changes in / [6ff08d8:a953c2e3]


Ignore:
Files:
2 deleted
3 edited

Legend:

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

    r6ff08d8 ra953c2e3  
    276276static inline void  ?{}( linear_backoff_then_block_lock & this ) { this{4, 1024, 16, 0}; }
    277277static 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;
    280278
    281279static 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>
    12#include <locks.hfa>
     3#include <thread.hfa>
    24
    3 #define LOCK fast_lock
    4 #include "mutex_test.hfa"
     5const unsigned int num_times = 50;
     6
     7struct MutexObj {
     8        fast_lock l;
     9        thread$ * id;
     10        uint32_t sum;
     11};
     12
     13MutexObj mo;
     14
     15void trash() {
     16        unsigned t[100];
     17        for(i; 100) {
     18                t[i] = 0xDEADBEEF;
     19        }
     20}
     21
     22uint32_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
     38thread LockCheck {
     39        uint32_t sum;
     40};
     41
     42void 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}
    551
    652int 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;
    866}
  • tests/unified_locking/thread_test.cfa

    r6ff08d8 ra953c2e3  
    88static unsigned int threadCount = 2;
    99static unsigned int lockCount = 1;
    10 static unsigned int total_times = 320000;
    11 static unsigned int num_times;
     10static unsigned int num_times = 10000;
    1211static const int workBufferSize = 16;
    1312static unsigned int work_unlocked = 10000;
     
    2625thread worker {
    2726    linear_backoff_then_block_lock * locks;
    28     bool improved;
    2927};
    3028
    31 void ?{}( worker & w, linear_backoff_then_block_lock * locks, bool improved ) {
     29void ?{}( worker & w, linear_backoff_then_block_lock * locks ) {
    3230        w.locks = locks;
    33     w.improved = improved;
    3431}
    3532
     33linear_backoff_then_block_lock norm_lock;
    3634
    3735void main( worker & this ) with(this) {
     
    3937    for (int i = 0; i < workBufferSize; i += 1) buffer[i] = rand() % 1024;
    4038    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];
    4240    for (unsigned int i = 0; i < num_times; i++) {
    4341        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);
    4645        dowork(buffer, work_locked);
     46        //printf("lock: %d %p LEAVE\n", i, &curr_lock);
    4747        unlock(*curr_lock);
     48        //unlock(norm_lock);
    4849        lck = rand() % lockCount;
    49         curr_lock = &locks[lck];
     50        //curr_lock = locks[lck];
    5051    }
    5152}
    5253
    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]);
    6056        case 5:
    6157            num_times = atoi(argv[4]);
     
    7268    }
    7369        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);
    7572    worker * worker_arr[taskCount];
    76     num_times = total_times  / taskCount;
    7773
    78         //printf("Start Test: martin lock simple\n");
     74        printf("Start Test: martin lock simple\n");
    7975        clock_t begin = clock();
    8076        for (unsigned int i = 0; i < taskCount; i++) {
    81         worker_arr[i] = new( locks, false );
     77        worker_arr[i] = new( &locks );
    8278    }
    8379    for (unsigned int i = 0; i < taskCount; i++) {
    84         delete( worker_arr[i] );
     80        free( worker_arr[i] );
    8581    }
    8682        clock_t end = clock();
    8783        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);
    10185}
Note: See TracChangeset for help on using the changeset viewer.