{"action":"created","comment":{"url":"https://api.github.com/repos/Amanieu/asyncplusplus/pulls/comments/53874171","id":53874171,"diff_hunk":"@@ -64,13 +69,69 @@ static void generic_wait_handler(task_wait_handle wait_task)\n \tthread_event.wait();\n }\n \n+#if defined(EMULATE_PTHREAD_THREAD_LOCAL)\n // Wait handler function, per-thread, defaults to generic version\n-static THREAD_LOCAL wait_handler thread_wait_handler = generic_wait_handler;\n+static pthread_key_t thread_wait_handler_key;\n+\n+static void create_thread_wait_handler()\n+{\n+    if(pthread_getspecific(thread_wait_handler_key) == nullptr) {\n+    \tpthread_setspecific(thread_wait_handler_key, (void*)generic_wait_handler);\n+    }\n+}\n+\n+struct pthread_emulation_thread_wait_handler_key_initializer {\n+    pthread_emulation_thread_wait_handler_key_initializer()\n+    {\n+        pthread_key_create(&thread_wait_handler_key, nullptr);\n+    }\n+        \n+    ~pthread_emulation_thread_wait_handler_key_initializer()\n+    {\n+        pthread_key_delete(thread_wait_handler_key);\n+    }\n+};\n+    \n+static pthread_emulation_thread_wait_handler_key_initializer thread_wait_handler_key_initalizer;\n+\n+#else\n+static THREAD_LOCAL wait_handler thread_wait_handler;\n+static void create_thread_wait_handler() {\n+\tthread_wait_handler = generic_wait_handler;\n+}\n+#endif\n+\n+static void set_thread_wait_handler(wait_handler handler)\n+{\n+#if defined(EMULATE_PTHREAD_THREAD_LOCAL)\n+    // we need to call this here, because the pthread initializer is lazy,\n+    // this means the it could be null and we need to set it before trying to\n+    // get or set it\n+    create_thread_wait_handler();","path":"src/scheduler.cpp","position":55,"original_position":55,"commit_id":"5059023a7267895fba7386cbb9ed034541ea0892","original_commit_id":"5059023a7267895fba7386cbb9ed034541ea0892","user":{"login":"Amanieu","id":278509,"avatar_url":"https://avatars.githubusercontent.com/u/278509?v=3","gravatar_id":"","url":"https://api.github.com/users/Amanieu","html_url":"https://github.com/Amanieu","followers_url":"https://api.github.com/users/Amanieu/followers","following_url":"https://api.github.com/users/Amanieu/following{/other_user}","gists_url":"https://api.github.com/users/Amanieu/gists{/gist_id}","starred_url":"https://api.github.com/users/Amanieu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Amanieu/subscriptions","organizations_url":"https://api.github.com/users/Amanieu/orgs","repos_url":"https://api.github.com/users/Amanieu/repos","events_url":"https://api.github.com/users/Amanieu/events{/privacy}","received_events_url":"https://api.github.com/users/Amanieu/received_events","type":"User","site_admin":false},"body":"Actually you can just remove the call to `create_thread_wait_handler` here since you're overwriting it anyways.","created_at":"2016-02-24T00:14:17Z","updated_at":"2016-02-24T00:14:17Z","html_url":"https://github.com/Amanieu/asyncplusplus/pull/15#discussion_r53874171","pull_request_url":"https://api.github.com/repos/Amanieu/asyncplusplus/pulls/15","_links":{"self":{"href":"https://api.github.com/repos/Amanieu/asyncplusplus/pulls/comments/53874171"},"html":{"href":"https://github.com/Amanieu/asyncplusplus/pull/15#discussion_r53874171"},"pull_request":{"href":"https://api.github.com/repos/Amanieu/asyncplusplus/pulls/15"}}},"pull_request":{"url":"https://api.github.com/repos/Amanieu/asyncplusplus/pulls/15","id":60433262,"html_url":"https://github.com/Amanieu/asyncplusplus/pull/15","diff_url":"https://github.com/Amanieu/asyncplusplus/pull/15.diff","patch_url":"https://github.com/Amanieu/asyncplusplus/pull/15.patch","issue_url":"https://api.github.com/repos/Amanieu/asyncplusplus/issues/15","number":15,"state":"open","locked":false,"title":"Implement a thread_local emulation for iOS devices","user":{"login":"Rogiel","id":755798,"avatar_url":"https://avatars.githubusercontent.com/u/755798?v=3","gravatar_id":"","url":"https://api.github.com/users/Rogiel","html_url":"https://github.com/Rogiel","followers_url":"https://api.github.com/users/Rogiel/followers","following_url":"https://api.github.com/users/Rogiel/following{/other_user}","gists_url":"https://api.github.com/users/Rogiel/gists{/gist_id}","starred_url":"https://api.github.com/users/Rogiel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rogiel/subscriptions","organizations_url":"https://api.github.com/users/Rogiel/orgs","repos_url":"https://api.github.com/users/Rogiel/repos","events_url":"https://api.github.com/users/Rogiel/events{/privacy}","received_events_url":"https://api.github.com/users/Rogiel/received_events","type":"User","site_admin":false},"body":"Apparently Apple does not implement any compiler based thread local storage on iOS. But pthread is capable of storing thread local data.\r\n\r\nThis pull requests adds a macro called **EMULATE_PTHREAD_THREAD_LOCAL** that enables the emulation.\r\n\r\nI have also changed the way the thread-global variables are accessed because pthread cannot map transparently to a variable (it could be done with templates... but i tried to keep it simple): a function is used to setup, get and set a thread local instead of a variable directly.","created_at":"2016-02-24T00:01:57Z","updated_at":"2016-02-24T00:14:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"61bfbfaac64f2e8351204ca59a69da68b13a87c6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Amanieu/asyncplusplus/pulls/15/commits","review_comments_url":"https://api.github.com/repos/Amanieu/asyncplusplus/pulls/15/comments","review_comment_url":"https://api.github.com/repos/Amanieu/asyncplusplus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Amanieu/asyncplusplus/issues/15/comments","statuses_url":"https://api.github.com/repos/Amanieu/asyncplusplus/statuses/5059023a7267895fba7386cbb9ed034541ea0892","head":{"label":"Rogiel:ios-thread-local-emulation","ref":"ios-thread-local-emulation","sha":"5059023a7267895fba7386cbb9ed034541ea0892","user":{"login":"Rogiel","id":755798,"avatar_url":"https://avatars.githubusercontent.com/u/755798?v=3","gravatar_id":"","url":"https://api.github.com/users/Rogiel","html_url":"https://github.com/Rogiel","followers_url":"https://api.github.com/users/Rogiel/followers","following_url":"https://api.github.com/users/Rogiel/following{/other_user}","gists_url":"https://api.github.com/users/Rogiel/gists{/gist_id}","starred_url":"https://api.github.com/users/Rogiel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rogiel/subscriptions","organizations_url":"https://api.github.com/users/Rogiel/orgs","repos_url":"https://api.github.com/users/Rogiel/repos","events_url":"https://api.github.com/users/Rogiel/events{/privacy}","received_events_url":"https://api.github.com/users/Rogiel/received_events","type":"User","site_admin":false},"repo":{"id":52178558,"name":"asyncplusplus","full_name":"Rogiel/asyncplusplus","owner":{"login":"Rogiel","id":755798,"avatar_url":"https://avatars.githubusercontent.com/u/755798?v=3","gravatar_id":"","url":"https://api.github.com/users/Rogiel","html_url":"https://github.com/Rogiel","followers_url":"https://api.github.com/users/Rogiel/followers","following_url":"https://api.github.com/users/Rogiel/following{/other_user}","gists_url":"https://api.github.com/users/Rogiel/gists{/gist_id}","starred_url":"https://api.github.com/users/Rogiel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rogiel/subscriptions","organizations_url":"https://api.github.com/users/Rogiel/orgs","repos_url":"https://api.github.com/users/Rogiel/repos","events_url":"https://api.github.com/users/Rogiel/events{/privacy}","received_events_url":"https://api.github.com/users/Rogiel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Rogiel/asyncplusplus","description":"Async++ concurrency framework for C++11","fork":true,"url":"https://api.github.com/repos/Rogiel/asyncplusplus","forks_url":"https://api.github.com/repos/Rogiel/asyncplusplus/forks","keys_url":"https://api.github.com/repos/Rogiel/asyncplusplus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Rogiel/asyncplusplus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Rogiel/asyncplusplus/teams","hooks_url":"https://api.github.com/repos/Rogiel/asyncplusplus/hooks","issue_events_url":"https://api.github.com/repos/Rogiel/asyncplusplus/issues/events{/number}","events_url":"https://api.github.com/repos/Rogiel/asyncplusplus/events","assignees_url":"https://api.github.com/repos/Rogiel/asyncplusplus/assignees{/user}","branches_url":"https://api.github.com/repos/Rogiel/asyncplusplus/branches{/branch}","tags_url":"https://api.github.com/repos/Rogiel/asyncplusplus/tags","blobs_url":"https://api.github.com/repos/Rogiel/asyncplusplus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Rogiel/asyncplusplus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Rogiel/asyncplusplus/git/refs{/sha}","trees_url":"https://api.github.com/repos/Rogiel/asyncplusplus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Rogiel/asyncplusplus/statuses/{sha}","languages_url":"https://api.github.com/repos/Rogiel/asyncplusplus/languages","stargazers_url":"https://api.github.com/repos/Rogiel/asyncplusplus/stargazers","contributors_url":"https://api.github.com/repos/Rogiel/asyncplusplus/contributors","subscribers_url":"https://api.github.com/repos/Rogiel/asyncplusplus/subscribers","subscription_url":"https://api.github.com/repos/Rogiel/asyncplusplus/subscription","commits_url":"https://api.github.com/repos/Rogiel/asyncplusplus/commits{/sha}","git_commits_url":"https://api.github.com/repos/Rogiel/asyncplusplus/git/commits{/sha}","comments_url":"https://api.github.com/repos/Rogiel/asyncplusplus/comments{/number}","issue_comment_url":"https://api.github.com/repos/Rogiel/asyncplusplus/issues/comments{/number}","contents_url":"https://api.github.com/repos/Rogiel/asyncplusplus/contents/{+path}","compare_url":"https://api.github.com/repos/Rogiel/asyncplusplus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Rogiel/asyncplusplus/merges","archive_url":"https://api.github.com/repos/Rogiel/asyncplusplus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Rogiel/asyncplusplus/downloads","issues_url":"https://api.github.com/repos/Rogiel/asyncplusplus/issues{/number}","pulls_url":"https://api.github.com/repos/Rogiel/asyncplusplus/pulls{/number}","milestones_url":"https://api.github.com/repos/Rogiel/asyncplusplus/milestones{/number}","notifications_url":"https://api.github.com/repos/Rogiel/asyncplusplus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Rogiel/asyncplusplus/labels{/name}","releases_url":"https://api.github.com/repos/Rogiel/asyncplusplus/releases{/id}","deployments_url":"https://api.github.com/repos/Rogiel/asyncplusplus/deployments","created_at":"2016-02-20T22:23:47Z","updated_at":"2016-02-20T22:23:47Z","pushed_at":"2016-02-23T23:55:02Z","git_url":"git://github.com/Rogiel/asyncplusplus.git","ssh_url":"git@github.com:Rogiel/asyncplusplus.git","clone_url":"https://github.com/Rogiel/asyncplusplus.git","svn_url":"https://github.com/Rogiel/asyncplusplus","homepage":null,"size":278,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"Amanieu:master","ref":"master","sha":"d2c399ebbc56c88a83ffb7971c5ec37974b2e5de","user":{"login":"Amanieu","id":278509,"avatar_url":"https://avatars.githubusercontent.com/u/278509?v=3","gravatar_id":"","url":"https://api.github.com/users/Amanieu","html_url":"https://github.com/Amanieu","followers_url":"https://api.github.com/users/Amanieu/followers","following_url":"https://api.github.com/users/Amanieu/following{/other_user}","gists_url":"https://api.github.com/users/Amanieu/gists{/gist_id}","starred_url":"https://api.github.com/users/Amanieu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Amanieu/subscriptions","organizations_url":"https://api.github.com/users/Amanieu/orgs","repos_url":"https://api.github.com/users/Amanieu/repos","events_url":"https://api.github.com/users/Amanieu/events{/privacy}","received_events_url":"https://api.github.com/users/Amanieu/received_events","type":"User","site_admin":false},"repo":{"id":8636694,"name":"asyncplusplus","full_name":"Amanieu/asyncplusplus","owner":{"login":"Amanieu","id":278509,"avatar_url":"https://avatars.githubusercontent.com/u/278509?v=3","gravatar_id":"","url":"https://api.github.com/users/Amanieu","html_url":"https://github.com/Amanieu","followers_url":"https://api.github.com/users/Amanieu/followers","following_url":"https://api.github.com/users/Amanieu/following{/other_user}","gists_url":"https://api.github.com/users/Amanieu/gists{/gist_id}","starred_url":"https://api.github.com/users/Amanieu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Amanieu/subscriptions","organizations_url":"https://api.github.com/users/Amanieu/orgs","repos_url":"https://api.github.com/users/Amanieu/repos","events_url":"https://api.github.com/users/Amanieu/events{/privacy}","received_events_url":"https://api.github.com/users/Amanieu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Amanieu/asyncplusplus","description":"Async++ concurrency framework for C++11","fork":false,"url":"https://api.github.com/repos/Amanieu/asyncplusplus","forks_url":"https://api.github.com/repos/Amanieu/asyncplusplus/forks","keys_url":"https://api.github.com/repos/Amanieu/asyncplusplus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Amanieu/asyncplusplus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Amanieu/asyncplusplus/teams","hooks_url":"https://api.github.com/repos/Amanieu/asyncplusplus/hooks","issue_events_url":"https://api.github.com/repos/Amanieu/asyncplusplus/issues/events{/number}","events_url":"https://api.github.com/repos/Amanieu/asyncplusplus/events","assignees_url":"https://api.github.com/repos/Amanieu/asyncplusplus/assignees{/user}","branches_url":"https://api.github.com/repos/Amanieu/asyncplusplus/branches{/branch}","tags_url":"https://api.github.com/repos/Amanieu/asyncplusplus/tags","blobs_url":"https://api.github.com/repos/Amanieu/asyncplusplus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Amanieu/asyncplusplus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Amanieu/asyncplusplus/git/refs{/sha}","trees_url":"https://api.github.com/repos/Amanieu/asyncplusplus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Amanieu/asyncplusplus/statuses/{sha}","languages_url":"https://api.github.com/repos/Amanieu/asyncplusplus/languages","stargazers_url":"https://api.github.com/repos/Amanieu/asyncplusplus/stargazers","contributors_url":"https://api.github.com/repos/Amanieu/asyncplusplus/contributors","subscribers_url":"https://api.github.com/repos/Amanieu/asyncplusplus/subscribers","subscription_url":"https://api.github.com/repos/Amanieu/asyncplusplus/subscription","commits_url":"https://api.github.com/repos/Amanieu/asyncplusplus/commits{/sha}","git_commits_url":"https://api.github.com/repos/Amanieu/asyncplusplus/git/commits{/sha}","comments_url":"https://api.github.com/repos/Amanieu/asyncplusplus/comments{/number}","issue_comment_url":"https://api.github.com/repos/Amanieu/asyncplusplus/issues/comments{/number}","contents_url":"https://api.github.com/repos/Amanieu/asyncplusplus/contents/{+path}","compare_url":"https://api.github.com/repos/Amanieu/asyncplusplus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Amanieu/asyncplusplus/merges","archive_url":"https://api.github.com/repos/Amanieu/asyncplusplus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Amanieu/asyncplusplus/downloads","issues_url":"https://api.github.com/repos/Amanieu/asyncplusplus/issues{/number}","pulls_url":"https://api.github.com/repos/Amanieu/asyncplusplus/pulls{/number}","milestones_url":"https://api.github.com/repos/Amanieu/asyncplusplus/milestones{/number}","notifications_url":"https://api.github.com/repos/Amanieu/asyncplusplus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Amanieu/asyncplusplus/labels{/name}","releases_url":"https://api.github.com/repos/Amanieu/asyncplusplus/releases{/id}","deployments_url":"https://api.github.com/repos/Amanieu/asyncplusplus/deployments","created_at":"2013-03-07T21:15:44Z","updated_at":"2016-02-19T12:37:55Z","pushed_at":"2016-02-24T00:01:58Z","git_url":"git://github.com/Amanieu/asyncplusplus.git","ssh_url":"git@github.com:Amanieu/asyncplusplus.git","clone_url":"https://github.com/Amanieu/asyncplusplus.git","svn_url":"https://github.com/Amanieu/asyncplusplus","homepage":null,"size":338,"stargazers_count":256,"watchers_count":256,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":42,"mirror_url":null,"open_issues_count":2,"forks":42,"open_issues":2,"watchers":256,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Amanieu/asyncplusplus/pulls/15"},"html":{"href":"https://github.com/Amanieu/asyncplusplus/pull/15"},"issue":{"href":"https://api.github.com/repos/Amanieu/asyncplusplus/issues/15"},"comments":{"href":"https://api.github.com/repos/Amanieu/asyncplusplus/issues/15/comments"},"review_comments":{"href":"https://api.github.com/repos/Amanieu/asyncplusplus/pulls/15/comments"},"review_comment":{"href":"https://api.github.com/repos/Amanieu/asyncplusplus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Amanieu/asyncplusplus/pulls/15/commits"},"statuses":{"href":"https://api.github.com/repos/Amanieu/asyncplusplus/statuses/5059023a7267895fba7386cbb9ed034541ea0892"}}}}