{"action":"created","comment":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls/comments/46211439","id":46211439,"diff_hunk":"@@ -1,30 +1,95 @@\n #include <mbgl/util/thread_context.hpp>\n \n+#include <mbgl/util/thread_local.hpp>\n+\n+#include <cassert>\n+\n+namespace {\n+\n+using namespace mbgl::util;\n+static tls<ThreadContext>& current = *new tls<ThreadContext>;","path":"src/mbgl/util/thread_context.cpp","position":10,"original_position":10,"commit_id":"c95c4ba79e72c5714fbb57722dfc617006e164b8","original_commit_id":"c95c4ba79e72c5714fbb57722dfc617006e164b8","user":{"login":"tmpsantos","id":996307,"avatar_url":"https://avatars.githubusercontent.com/u/996307?v=3","gravatar_id":"","url":"https://api.github.com/users/tmpsantos","html_url":"https://github.com/tmpsantos","followers_url":"https://api.github.com/users/tmpsantos/followers","following_url":"https://api.github.com/users/tmpsantos/following{/other_user}","gists_url":"https://api.github.com/users/tmpsantos/gists{/gist_id}","starred_url":"https://api.github.com/users/tmpsantos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmpsantos/subscriptions","organizations_url":"https://api.github.com/users/tmpsantos/orgs","repos_url":"https://api.github.com/users/tmpsantos/repos","events_url":"https://api.github.com/users/tmpsantos/events{/privacy}","received_events_url":"https://api.github.com/users/tmpsantos/received_events","type":"User","site_admin":false},"body":"Yes and I did the same with `RunLoop`. I was hitting sometimes a bug that would sometimes the `static tls<RunLoop> current` before a `RunLoop` object on the heap. The object on the heap sets the `::current` to `nullptr` and crashes.\r\n\r\nThat reminded me that a practice we had at the Chromium browser to \"leak\" static variables to prevent this sort of issues: https://code.google.com/p/chromium/codesearch#chromium/src/base/macros.h&l=153\r\n\r\nIt is not exactly a leak because it is still referenced (so valgrind won't complain) and it would only be destructed at exit anyway.","created_at":"2015-11-30T22:10:44Z","updated_at":"2015-11-30T22:10:44Z","html_url":"https://github.com/mapbox/mapbox-gl-native/pull/3139#discussion_r46211439","pull_request_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls/3139","_links":{"self":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls/comments/46211439"},"html":{"href":"https://github.com/mapbox/mapbox-gl-native/pull/3139#discussion_r46211439"},"pull_request":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls/3139"}}},"pull_request":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls/3139","id":51950769,"html_url":"https://github.com/mapbox/mapbox-gl-native/pull/3139","diff_url":"https://github.com/mapbox/mapbox-gl-native/pull/3139.diff","patch_url":"https://github.com/mapbox/mapbox-gl-native/pull/3139.patch","issue_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/3139","number":3139,"state":"open","locked":false,"title":"[core] Abstract libuv","user":{"login":"tmpsantos","id":996307,"avatar_url":"https://avatars.githubusercontent.com/u/996307?v=3","gravatar_id":"","url":"https://api.github.com/users/tmpsantos","html_url":"https://github.com/tmpsantos","followers_url":"https://api.github.com/users/tmpsantos/followers","following_url":"https://api.github.com/users/tmpsantos/following{/other_user}","gists_url":"https://api.github.com/users/tmpsantos/gists{/gist_id}","starred_url":"https://api.github.com/users/tmpsantos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmpsantos/subscriptions","organizations_url":"https://api.github.com/users/tmpsantos/orgs","repos_url":"https://api.github.com/users/tmpsantos/repos","events_url":"https://api.github.com/users/tmpsantos/events{/privacy}","received_events_url":"https://api.github.com/users/tmpsantos/received_events","type":"User","site_admin":false},"body":"This branch reduces the delta between master and the Qt branch that is under development. It enables the platform to reimplement the main loop and get rid of libuv in favor of, say, glib or the Qt main loop.\n\nWrapping is mostly done by reusing existing `util::` like `util::Thread` and also by 3 new classes:\n - `AsyncTask`: Send asynchronous messages to the main loop where the `AsyncTask` object lives, coalescing multiple messages.\n - `Timer`: an ordinary timer.\n - `RunLoop`: not exactly new but was refactored to allow reimplementation. Consists of a platform main loop, using `AsyncTask` internally for waking up.\n\nAll these new classes were implemented in a way to be almost a drop-in replacement for the libuv counterparts, making the changes as mild as possible. `AssetFS` and `AssetZIP` are exceptions, as they were heavily refactored to use `util::Thread` for doing threaded file I/O instead of libuv workers.\n\nFor all the newly introduced classes, unit tests were also added and in some cases, like for the `AssetZIP`, broken unit tests were fixed and more were added.\n\nThis PR also is also a enabler for #2909.","created_at":"2015-11-26T23:45:27Z","updated_at":"2015-11-30T22:10:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"25f38c769bc8143f7e263c76335c290ae70fa9c8","assignee":{"login":"tmpsantos","id":996307,"avatar_url":"https://avatars.githubusercontent.com/u/996307?v=3","gravatar_id":"","url":"https://api.github.com/users/tmpsantos","html_url":"https://github.com/tmpsantos","followers_url":"https://api.github.com/users/tmpsantos/followers","following_url":"https://api.github.com/users/tmpsantos/following{/other_user}","gists_url":"https://api.github.com/users/tmpsantos/gists{/gist_id}","starred_url":"https://api.github.com/users/tmpsantos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmpsantos/subscriptions","organizations_url":"https://api.github.com/users/tmpsantos/orgs","repos_url":"https://api.github.com/users/tmpsantos/repos","events_url":"https://api.github.com/users/tmpsantos/events{/privacy}","received_events_url":"https://api.github.com/users/tmpsantos/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls/3139/commits","review_comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls/3139/comments","review_comment_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/3139/comments","statuses_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/statuses/c95c4ba79e72c5714fbb57722dfc617006e164b8","head":{"label":"mapbox:tmpsantos-libuv_abstracted","ref":"tmpsantos-libuv_abstracted","sha":"c95c4ba79e72c5714fbb57722dfc617006e164b8","user":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"repo":{"id":16286131,"name":"mapbox-gl-native","full_name":"mapbox/mapbox-gl-native","owner":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapbox/mapbox-gl-native","description":"Render Mapbox styles in mobile, desktop, and node applications using C++ and OpenGL","fork":false,"url":"https://api.github.com/repos/mapbox/mapbox-gl-native","forks_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/forks","keys_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/teams","hooks_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/hooks","issue_events_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/events{/number}","events_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/events","assignees_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/assignees{/user}","branches_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/branches{/branch}","tags_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/tags","blobs_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/statuses/{sha}","languages_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/languages","stargazers_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/stargazers","contributors_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/contributors","subscribers_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/subscribers","subscription_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/subscription","commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/contents/{+path}","compare_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/merges","archive_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/downloads","issues_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues{/number}","pulls_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls{/number}","milestones_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/milestones{/number}","notifications_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/labels{/name}","releases_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/releases{/id}","created_at":"2014-01-27T17:14:48Z","updated_at":"2015-11-30T17:05:56Z","pushed_at":"2015-11-30T21:58:26Z","git_url":"git://github.com/mapbox/mapbox-gl-native.git","ssh_url":"git@github.com:mapbox/mapbox-gl-native.git","clone_url":"https://github.com/mapbox/mapbox-gl-native.git","svn_url":"https://github.com/mapbox/mapbox-gl-native","homepage":"https://mapbox.com/mobile","size":103308,"stargazers_count":900,"watchers_count":900,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":205,"mirror_url":null,"open_issues_count":473,"forks":205,"open_issues":473,"watchers":900,"default_branch":"master"}},"base":{"label":"mapbox:master","ref":"master","sha":"77df026adcabb04ddbaa90c3782fc7f11bc46ec7","user":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"repo":{"id":16286131,"name":"mapbox-gl-native","full_name":"mapbox/mapbox-gl-native","owner":{"login":"mapbox","id":600935,"avatar_url":"https://avatars.githubusercontent.com/u/600935?v=3","gravatar_id":"","url":"https://api.github.com/users/mapbox","html_url":"https://github.com/mapbox","followers_url":"https://api.github.com/users/mapbox/followers","following_url":"https://api.github.com/users/mapbox/following{/other_user}","gists_url":"https://api.github.com/users/mapbox/gists{/gist_id}","starred_url":"https://api.github.com/users/mapbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapbox/subscriptions","organizations_url":"https://api.github.com/users/mapbox/orgs","repos_url":"https://api.github.com/users/mapbox/repos","events_url":"https://api.github.com/users/mapbox/events{/privacy}","received_events_url":"https://api.github.com/users/mapbox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapbox/mapbox-gl-native","description":"Render Mapbox styles in mobile, desktop, and node applications using C++ and OpenGL","fork":false,"url":"https://api.github.com/repos/mapbox/mapbox-gl-native","forks_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/forks","keys_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/teams","hooks_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/hooks","issue_events_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/events{/number}","events_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/events","assignees_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/assignees{/user}","branches_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/branches{/branch}","tags_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/tags","blobs_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/statuses/{sha}","languages_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/languages","stargazers_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/stargazers","contributors_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/contributors","subscribers_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/subscribers","subscription_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/subscription","commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/contents/{+path}","compare_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/merges","archive_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/downloads","issues_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues{/number}","pulls_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls{/number}","milestones_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/milestones{/number}","notifications_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/labels{/name}","releases_url":"https://api.github.com/repos/mapbox/mapbox-gl-native/releases{/id}","created_at":"2014-01-27T17:14:48Z","updated_at":"2015-11-30T17:05:56Z","pushed_at":"2015-11-30T21:58:26Z","git_url":"git://github.com/mapbox/mapbox-gl-native.git","ssh_url":"git@github.com:mapbox/mapbox-gl-native.git","clone_url":"https://github.com/mapbox/mapbox-gl-native.git","svn_url":"https://github.com/mapbox/mapbox-gl-native","homepage":"https://mapbox.com/mobile","size":103308,"stargazers_count":900,"watchers_count":900,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":205,"mirror_url":null,"open_issues_count":473,"forks":205,"open_issues":473,"watchers":900,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls/3139"},"html":{"href":"https://github.com/mapbox/mapbox-gl-native/pull/3139"},"issue":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/3139"},"comments":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-native/issues/3139/comments"},"review_comments":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls/3139/comments"},"review_comment":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-native/pulls/3139/commits"},"statuses":{"href":"https://api.github.com/repos/mapbox/mapbox-gl-native/statuses/c95c4ba79e72c5714fbb57722dfc617006e164b8"}}}}