X-Git-Url: https://git.harvie.cz/?a=blobdiff_plain;f=c%2Fpthread_extra%2Fpthread_multi.c;h=992e627c073731d6ae077f1b755948f906a7bb5d;hb=3aac261937c3a94461f4dd8fa64c17d5e158c692;hp=95c581ccefaf1ca776670f097bb89f03308c10f4;hpb=63658368a85bba1239a9049b6bbd4ea4d87469b2;p=mirrors%2FPrograms.git diff --git a/c/pthread_extra/pthread_multi.c b/c/pthread_extra/pthread_multi.c index 95c581c..992e627 100644 --- a/c/pthread_extra/pthread_multi.c +++ b/c/pthread_extra/pthread_multi.c @@ -1,22 +1,8 @@ -/* - * CFLAGS=-lpthread make pthread_multi - */ - -#include +#include #include #include #include -#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"); - } - -}