sr-761-a.patch 3.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
From 5e1aad762cb93a54609de5fe49661e77323b3fa3 Mon Sep 17 00:00:00 2001
From: Hubertus Franke <frankeh@us.ibm.com>
Date: Wed, 24 Feb 2016 17:58:40 -0500
Subject: [PATCH] Enable notification to libpwq before semaphore waiting

Drew's reroll with:

* libpwq update to origin/master (e16bcd6c4b4df3fd85939a981baf94b30968a1ba)
* futex support per https://bugs.swift.org/browse/SR-761?focusedCommentId=12435&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12435
* More futex support per https://bugs.swift.org/browse/SR-761?focusedCommentId=12442&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12442

Signed-off-by: Drew Crawford <drew@sealedabstract.com>
---
 libpwq          |  2 +-
 src/semaphore.c | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/libpwq b/libpwq
index 4312f99..e16bcd6 160000
--- a/libpwq
+++ b/libpwq
@@ -1 +1 @@
-Subproject commit 4312f994da24d35fb355ad6701418752ab8fdf3a
+Subproject commit e16bcd6c4b4df3fd85939a981baf94b30968a1ba
diff --git a/src/semaphore.c b/src/semaphore.c
index db40161..9f6055d 100644
--- a/src/semaphore.c
+++ b/src/semaphore.c
@@ -301,6 +301,13 @@ dispatch_semaphore_signal(dispatch_semaphore_t dsema)
 	return _dispatch_semaphore_signal_slow(dsema);
 }
 
+#if (USE_POSIX_SEM || USE_FUTEX_SEM) && HAVE_PTHREAD_WORKQUEUES
+extern void pthread_workqueue_signal_np(void);
+#define _dispatch_threadmgr_inform_wait() pthread_workqueue_signal_np()
+#else
+#define _dispatch_threadmgr_inform_wait()  do { } while (0)
+#endif
+
 DISPATCH_NOINLINE
 static long
 _dispatch_semaphore_wait_slow(dispatch_semaphore_t dsema,
@@ -371,6 +378,7 @@ again:
 			uint64_t nsec = _dispatch_time_to_nanoseconds(timeout);
 			_timeout.tv_sec = (typeof(_timeout.tv_sec))(nsec / NSEC_PER_SEC);
 			_timeout.tv_nsec = (typeof(_timeout.tv_nsec))(nsec % NSEC_PER_SEC);
+			_dispatch_threadmgr_inform_wait();
 			ret = slowpath(sem_timedwait(&dsema->dsema_sem, &_timeout));
 		} while (ret == -1 && errno == EINTR);
 
@@ -383,6 +391,7 @@ again:
 			uint64_t nsec = _dispatch_time_to_nanoseconds(timeout);
 			_timeout.tv_sec = (typeof(_timeout.tv_sec))(nsec / NSEC_PER_SEC);
 			_timeout.tv_nsec = (typeof(_timeout.tv_nsec))(nsec % NSEC_PER_SEC);
+			_dispatch_threadmgr_inform_wait();
 			ret = slowpath(_dispatch_futex_wait(&dsema->dsema_futex, &_timeout));
 		} while (ret == false && errno == EINTR);
 
@@ -425,11 +434,13 @@ again:
 		DISPATCH_SEMAPHORE_VERIFY_KR(kr);
 #elif USE_POSIX_SEM
 		do {
+			_dispatch_threadmgr_inform_wait();
 			ret = sem_wait(&dsema->dsema_sem);
 		} while (ret != 0);
 		DISPATCH_SEMAPHORE_VERIFY_RET(ret);
 #elif USE_FUTEX_SEM
 		do {
+			_dispatch_threadmgr_inform_wait();
 			ret = _dispatch_futex_wait(&dsema->dsema_futex, NULL);
 		} while (ret == false && errno == EINTR);
 		DISPATCH_SEMAPHORE_VERIFY_RET(ret);
@@ -636,6 +647,7 @@ again:
 			uint64_t nsec = _dispatch_time_to_nanoseconds(timeout);
 			_timeout.tv_sec = (typeof(_timeout.tv_sec))(nsec / NSEC_PER_SEC);
 			_timeout.tv_nsec = (typeof(_timeout.tv_nsec))(nsec % NSEC_PER_SEC);
+			_dispatch_threadmgr_inform_wait();
 			ret = slowpath(sem_timedwait(&dsema->dsema_sem, &_timeout));
 		} while (ret == -1 && errno == EINTR);
 
@@ -649,6 +661,7 @@ again:
 			uint64_t nsec = _dispatch_timeout(timeout);
 			_timeout.tv_sec = nsec / NSEC_PER_SEC;
 			_timeout.tv_nsec = nsec % NSEC_PER_SEC;
+			_dispatch_threadmgr_inform_wait();
 			ret = slowpath(_dispatch_futex_wait(&dsema->dsema_futex, &_timeout));
 		} while (ret == false && errno == EINTR);
 
@@ -691,11 +704,13 @@ again:
 		DISPATCH_GROUP_VERIFY_KR(kr);
 #elif USE_POSIX_SEM
 		do {
+			_dispatch_threadmgr_inform_wait();
 			ret = sem_wait(&dsema->dsema_sem);
 		} while (ret == -1 && errno == EINTR);
 		DISPATCH_SEMAPHORE_VERIFY_RET(ret);
 #elif USE_FUTEX_SEM
 		do {
+			_dispatch_threadmgr_inform_wait();
 			ret = _dispatch_futex_wait(&dsema->dsema_futex, NULL);
 		} while (ret == false && errno == EINTR);
 		DISPATCH_SEMAPHORE_VERIFY_RET(ret);
-- 
2.5.4 (Apple Git-61)