X-Git-Url: https://git.saurik.com/apple/libpthread.git/blobdiff_plain/964d3577b041867f776d8eb940bf4a1108ffb97c..a03d92013c2a24ebc4e02e5d1f575787f8467f6b:/tests/wq_kevent.c?ds=sidebyside diff --git a/tests/wq_kevent.c b/tests/wq_kevent.c index 808cc25..2b02039 100644 --- a/tests/wq_kevent.c +++ b/tests/wq_kevent.c @@ -26,7 +26,7 @@ static int do_wait(int threads){ return 1; } } - fprintf(stderr, "\tsuccessfully signaled by %d threads.\n", threads); + fprintf(stderr, "\tsuccessfully signaled by %d threads.\n\n", threads); return 0; } @@ -35,13 +35,13 @@ static void workqueue_func(pthread_priority_t priority){ dispatch_semaphore_signal(sema); } -void (^cb)(void) = NULL; +void (^cb)(pthread_priority_t p) = NULL; static void workqueue_func_kevent(void **buf, int *count){ pthread_priority_t p = (pthread_priority_t)pthread_getspecific(4); - fprintf(stderr, "\tthread with qos %s spawned.\n", describe_pri(p)); + fprintf(stderr, "\tthread with qos %s spawned. (buf: %p, count: %d)\n", describe_pri(p), buf ? *buf : NULL, count ? *count : 0); if (cb){ - cb(); + cb(p); } dispatch_semaphore_signal(sema); @@ -88,12 +88,19 @@ int main(int argc, char *argv[]){ if ((ret = do_req()) < 0) return ret; if ((ret = do_wait(1)) < 0) return ret; - // whole bunch of constrained threads + // whole bunch of constrained threads (must be last) + + dispatch_semaphore_t mgr_sema = dispatch_semaphore_create(0); + assert(mgr_sema != NULL); requests[0].priority = _pthread_qos_class_encode(QOS_CLASS_USER_INTERACTIVE, 0, 0); requests[0].count = 1; - cb = ^{ + cb = ^(pthread_priority_t p){ + if (p & _PTHREAD_PRIORITY_EVENT_MANAGER_FLAG){ + dispatch_semaphore_signal(mgr_sema); + } + // burn some CPU for (int i = 0; i < 1000000; i++){ char c[32]; @@ -102,7 +109,12 @@ int main(int argc, char *argv[]){ }; for (int i = 0; i < 8; i++) if ((ret = do_req()) < 0) return ret; - if ((ret = do_wait(8)) < 0) return ret; + ret = dispatch_semaphore_wait(mgr_sema, timeout); + if (ret) { + fprintf(stderr, "timeout waiting for a manager thread"); + return 1; + } + fprintf(stderr, "\tsucessfully signaled by a manager thread.\n"); return 0; }