|
From: <sv...@va...> - 2009-07-23 18:03:03
|
Author: bart
Date: 2009-07-23 19:02:52 +0100 (Thu, 23 Jul 2009)
New Revision: 10566
Log:
Ported the pth_inconsistent_cond_wait test program to Darwin.
Modified:
trunk/drd/tests/pth_inconsistent_cond_wait.c
Modified: trunk/drd/tests/pth_inconsistent_cond_wait.c
===================================================================
--- trunk/drd/tests/pth_inconsistent_cond_wait.c 2009-07-23 17:52:51 UTC (rev 10565)
+++ trunk/drd/tests/pth_inconsistent_cond_wait.c 2009-07-23 18:02:52 UTC (rev 10566)
@@ -39,18 +39,28 @@
sem_t* s_sem;
-static sem_t* create_semaphore()
+static sem_t* create_semaphore(const char* const name)
{
+#ifdef __APPLE__
+ sem_t* p = sem_open(name, O_CREAT, 0600, 0);
+ return p;
+#else
sem_t* p = malloc(sizeof(*p));
if (p)
sem_init(p, 0, 0);
return p;
+#endif
}
-static void destroy_semaphore(sem_t* p)
+static void destroy_semaphore(const char* const name, sem_t* p)
{
+#ifdef __APPLE__
+ sem_close(p);
+ sem_unlink(name);
+#else
sem_destroy(p);
free(p);
+#endif
}
static void* thread_func(void* mutex)
@@ -75,7 +85,9 @@
pthread_t tid2;
/* Initialize synchronization objects. */
- s_sem = create_semaphore();
+ char semaphore_name[32];
+ snprintf(semaphore_name, sizeof(semaphore_name), "semaphore-%d", getpid());
+ s_sem = create_semaphore(semaphore_name);
PTH_CALL(pthread_cond_init(&s_cond, 0));
PTH_CALL(pthread_mutex_init(&s_mutex1, 0));
PTH_CALL(pthread_mutex_init(&s_mutex2, 0));
@@ -87,7 +99,7 @@
/* Wait until both threads have called sem_post(). */
sem_wait(s_sem);
sem_wait(s_sem);
- destroy_semaphore(s_sem);
+ destroy_semaphore(semaphore_name, s_sem);
s_sem = 0;
/* Wait until both threads are waiting inside pthread_cond_wait(). */
|