ms-queue: more cleanup
[model-checker-benchmarks.git] / ms-queue / main.c
index 30d9da9..fefb386 100644 (file)
@@ -1,10 +1,33 @@
-#include "main.h"
 #include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
+#include <threads.h>
 
-unsigned procs = 2;
-unsigned iterations = 1;
+#include "my_queue.h"
+
+static int procs = 2;
+static int iterations = 1;
 private_t private;
-shared_mem_t *smp;
+static queue_t *queue;
+
+static void parse_args(int argc, char **argv)
+{
+       extern char *optarg;
+       int c;
+
+       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);
+               }
+       }
+}
 
 static void main_task(void *param)
 {
@@ -12,13 +35,12 @@ static void main_task(void *param)
        unsigned val;
        int pid = *((int *)param);
 
-       init_memory();
        init_private(pid);
        for (i = 0; i < iterations; i++) {
-               val = private.value;
-               enqueue(val);
-               val = dequeue();
-               private.value++;
+               val = 1 + pid * iterations + i;
+               enqueue(queue, val);
+
+               val = dequeue(queue);
        }
 }
 
@@ -31,14 +53,14 @@ int user_main(int argc, char **argv)
        parse_args(argc, argv);
        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;
        t = malloc(num_threads * sizeof(thrd_t));
        param = malloc(num_threads * sizeof(*param));
 
-       init_queue();
+       init_queue(queue);
        for (i = 0; i < num_threads; i++) {
                param[i] = i;
                thrd_create(&t[i], main_task, &param[i]);
@@ -48,7 +70,7 @@ int user_main(int argc, char **argv)
 
        free(param);
        free(t);
-       free(smp);
+       free(queue);
 
        return 0;
 }