summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/tsan/signal_cond.cc
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2015-11-24 13:28:27 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2015-11-24 13:28:27 +0000
commit941d0a756a0d5b37edaa6d0332ae46f0bc32cded (patch)
tree81dbe1810f12138fe321b080b169de87d0df3a25 /compiler-rt/test/tsan/signal_cond.cc
parent377cafbbbcc98f2cf19c72605b7bcc5fa3fcf0f3 (diff)
downloadbcm5719-llvm-941d0a756a0d5b37edaa6d0332ae46f0bc32cded.tar.gz
bcm5719-llvm-941d0a756a0d5b37edaa6d0332ae46f0bc32cded.zip
[tsan] Replace pthread semaphore in signal_cond.cc with barrier_wait
Pthread semaphores are not available on OS X. Let's replace sem_wait/sem_post with barrier_wait, which makes the test pass on OS X. I know that sem_wait/sem_post is intercepted by TSan, whereas barrier_wait is TSan-invisible, but the purpose of the test is not affected by this. Also, let's properly initialize the mutex and cond variables. Differential Revision: http://reviews.llvm.org/D14924 llvm-svn: 253980
Diffstat (limited to 'compiler-rt/test/tsan/signal_cond.cc')
-rw-r--r--compiler-rt/test/tsan/signal_cond.cc12
1 files changed, 7 insertions, 5 deletions
diff --git a/compiler-rt/test/tsan/signal_cond.cc b/compiler-rt/test/tsan/signal_cond.cc
index f5eae745d40..ff565ea4fff 100644
--- a/compiler-rt/test/tsan/signal_cond.cc
+++ b/compiler-rt/test/tsan/signal_cond.cc
@@ -11,12 +11,11 @@
int g_thread_run = 1;
pthread_mutex_t mutex;
pthread_cond_t cond;
-sem_t sem;
void sig_handler(int sig) {
(void)sig;
write(1, "SIGNAL\n", sizeof("SIGNAL\n") - 1);
- sem_post(&sem);
+ barrier_wait(&barrier);
}
void* my_thread(void* arg) {
@@ -28,7 +27,11 @@ void* my_thread(void* arg) {
}
int main() {
- sem_init(&sem, 0, 0);
+ barrier_init(&barrier, 2);
+
+ pthread_mutex_init(&mutex, 0);
+ pthread_cond_init(&cond, 0);
+
signal(SIGUSR1, &sig_handler);
pthread_t thr;
pthread_create(&thr, 0, &my_thread, 0);
@@ -36,8 +39,7 @@ int main() {
// (can't use barrier_wait for that)
sleep(1);
pthread_kill(thr, SIGUSR1);
- while (sem_wait(&sem) == -1 && errno == EINTR) {
- }
+ barrier_wait(&barrier);
pthread_mutex_lock(&mutex);
g_thread_run = 0;
pthread_cond_signal(&cond);
OpenPOWER on IntegriCloud