{"action":"created","comment":{"url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/pulls/comments/54024353","id":54024353,"diff_hunk":"@@ -804,3 +889,110 @@ _dispatch_thread_semaphore_wait(_dispatch_thread_semaphore_t sema)\n #error \"No supported semaphore type\"\n #endif\n }\n+\n+#if USE_FUTEX_SEM\n+#define DISPATCH_FUTEX_NUM_SPINS 100\n+#define DISPATCH_FUTEX_VALUE_MAX INT_MAX\n+#define DISPATCH_FUTEX_NWAITERS_SHIFT 32\n+#define DISPATCH_FUTEX_VALUE_MASK ((1ull << DISPATCH_FUTEX_NWAITERS_SHIFT) - 1)\n+\n+static bool _dispatch_futex_wait_slow(dispatch_futex_t dfx,\n+\t\tconst struct timespec* timeout);\n+\n+DISPATCH_INLINE\n+static int\n+_dispatch_futex_syscall(int *futex_addr, \n+\t\tint op, int val, const struct timespec *timeout)\n+{\n+\treturn (int)syscall(SYS_futex, futex_addr, op | FUTEX_PRIVATE_FLAG, val, \n+\t\t\t\t\t\ttimeout, NULL, 0);\n+}\n+\n+/* all memory orders below were added with strict seq_cst semantics\n+ * assumed to be the strongest\n+ */\n+\n+// Atomic-decrement-if-positive on the semaphore value, with acquire MO if\n+// successful.\n+DISPATCH_INLINE\n+bool\n+_dispatch_futex_trywait(dispatch_futex_t dfx)\n+{\n+\tuint64_t orig;\n+\twhile ((orig = dfx->dfx_data) & DISPATCH_FUTEX_VALUE_MASK) {\n+\t\tif (dispatch_atomic_cmpxchg2o(dfx, dfx_data, orig, orig - 1, acquire)) {\n+\t\t\treturn true;\n+\t\t}\n+\t}\n+\treturn false;\n+}\n+\n+// Increments semaphore value and reads wait count in a single atomic\n+// operation, with release MO. If wait count is nonzero, issues a FUTEX_WAKE.\n+DISPATCH_INLINE\n+bool\n+_dispatch_futex_signal(dispatch_futex_t dfx)\n+{\n+\tuint64_t orig;\n+\tdo {\n+\t\torig = dfx->dfx_data;\n+\t\tif (slowpath((orig & DISPATCH_FUTEX_VALUE_MASK) ==\n+\t\t\t\t\t DISPATCH_FUTEX_VALUE_MAX)) {\n+\t\t\tDISPATCH_CRASH(\"semaphore overflow\");\n+\t\t}\n+\t} while (!dispatch_atomic_cmpxchgvw2o(dfx, dfx_data, orig, orig + 1, &orig, release));\n+\tif (slowpath(orig >> DISPATCH_FUTEX_NWAITERS_SHIFT)) {\n+\t\tint ret = _dispatch_futex_syscall(&dfx->dfx_futex, FUTEX_WAKE, 1, NULL);","path":"src/semaphore.c","position":305,"original_position":305,"commit_id":"f2b865b6d96fe1e1fce76f6ba352b5c4372586d5","original_commit_id":"f2b865b6d96fe1e1fce76f6ba352b5c4372586d5","user":{"login":"MadCoder","id":44708,"avatar_url":"https://avatars.githubusercontent.com/u/44708?v=3","gravatar_id":"","url":"https://api.github.com/users/MadCoder","html_url":"https://github.com/MadCoder","followers_url":"https://api.github.com/users/MadCoder/followers","following_url":"https://api.github.com/users/MadCoder/following{/other_user}","gists_url":"https://api.github.com/users/MadCoder/gists{/gist_id}","starred_url":"https://api.github.com/users/MadCoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MadCoder/subscriptions","organizations_url":"https://api.github.com/users/MadCoder/orgs","repos_url":"https://api.github.com/users/MadCoder/repos","events_url":"https://api.github.com/users/MadCoder/events{/privacy}","received_events_url":"https://api.github.com/users/MadCoder/received_events","type":"User","site_admin":false},"body":"can't you get EINTR if a debugger is attached? in which case you have to loop","created_at":"2016-02-24T23:14:36Z","updated_at":"2016-02-24T23:14:36Z","html_url":"https://github.com/apple/swift-corelibs-libdispatch/pull/50#discussion_r54024353","pull_request_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/pulls/50","_links":{"self":{"href":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/pulls/comments/54024353"},"html":{"href":"https://github.com/apple/swift-corelibs-libdispatch/pull/50#discussion_r54024353"},"pull_request":{"href":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/pulls/50"}}},"pull_request":{"url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/pulls/50","id":59383823,"html_url":"https://github.com/apple/swift-corelibs-libdispatch/pull/50","diff_url":"https://github.com/apple/swift-corelibs-libdispatch/pull/50.diff","patch_url":"https://github.com/apple/swift-corelibs-libdispatch/pull/50.patch","issue_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/issues/50","number":50,"state":"open","locked":false,"title":"add futex semaphore support derived from hutchinson port","user":{"login":"frankeh","id":15785601,"avatar_url":"https://avatars.githubusercontent.com/u/15785601?v=3","gravatar_id":"","url":"https://api.github.com/users/frankeh","html_url":"https://github.com/frankeh","followers_url":"https://api.github.com/users/frankeh/followers","following_url":"https://api.github.com/users/frankeh/following{/other_user}","gists_url":"https://api.github.com/users/frankeh/gists{/gist_id}","starred_url":"https://api.github.com/users/frankeh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frankeh/subscriptions","organizations_url":"https://api.github.com/users/frankeh/orgs","repos_url":"https://api.github.com/users/frankeh/repos","events_url":"https://api.github.com/users/frankeh/events{/privacy}","received_events_url":"https://api.github.com/users/frankeh/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-15T16:12:54Z","updated_at":"2016-02-24T23:14:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fb6fc59ed2547cb5b23e073a82d89044fd58b228","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/pulls/50/commits","review_comments_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/pulls/50/comments","review_comment_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/issues/50/comments","statuses_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/statuses/f2b865b6d96fe1e1fce76f6ba352b5c4372586d5","head":{"label":"frankeh:futexes","ref":"futexes","sha":"f2b865b6d96fe1e1fce76f6ba352b5c4372586d5","user":{"login":"frankeh","id":15785601,"avatar_url":"https://avatars.githubusercontent.com/u/15785601?v=3","gravatar_id":"","url":"https://api.github.com/users/frankeh","html_url":"https://github.com/frankeh","followers_url":"https://api.github.com/users/frankeh/followers","following_url":"https://api.github.com/users/frankeh/following{/other_user}","gists_url":"https://api.github.com/users/frankeh/gists{/gist_id}","starred_url":"https://api.github.com/users/frankeh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frankeh/subscriptions","organizations_url":"https://api.github.com/users/frankeh/orgs","repos_url":"https://api.github.com/users/frankeh/repos","events_url":"https://api.github.com/users/frankeh/events{/privacy}","received_events_url":"https://api.github.com/users/frankeh/received_events","type":"User","site_admin":false},"repo":{"id":48249613,"name":"swift-corelibs-libdispatch","full_name":"frankeh/swift-corelibs-libdispatch","owner":{"login":"frankeh","id":15785601,"avatar_url":"https://avatars.githubusercontent.com/u/15785601?v=3","gravatar_id":"","url":"https://api.github.com/users/frankeh","html_url":"https://github.com/frankeh","followers_url":"https://api.github.com/users/frankeh/followers","following_url":"https://api.github.com/users/frankeh/following{/other_user}","gists_url":"https://api.github.com/users/frankeh/gists{/gist_id}","starred_url":"https://api.github.com/users/frankeh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frankeh/subscriptions","organizations_url":"https://api.github.com/users/frankeh/orgs","repos_url":"https://api.github.com/users/frankeh/repos","events_url":"https://api.github.com/users/frankeh/events{/privacy}","received_events_url":"https://api.github.com/users/frankeh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/frankeh/swift-corelibs-libdispatch","description":"The libdispatch Project, (a.k.a. Grand Central Dispatch), for concurrency on multicore hardware","fork":true,"url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch","forks_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/forks","keys_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/teams","hooks_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/hooks","issue_events_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/issues/events{/number}","events_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/events","assignees_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/assignees{/user}","branches_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/branches{/branch}","tags_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/tags","blobs_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/git/refs{/sha}","trees_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/statuses/{sha}","languages_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/languages","stargazers_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/stargazers","contributors_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/contributors","subscribers_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/subscribers","subscription_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/subscription","commits_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/commits{/sha}","git_commits_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/git/commits{/sha}","comments_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/comments{/number}","issue_comment_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/issues/comments{/number}","contents_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/contents/{+path}","compare_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/merges","archive_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/downloads","issues_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/issues{/number}","pulls_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/pulls{/number}","milestones_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/milestones{/number}","notifications_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/labels{/name}","releases_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/releases{/id}","deployments_url":"https://api.github.com/repos/frankeh/swift-corelibs-libdispatch/deployments","created_at":"2015-12-18T18:15:52Z","updated_at":"2016-01-26T15:25:37Z","pushed_at":"2016-02-24T22:59:03Z","git_url":"git://github.com/frankeh/swift-corelibs-libdispatch.git","ssh_url":"git@github.com:frankeh/swift-corelibs-libdispatch.git","clone_url":"https://github.com/frankeh/swift-corelibs-libdispatch.git","svn_url":"https://github.com/frankeh/swift-corelibs-libdispatch","homepage":"swift.org","size":560,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apple:master","ref":"master","sha":"c04488a632e793150c45a5fd3cc07848aa187c24","user":{"login":"apple","id":10639145,"avatar_url":"https://avatars.githubusercontent.com/u/10639145?v=3","gravatar_id":"","url":"https://api.github.com/users/apple","html_url":"https://github.com/apple","followers_url":"https://api.github.com/users/apple/followers","following_url":"https://api.github.com/users/apple/following{/other_user}","gists_url":"https://api.github.com/users/apple/gists{/gist_id}","starred_url":"https://api.github.com/users/apple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apple/subscriptions","organizations_url":"https://api.github.com/users/apple/orgs","repos_url":"https://api.github.com/users/apple/repos","events_url":"https://api.github.com/users/apple/events{/privacy}","received_events_url":"https://api.github.com/users/apple/received_events","type":"Organization","site_admin":false},"repo":{"id":45863965,"name":"swift-corelibs-libdispatch","full_name":"apple/swift-corelibs-libdispatch","owner":{"login":"apple","id":10639145,"avatar_url":"https://avatars.githubusercontent.com/u/10639145?v=3","gravatar_id":"","url":"https://api.github.com/users/apple","html_url":"https://github.com/apple","followers_url":"https://api.github.com/users/apple/followers","following_url":"https://api.github.com/users/apple/following{/other_user}","gists_url":"https://api.github.com/users/apple/gists{/gist_id}","starred_url":"https://api.github.com/users/apple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apple/subscriptions","organizations_url":"https://api.github.com/users/apple/orgs","repos_url":"https://api.github.com/users/apple/repos","events_url":"https://api.github.com/users/apple/events{/privacy}","received_events_url":"https://api.github.com/users/apple/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apple/swift-corelibs-libdispatch","description":"The libdispatch Project, (a.k.a. Grand Central Dispatch), for concurrency on multicore hardware","fork":false,"url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch","forks_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/forks","keys_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/teams","hooks_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/hooks","issue_events_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/issues/events{/number}","events_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/events","assignees_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/assignees{/user}","branches_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/branches{/branch}","tags_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/tags","blobs_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/git/refs{/sha}","trees_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/statuses/{sha}","languages_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/languages","stargazers_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/stargazers","contributors_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/contributors","subscribers_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/subscribers","subscription_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/subscription","commits_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/commits{/sha}","git_commits_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/git/commits{/sha}","comments_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/comments{/number}","issue_comment_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/issues/comments{/number}","contents_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/contents/{+path}","compare_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/merges","archive_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/downloads","issues_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/issues{/number}","pulls_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/pulls{/number}","milestones_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/milestones{/number}","notifications_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/labels{/name}","releases_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/releases{/id}","deployments_url":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/deployments","created_at":"2015-11-09T20:13:55Z","updated_at":"2016-02-24T06:41:36Z","pushed_at":"2016-02-24T23:05:02Z","git_url":"git://github.com/apple/swift-corelibs-libdispatch.git","ssh_url":"git@github.com:apple/swift-corelibs-libdispatch.git","clone_url":"https://github.com/apple/swift-corelibs-libdispatch.git","svn_url":"https://github.com/apple/swift-corelibs-libdispatch","homepage":"swift.org","size":718,"stargazers_count":614,"watchers_count":614,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":83,"mirror_url":null,"open_issues_count":5,"forks":83,"open_issues":5,"watchers":614,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/pulls/50"},"html":{"href":"https://github.com/apple/swift-corelibs-libdispatch/pull/50"},"issue":{"href":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/issues/50"},"comments":{"href":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/issues/50/comments"},"review_comments":{"href":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/pulls/50/comments"},"review_comment":{"href":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/pulls/50/commits"},"statuses":{"href":"https://api.github.com/repos/apple/swift-corelibs-libdispatch/statuses/f2b865b6d96fe1e1fce76f6ba352b5c4372586d5"}}}}