{"action":"created","comment":{"url":"https://api.github.com/repos/mockingbirdnest/Principia/pulls/comments/89657618","pull_request_review_id":10202467,"id":89657618,"diff_hunk":"@@ -0,0 +1,119 @@\n+﻿\n+#include \"base/bundle.hpp\"\n+\n+#include <functional>\n+#include <list>\n+\n+#include \"base/map_util.hpp\"\n+#include \"base/status.hpp\"\n+\n+namespace principia {\n+namespace base {\n+\n+thread_local std::function<bool()> AbortRequested = [] { return false; };\n+\n+Bundle::Bundle(int threads)\n+    : terminate_on_empty_(false),\n+      max_workers_(threads),\n+      master_abort_(&AbortRequested) {\n+  workers_.reserve(max_workers_);\n+}\n+\n+Status Bundle::Join() {\n+  {\n+    std::unique_lock<std::mutex> lock(lock_);\n+    CHECK(!terminate_on_empty_);\n+    terminate_on_empty_ = true;\n+  }\n+  tasks_not_empty_or_terminate_.notify_all();\n+  for (auto& thread : workers_) {\n+    thread.join();\n+  }\n+  std::shared_lock<std::shared_mutex> abort_lock(abort_lock_);\n+  return status_;\n+}\n+\n+Status Bundle::JoinWithin(std::chrono::steady_clock::duration Δt) {\n+  return JoinBefore(std::chrono::steady_clock::now() + Δt);\n+}\n+\n+Status Bundle::JoinBefore(std::chrono::steady_clock::time_point t) {\n+  {\n+    std::unique_lock<std::shared_mutex> abort_lock(abort_lock_);\n+    deadline_ = t;\n+  }\n+  return Join();\n+}\n+\n+void Bundle::Add(Task task) {\n+  {\n+    std::unique_lock<std::mutex> lock(lock_);\n+    CHECK(!terminate_on_empty_);\n+    if (workers_.size() < max_workers_) {\n+      workers_.emplace_back(&Bundle::Toil, this);\n+    }\n+    tasks_.emplace(task);\n+  }\n+  tasks_not_empty_or_terminate_.notify_one();\n+}\n+\n+void Bundle::Toil() {\n+  Task current_task;\n+  AbortRequested = std::bind(&Bundle::BundleShouldAbort, this);\n+  for (;;) {\n+    {\n+      std::unique_lock<std::mutex> lock(lock_);\n+      tasks_not_empty_or_terminate_.wait(\n+          lock,\n+          [this] {\n+            return !tasks_.empty() || terminate_on_empty_ || Aborting();\n+          });\n+      // The call to |BundleShouldAbort| checks for deadline expiry and master\n+      // abort.\n+      if (tasks_.empty() || BundleShouldAbort()) {\n+        return;\n+      }\n+      current_task = std::move(tasks_.front());\n+      tasks_.pop();\n+    }\n+    Status status = current_task();","path":"base/bundle.cpp","position":79,"original_position":79,"commit_id":"436eb5b9e2913edd2227eb6b512bf2112a186fbe","original_commit_id":"436eb5b9e2913edd2227eb6b512bf2112a186fbe","user":{"login":"pleroy","id":7423020,"avatar_url":"https://avatars.githubusercontent.com/u/7423020?v=3","gravatar_id":"","url":"https://api.github.com/users/pleroy","html_url":"https://github.com/pleroy","followers_url":"https://api.github.com/users/pleroy/followers","following_url":"https://api.github.com/users/pleroy/following{/other_user}","gists_url":"https://api.github.com/users/pleroy/gists{/gist_id}","starred_url":"https://api.github.com/users/pleroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pleroy/subscriptions","organizations_url":"https://api.github.com/users/pleroy/orgs","repos_url":"https://api.github.com/users/pleroy/repos","events_url":"https://api.github.com/users/pleroy/events{/privacy}","received_events_url":"https://api.github.com/users/pleroy/received_events","type":"User","site_admin":false},"body":"`const`","created_at":"2016-11-25T21:17:56Z","updated_at":"2016-11-25T21:17:56Z","html_url":"https://github.com/mockingbirdnest/Principia/pull/1153#discussion_r89657618","pull_request_url":"https://api.github.com/repos/mockingbirdnest/Principia/pulls/1153","_links":{"self":{"href":"https://api.github.com/repos/mockingbirdnest/Principia/pulls/comments/89657618"},"html":{"href":"https://github.com/mockingbirdnest/Principia/pull/1153#discussion_r89657618"},"pull_request":{"href":"https://api.github.com/repos/mockingbirdnest/Principia/pulls/1153"}}},"pull_request":{"url":"https://api.github.com/repos/mockingbirdnest/Principia/pulls/1153","id":94858508,"html_url":"https://github.com/mockingbirdnest/Principia/pull/1153","diff_url":"https://github.com/mockingbirdnest/Principia/pull/1153.diff","patch_url":"https://github.com/mockingbirdnest/Principia/pull/1153.patch","issue_url":"https://api.github.com/repos/mockingbirdnest/Principia/issues/1153","number":1153,"state":"open","locked":false,"title":"Bundle","user":{"login":"eggrobin","id":2284290,"avatar_url":"https://avatars.githubusercontent.com/u/2284290?v=3","gravatar_id":"","url":"https://api.github.com/users/eggrobin","html_url":"https://github.com/eggrobin","followers_url":"https://api.github.com/users/eggrobin/followers","following_url":"https://api.github.com/users/eggrobin/following{/other_user}","gists_url":"https://api.github.com/users/eggrobin/gists{/gist_id}","starred_url":"https://api.github.com/users/eggrobin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eggrobin/subscriptions","organizations_url":"https://api.github.com/users/eggrobin/orgs","repos_url":"https://api.github.com/users/eggrobin/repos","events_url":"https://api.github.com/users/eggrobin/events{/privacy}","received_events_url":"https://api.github.com/users/eggrobin/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-11-22T17:16:50Z","updated_at":"2016-11-25T21:24:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6c0661043f407860bc869f5b4de255b68f8dd4b0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mockingbirdnest/Principia/pulls/1153/commits","review_comments_url":"https://api.github.com/repos/mockingbirdnest/Principia/pulls/1153/comments","review_comment_url":"https://api.github.com/repos/mockingbirdnest/Principia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mockingbirdnest/Principia/issues/1153/comments","statuses_url":"https://api.github.com/repos/mockingbirdnest/Principia/statuses/436eb5b9e2913edd2227eb6b512bf2112a186fbe","head":{"label":"eggrobin:bundle","ref":"bundle","sha":"436eb5b9e2913edd2227eb6b512bf2112a186fbe","user":{"login":"eggrobin","id":2284290,"avatar_url":"https://avatars.githubusercontent.com/u/2284290?v=3","gravatar_id":"","url":"https://api.github.com/users/eggrobin","html_url":"https://github.com/eggrobin","followers_url":"https://api.github.com/users/eggrobin/followers","following_url":"https://api.github.com/users/eggrobin/following{/other_user}","gists_url":"https://api.github.com/users/eggrobin/gists{/gist_id}","starred_url":"https://api.github.com/users/eggrobin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eggrobin/subscriptions","organizations_url":"https://api.github.com/users/eggrobin/orgs","repos_url":"https://api.github.com/users/eggrobin/repos","events_url":"https://api.github.com/users/eggrobin/events{/privacy}","received_events_url":"https://api.github.com/users/eggrobin/received_events","type":"User","site_admin":false},"repo":{"id":19360849,"name":"Principia","full_name":"eggrobin/Principia","owner":{"login":"eggrobin","id":2284290,"avatar_url":"https://avatars.githubusercontent.com/u/2284290?v=3","gravatar_id":"","url":"https://api.github.com/users/eggrobin","html_url":"https://github.com/eggrobin","followers_url":"https://api.github.com/users/eggrobin/followers","following_url":"https://api.github.com/users/eggrobin/following{/other_user}","gists_url":"https://api.github.com/users/eggrobin/gists{/gist_id}","starred_url":"https://api.github.com/users/eggrobin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eggrobin/subscriptions","organizations_url":"https://api.github.com/users/eggrobin/orgs","repos_url":"https://api.github.com/users/eggrobin/repos","events_url":"https://api.github.com/users/eggrobin/events{/privacy}","received_events_url":"https://api.github.com/users/eggrobin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/eggrobin/Principia","description":"N-Body Gravitation and Better Integrators for Kerbal Space Program","fork":true,"url":"https://api.github.com/repos/eggrobin/Principia","forks_url":"https://api.github.com/repos/eggrobin/Principia/forks","keys_url":"https://api.github.com/repos/eggrobin/Principia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eggrobin/Principia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eggrobin/Principia/teams","hooks_url":"https://api.github.com/repos/eggrobin/Principia/hooks","issue_events_url":"https://api.github.com/repos/eggrobin/Principia/issues/events{/number}","events_url":"https://api.github.com/repos/eggrobin/Principia/events","assignees_url":"https://api.github.com/repos/eggrobin/Principia/assignees{/user}","branches_url":"https://api.github.com/repos/eggrobin/Principia/branches{/branch}","tags_url":"https://api.github.com/repos/eggrobin/Principia/tags","blobs_url":"https://api.github.com/repos/eggrobin/Principia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eggrobin/Principia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eggrobin/Principia/git/refs{/sha}","trees_url":"https://api.github.com/repos/eggrobin/Principia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eggrobin/Principia/statuses/{sha}","languages_url":"https://api.github.com/repos/eggrobin/Principia/languages","stargazers_url":"https://api.github.com/repos/eggrobin/Principia/stargazers","contributors_url":"https://api.github.com/repos/eggrobin/Principia/contributors","subscribers_url":"https://api.github.com/repos/eggrobin/Principia/subscribers","subscription_url":"https://api.github.com/repos/eggrobin/Principia/subscription","commits_url":"https://api.github.com/repos/eggrobin/Principia/commits{/sha}","git_commits_url":"https://api.github.com/repos/eggrobin/Principia/git/commits{/sha}","comments_url":"https://api.github.com/repos/eggrobin/Principia/comments{/number}","issue_comment_url":"https://api.github.com/repos/eggrobin/Principia/issues/comments{/number}","contents_url":"https://api.github.com/repos/eggrobin/Principia/contents/{+path}","compare_url":"https://api.github.com/repos/eggrobin/Principia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eggrobin/Principia/merges","archive_url":"https://api.github.com/repos/eggrobin/Principia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eggrobin/Principia/downloads","issues_url":"https://api.github.com/repos/eggrobin/Principia/issues{/number}","pulls_url":"https://api.github.com/repos/eggrobin/Principia/pulls{/number}","milestones_url":"https://api.github.com/repos/eggrobin/Principia/milestones{/number}","notifications_url":"https://api.github.com/repos/eggrobin/Principia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eggrobin/Principia/labels{/name}","releases_url":"https://api.github.com/repos/eggrobin/Principia/releases{/id}","deployments_url":"https://api.github.com/repos/eggrobin/Principia/deployments","created_at":"2014-05-01T23:29:34Z","updated_at":"2016-10-31T11:19:03Z","pushed_at":"2016-11-24T21:59:07Z","git_url":"git://github.com/eggrobin/Principia.git","ssh_url":"git@github.com:eggrobin/Principia.git","clone_url":"https://github.com/eggrobin/Principia.git","svn_url":"https://github.com/eggrobin/Principia","homepage":"http://forum.kerbalspaceprogram.com/threads/68502-WIP-Principia-N-Body-Gravitation-and-Better-Integrators-for-Kerbal-Space-Program","size":26392,"stargazers_count":2,"watchers_count":2,"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":2,"default_branch":"master"}},"base":{"label":"mockingbirdnest:master","ref":"master","sha":"bbb372ffdf51dd789ff9a7bc9e77f9145015bb40","user":{"login":"mockingbirdnest","id":7462691,"avatar_url":"https://avatars.githubusercontent.com/u/7462691?v=3","gravatar_id":"","url":"https://api.github.com/users/mockingbirdnest","html_url":"https://github.com/mockingbirdnest","followers_url":"https://api.github.com/users/mockingbirdnest/followers","following_url":"https://api.github.com/users/mockingbirdnest/following{/other_user}","gists_url":"https://api.github.com/users/mockingbirdnest/gists{/gist_id}","starred_url":"https://api.github.com/users/mockingbirdnest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mockingbirdnest/subscriptions","organizations_url":"https://api.github.com/users/mockingbirdnest/orgs","repos_url":"https://api.github.com/users/mockingbirdnest/repos","events_url":"https://api.github.com/users/mockingbirdnest/events{/privacy}","received_events_url":"https://api.github.com/users/mockingbirdnest/received_events","type":"Organization","site_admin":false},"repo":{"id":16634370,"name":"Principia","full_name":"mockingbirdnest/Principia","owner":{"login":"mockingbirdnest","id":7462691,"avatar_url":"https://avatars.githubusercontent.com/u/7462691?v=3","gravatar_id":"","url":"https://api.github.com/users/mockingbirdnest","html_url":"https://github.com/mockingbirdnest","followers_url":"https://api.github.com/users/mockingbirdnest/followers","following_url":"https://api.github.com/users/mockingbirdnest/following{/other_user}","gists_url":"https://api.github.com/users/mockingbirdnest/gists{/gist_id}","starred_url":"https://api.github.com/users/mockingbirdnest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mockingbirdnest/subscriptions","organizations_url":"https://api.github.com/users/mockingbirdnest/orgs","repos_url":"https://api.github.com/users/mockingbirdnest/repos","events_url":"https://api.github.com/users/mockingbirdnest/events{/privacy}","received_events_url":"https://api.github.com/users/mockingbirdnest/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mockingbirdnest/Principia","description":"N-Body and Extended Body Gravitation for Kerbal Space Program","fork":false,"url":"https://api.github.com/repos/mockingbirdnest/Principia","forks_url":"https://api.github.com/repos/mockingbirdnest/Principia/forks","keys_url":"https://api.github.com/repos/mockingbirdnest/Principia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mockingbirdnest/Principia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mockingbirdnest/Principia/teams","hooks_url":"https://api.github.com/repos/mockingbirdnest/Principia/hooks","issue_events_url":"https://api.github.com/repos/mockingbirdnest/Principia/issues/events{/number}","events_url":"https://api.github.com/repos/mockingbirdnest/Principia/events","assignees_url":"https://api.github.com/repos/mockingbirdnest/Principia/assignees{/user}","branches_url":"https://api.github.com/repos/mockingbirdnest/Principia/branches{/branch}","tags_url":"https://api.github.com/repos/mockingbirdnest/Principia/tags","blobs_url":"https://api.github.com/repos/mockingbirdnest/Principia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mockingbirdnest/Principia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mockingbirdnest/Principia/git/refs{/sha}","trees_url":"https://api.github.com/repos/mockingbirdnest/Principia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mockingbirdnest/Principia/statuses/{sha}","languages_url":"https://api.github.com/repos/mockingbirdnest/Principia/languages","stargazers_url":"https://api.github.com/repos/mockingbirdnest/Principia/stargazers","contributors_url":"https://api.github.com/repos/mockingbirdnest/Principia/contributors","subscribers_url":"https://api.github.com/repos/mockingbirdnest/Principia/subscribers","subscription_url":"https://api.github.com/repos/mockingbirdnest/Principia/subscription","commits_url":"https://api.github.com/repos/mockingbirdnest/Principia/commits{/sha}","git_commits_url":"https://api.github.com/repos/mockingbirdnest/Principia/git/commits{/sha}","comments_url":"https://api.github.com/repos/mockingbirdnest/Principia/comments{/number}","issue_comment_url":"https://api.github.com/repos/mockingbirdnest/Principia/issues/comments{/number}","contents_url":"https://api.github.com/repos/mockingbirdnest/Principia/contents/{+path}","compare_url":"https://api.github.com/repos/mockingbirdnest/Principia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mockingbirdnest/Principia/merges","archive_url":"https://api.github.com/repos/mockingbirdnest/Principia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mockingbirdnest/Principia/downloads","issues_url":"https://api.github.com/repos/mockingbirdnest/Principia/issues{/number}","pulls_url":"https://api.github.com/repos/mockingbirdnest/Principia/pulls{/number}","milestones_url":"https://api.github.com/repos/mockingbirdnest/Principia/milestones{/number}","notifications_url":"https://api.github.com/repos/mockingbirdnest/Principia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mockingbirdnest/Principia/labels{/name}","releases_url":"https://api.github.com/repos/mockingbirdnest/Principia/releases{/id}","deployments_url":"https://api.github.com/repos/mockingbirdnest/Principia/deployments","created_at":"2014-02-08T02:55:32Z","updated_at":"2016-11-19T03:51:09Z","pushed_at":"2016-11-24T21:59:08Z","git_url":"git://github.com/mockingbirdnest/Principia.git","ssh_url":"git@github.com:mockingbirdnest/Principia.git","clone_url":"https://github.com/mockingbirdnest/Principia.git","svn_url":"https://github.com/mockingbirdnest/Principia","homepage":"","size":28548,"stargazers_count":132,"watchers_count":132,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":50,"forks":15,"open_issues":50,"watchers":132,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mockingbirdnest/Principia/pulls/1153"},"html":{"href":"https://github.com/mockingbirdnest/Principia/pull/1153"},"issue":{"href":"https://api.github.com/repos/mockingbirdnest/Principia/issues/1153"},"comments":{"href":"https://api.github.com/repos/mockingbirdnest/Principia/issues/1153/comments"},"review_comments":{"href":"https://api.github.com/repos/mockingbirdnest/Principia/pulls/1153/comments"},"review_comment":{"href":"https://api.github.com/repos/mockingbirdnest/Principia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mockingbirdnest/Principia/pulls/1153/commits"},"statuses":{"href":"https://api.github.com/repos/mockingbirdnest/Principia/statuses/436eb5b9e2913edd2227eb6b512bf2112a186fbe"}}}}
{"actor":{"display_login":"pleroy"}}