Refaktorace knihovny
[mirrors/Programs.git] / c / pthread_extra / pthread_multi.c
index 95c581ccefaf1ca776670f097bb89f03308c10f4..992e627c073731d6ae077f1b755948f906a7bb5d 100644 (file)
@@ -1,22 +1,8 @@
-/*
- * CFLAGS=-lpthread make pthread_multi
- */
-
-#include <pthread.h>
+#include <pthread_extra.h>
 #include <time.h>
 #include <stdio.h>
 #include <stdbool.h>
 
-#define pthread_mutex_swap(a, b) ({ pthread_mutex_t *s; s = (a); a = (b); b = s; })
-
-#define pthread_mutex_lock_two(a,b) pthread_mutex_timedlock_multi_generic((pthread_mutex_t *[2]){(a), (b)}, 2, true, NULL)
-#define pthread_mutex_timedlock_two(a,b,tm) pthread_mutex_timedlock_multi_generic((pthread_mutex_t *[2]){(a), (b)}, 2, true, (tm))
-#define pthread_mutex_trylock_two(a,b) pthread_mutex_timedlock_multi_generic((pthread_mutex_t *[2]){(a), (b)}, 2, false, NULL)
-
-#define pthread_mutex_lock_multi(lcks,cnt) pthread_mutex_timedlock_multi_generic((lcks),(cnt),true,NULL)
-#define pthread_mutex_timedlock_multi(lcks,cnt,tm) pthread_mutex_timedlock_multi_generic((lcks),(cnt),true,(tm))
-#define pthread_mutex_trylock_multi(lcks,cnt) pthread_mutex_timedlock_multi_generic((lcks),(cnt),false,NULL)
-
 /*
 //This is first prototype for two mutexes only, it is useful in order to understand how this all works
 //Currently it was replaced by macro with the same name
@@ -79,28 +65,3 @@ int pthread_mutex_timedlock_multi_generic(pthread_mutex_t **lck, int cnt, bool b
                pthread_mutex_swap(lck[0],lck[locked]);
        }
 }
-
-int main() {
-       //Prepare mutex array for tests
-       static pthread_mutex_t la = PTHREAD_MUTEX_INITIALIZER;
-       static pthread_mutex_t lb = PTHREAD_MUTEX_INITIALIZER;
-       static pthread_mutex_t lc = PTHREAD_MUTEX_INITIALIZER;
-       static pthread_mutex_t ld = PTHREAD_MUTEX_INITIALIZER;
-       static pthread_mutex_t *lck[4] = {&la, &lb, &lc, &ld};
-
-       //Set timeout
-       struct  timespec tm;
-       clock_gettime(CLOCK_REALTIME, &tm);
-       tm.tv_sec  += 5;
-
-       //Lock one of the locks for testing
-       pthread_mutex_lock(lck[2]);
-
-       if(!pthread_mutex_timedlock_multi(lck, 4, &tm)) {
-       //if(!pthread_mutex_timedlock_two(&la, lck[2], &tm)) {
-               printf("LOCKED!\n");
-       } else {
-               printf("FAILED!\n");
-       }
-
-}
This page took 0.135627 seconds and 4 git commands to generate.