Changeset deada67 in mainline for kernel/test/synch/rwlock3.c


Ignore:
Timestamp:
2006-12-19T17:54:50Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
730376d
Parents:
6536a4a9
Message:

quiet variants of tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/test/synch/rwlock3.c

    r6536a4a9 rdeada67  
    3535#include <synch/rwlock.h>
    3636
    37 #define READERS         50
    38 #define WRITERS         50
     37#define THREADS 4
    3938
     39static atomic_t thread_count;
    4040static rwlock_t rwlock;
     41static bool sh_quiet;
    4142
    4243static void reader(void *arg)
    4344{
    4445        thread_detach(THREAD);
    45 
    46         printf("cpu%d, tid %d: trying to lock rwlock for reading....\n", CPU->id, THREAD->tid);         
     46       
     47        if (!sh_quiet)
     48                printf("cpu%d, tid %d: trying to lock rwlock for reading....\n", CPU->id, THREAD->tid);
     49       
    4750        rwlock_read_lock(&rwlock);
    48         rwlock_read_unlock(&rwlock);   
    49         printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid);               
    50 
    51         printf("cpu%d, tid %d: trying to lock rwlock for writing....\n", CPU->id, THREAD->tid);         
     51        rwlock_read_unlock(&rwlock);
     52       
     53        if (!sh_quiet) {
     54                printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid);               
     55                printf("cpu%d, tid %d: trying to lock rwlock for writing....\n", CPU->id, THREAD->tid);         
     56        }
    5257
    5358        rwlock_write_lock(&rwlock);
    5459        rwlock_write_unlock(&rwlock);
    55         printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid);                       
     60       
     61        if (!sh_quiet)
     62                printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid);
     63       
     64        atomic_dec(&thread_count);
    5665}
    5766
     
    6069        int i;
    6170        thread_t *thrd;
     71        sh_quiet = quiet;
     72       
     73        atomic_set(&thread_count, THREADS);
    6274       
    6375        rwlock_initialize(&rwlock);
    6476        rwlock_write_lock(&rwlock);
    6577       
    66         for (i = 0; i < 4; i++) {
     78        for (i = 0; i < THREADS; i++) {
    6779                thrd = thread_create(reader, NULL, TASK, 0, "reader", false);
    6880                if (thrd)
    6981                        thread_ready(thrd);
    70                 else
     82                else if (!quiet)
    7183                        printf("Could not create reader %d\n", i);
    7284        }
    7385
    7486        thread_sleep(1);
     87        rwlock_write_unlock(&rwlock);
    7588       
    76         rwlock_write_unlock(&rwlock);
     89        while (atomic_get(&thread_count) > 0) {
     90                if (!quiet)
     91                        printf("Threads left: %d\n", atomic_get(&thread_count));
     92                thread_sleep(1);
     93        }
    7794       
    7895        return NULL;
Note: See TracChangeset for help on using the changeset viewer.