/* * UW - Synchronization test code. * Tim Brecht July, 2013 * UW - uwvmstats tests code. * Tim Brecht January, 2014 */ #include #include #include #include #include #define NAME_LEN (30) static struct lock *testlock = NULL; static struct semaphore *donesem = NULL; #define NTESTLOOPS (5000) /* Needs to be evenly divisible by 8 */ #define NTESTTHREADS (8) #define START_VALUE (0) static volatile int test_value = START_VALUE; static int use_locks = 1; static void cleanitems(void) { kprintf("cleanitems: Destroying sems and locks\n"); lock_destroy(testlock); testlock = NULL; sem_destroy(donesem); donesem = NULL; test_value = START_VALUE; } static void inititems(void) { if (testlock==NULL) { testlock = lock_create("testlock"); if (testlock == NULL) { panic("synchtest: lock_create failed\n"); } } if (donesem==NULL) { donesem = sem_create("donesem", 0); if (donesem == NULL) { panic("synchtest: sem_create failed\n"); } } } /* This thread adds values to a global variable. */ static void add_thread(void *junk, unsigned long num) { int i; (void) num; (void) junk; for (i=0; i