#include <threading/rwlock.h>
#include <threading/rwlock_condvar.h>
#include <threading/spinlock.h>
+#include <threading/semaphore.h>
#include <threading/thread_value.h>
/*******************************************************************************
}
END_TEST
+/**
+ * Semaphore for different tests
+ */
+static semaphore_t *semaphore;
+
+static void *semaphore_run(void *data)
+{
+ semaphore->post(semaphore);
+ return NULL;
+}
+
+START_TEST(test_semaphore)
+{
+ thread_t *threads[THREADS];
+ int i, initial = 5;
+
+ semaphore = semaphore_create(initial);
+
+ for (i = 0; i < THREADS; i++)
+ {
+ threads[i] = thread_create(semaphore_run, NULL);
+ }
+ for (i = 0; i < THREADS + initial; i++)
+ {
+ semaphore->wait(semaphore);
+ }
+ for (i = 0; i < THREADS; i++)
+ {
+ threads[i]->join(threads[i]);
+ }
+
+ semaphore->destroy(semaphore);
+}
+END_TEST
+
static void *join_run(void *data)
{
/* force some context switches */
tcase_add_test(tc, test_rwlock_condvar_cancel);
suite_add_tcase(s, tc);
+ tc = tcase_create("semaphore");
+ tcase_add_test(tc, test_semaphore);
+ suite_add_tcase(s, tc);
+
tc = tcase_create("thread joining");
tcase_add_test(tc, test_join);
tcase_add_test(tc, test_join_exit);