ms-queue: more cleanup
[model-checker-benchmarks.git] / ms-queue / main.c
index 015fbd4..fefb386 100644 (file)
@@ -1,55 +1,46 @@
-#include "main.h"
 #include <stdlib.h>
 #include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
+#include <threads.h>
 
 
-#define NUM_PROCESSORS                 12
+#include "my_queue.h"
 
 
-struct tms tim;
-struct tms tim1;
-
-int shmid;
-
-unsigned pid;
-char* name = "";
-unsigned procs = 1;
-unsigned multi = 1;
-unsigned iterations = 1;
-unsigned initial_nodes = 0;
-unsigned repetitions = 1;
-unsigned work = 0;
+static int procs = 2;
+static int iterations = 1;
 private_t private;
 private_t private;
-shared_mem_t *smp;
+static queue_t *queue;
 
 
-void time_test()
+static void parse_args(int argc, char **argv)
 {
 {
-       unsigned i,j;
-       struct tms time_val;
-       clock_t t1, t2;
-       unsigned val;
+       extern char *optarg;
+       int c;
 
 
-       if(pid==0) {
-               init_queue();
-       }
-       init_memory();
-       init_private();
-       for(i=0;i<iterations;i++) {
-               val = private.value;
-               enqueue(val);
-               for(j=0; j<work;) j++;
-               val = dequeue();
-               for(j=0; j<work;) j++;
-               private.value++;
+       while ((c = getopt(argc, argv, "i:p:")) != EOF) {
+               switch (c) {
+               case 'i':
+                       iterations = atoi(optarg);
+                       break;
+               case 'p':
+                       procs = atoi(optarg);
+                       break;
+               default:
+                       assert(0);
+               }
        }
 }
 
        }
 }
 
-void main_task()
+static void main_task(void *param)
 {
 {
-       unsigned processor;
-       unsigned i;
+       unsigned i, j;
+       unsigned val;
+       int pid = *((int *)param);
+
+       init_private(pid);
+       for (i = 0; i < iterations; i++) {
+               val = 1 + pid * iterations + i;
+               enqueue(queue, val);
 
 
-       processor = (pid/multi)+1;
-       processor %= NUM_PROCESSORS;
-       for (i=0; i<repetitions; i++) {
-               time_test();
+               val = dequeue(queue);
        }
 }
 
        }
 }
 
@@ -57,24 +48,29 @@ int user_main(int argc, char **argv)
 {
        int i, num_threads;
        thrd_t *t;
 {
        int i, num_threads;
        thrd_t *t;
+       int *param;
 
        parse_args(argc, argv);
 
        parse_args(argc, argv);
-       name = argv[0];
-       iterations = (iterations + ((procs*multi)>>1))/(procs*multi);
+       iterations = (iterations + (procs >> 1)) / procs;
 
 
-       smp = (shared_mem_t *)calloc(1, sizeof(shared_mem_t));
-       assert(smp);
+       queue = calloc(1, sizeof(*queue));
+       assert(queue);
 
 
-       num_threads = procs * multi;
+       num_threads = procs;
        t = malloc(num_threads * sizeof(thrd_t));
        t = malloc(num_threads * sizeof(thrd_t));
+       param = malloc(num_threads * sizeof(*param));
 
 
-       for (i = 0; i < num_threads; i++)
-               thrd_create(&t[i], main_task, NULL);
+       init_queue(queue);
+       for (i = 0; i < num_threads; i++) {
+               param[i] = i;
+               thrd_create(&t[i], main_task, &param[i]);
+       }
        for (i = 0; i < num_threads; i++)
                thrd_join(t[i]);
 
        for (i = 0; i < num_threads; i++)
                thrd_join(t[i]);
 
+       free(param);
        free(t);
        free(t);
-       free(smp);
+       free(queue);
 
        return 0;
 }
 
        return 0;
 }