2 * Copyright (C) 2013 Tobias Brunner
3 * Copyright (C) 2008 Martin Willi
4 * Hochschule fuer Technik Rapperswil
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 #include "test_suite.h"
22 #include <threading/mutex.h>
24 /*******************************************************************************
25 * recursive mutex test
30 static mutex_t
*mutex
;
32 static pthread_barrier_t mutex_barrier
;
34 static int mutex_locked
= 0;
36 static void *mutex_run(void *data
)
40 /* wait for all threads before getting in action */
41 pthread_barrier_wait(&mutex_barrier
);
43 for (i
= 0; i
< 100; i
++)
52 fail("two threads locked the mutex concurrently");
62 START_TEST(test_mutex
)
64 pthread_t threads
[THREADS
];
67 mutex
= mutex_create(MUTEX_TYPE_RECURSIVE
);
69 for (i
= 0; i
< 10; i
++)
74 for (i
= 0; i
< 10; i
++)
78 for (i
= 0; i
< 10; i
++)
83 pthread_barrier_init(&mutex_barrier
, NULL
, THREADS
);
84 for (i
= 0; i
< THREADS
; i
++)
86 pthread_create(&threads
[i
], NULL
, mutex_run
, NULL
);
88 for (i
= 0; i
< THREADS
; i
++)
90 pthread_join(threads
[i
], NULL
);
92 pthread_barrier_destroy(&mutex_barrier
);
94 mutex
->destroy(mutex
);
98 Suite
*threading_suite_create()
103 s
= suite_create("threading");
105 tc
= tcase_create("recursive mutex");
106 tcase_add_test(tc
, test_mutex
);
107 suite_add_tcase(s
, tc
);