GitHub PullRequestReviewCommentEvent at 2014-07-16 04:47:19
Repository: rippled
Actor: rec
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/ripple/rippled/pulls/comments/14981161","id":14981161,"diff_hunk":"@@ -22,201 +22,145 @@\n \n #include <beast/chrono/chrono_util.h>\n \n-#include <algorithm>\n #include <chrono>\n #include <condition_variable>\n #include <mutex>\n #include <thread>\n-#include <vector>\n \n-namespace beast {\n+extern \"C\" int main(int argc, char** argv);\n \n-namespace detail {\n+namespace beast {\n \n-class seconds_clock_worker\n+/** A clock whose minimum resolution is one second.\n+    The purpose of this class is to optimize the performance of the now()\n+    member function call. It uses a dedicated thread that wakes up at least\n+    once per second to sample the requested trivial clock.\n+    @tparam TrivialClock The clock to sample.\n+*/\n+template <class TrivialClock>\n+class basic_seconds_clock\n {\n public:\n-    virtual void sample () = 0;\n-};\n+    typedef std::chrono::seconds      duration;\n+    typedef typename duration::period period;\n+    typedef typename duration::rep    rep;\n+    typedef std::chrono::time_point <basic_seconds_clock> time_point;\n \n-//------------------------------------------------------------------------------\n+    static bool const is_steady = TrivialClock::is_steady;\n \n-// Updates the clocks\n-class seconds_clock_thread\n-{\n-public:\n-    typedef std::mutex mutex;\n-    typedef std::condition_variable cond_var;\n-    typedef std::lock_guard <mutex> lock_guard;\n-    typedef std::unique_lock <mutex> unique_lock;\n-    typedef std::chrono::steady_clock clock_type;\n-    typedef std::chrono::seconds seconds;\n-    typedef std::thread thread;\n-    typedef std::vector <seconds_clock_worker*> workers;\n-\n-    bool m_stop;\n-    mutex m_mutex;\n-    cond_var m_cond;\n-    workers m_workers;\n-    thread m_thread;\n-\n-    seconds_clock_thread ()\n-        : m_stop (false)\n+    ~basic_seconds_clock() = delete;\n+    basic_seconds_clock() = delete;\n+    static time_point now();\n+\n+private:\n+\n+    static std::mutex& mut()\n     {\n-        m_thread = thread (std::bind(\n-            &seconds_clock_thread::run, this));\n+        static std::mutex mut;\n+        return mut;\n     }\n \n-    ~seconds_clock_thread ()\n+    static std::condition_variable& cv()\n     {\n-        stop();\n+        static std::condition_variable cv;\n+        return cv;\n     }\n+    enum {uninitialized, started, stopping, stopped};\n \n-    void add (seconds_clock_worker& w)\n+    static unsigned& state()\n     {\n-        lock_guard lock (m_mutex);\n-        m_workers.push_back (&w);\n+        static unsigned state = uninitialized;\n+        return state;\n     }\n \n-    void remove (seconds_clock_worker& w)\n+    static time_point& get_now()\n     {\n-        lock_guard lock (m_mutex);\n-        m_workers.erase (std::find (\n-            m_workers.begin (), m_workers.end(), &w));\n+        static time_point now;\n+        return now;\n     }\n \n-    void stop()\n+    static void stop();\n+    static void update_clock();\n+    static unsigned init();\n+\n+    friend int ::main(int argc, char** argv);\n+};\n+\n+// If uninitialized, set to stopped.\n+// If started, stop.\n+// If stopping, wait for stopped then return.\n+// If stopped, do nothing.\n+template <class TrivialClock>\n+void\n+basic_seconds_clock<TrivialClock>::stop()\n+{\n+    std::unique_lock<std::mutex> lk(mut());\n+    if (state() == uninitialized)\n     {\n-        if (m_thread.joinable())\n-        {\n-            {\n-                lock_guard lock (m_mutex);\n-                m_stop = true;\n-            }\n-            m_cond.notify_all();\n-            m_thread.join();\n-        }\n+        state() = stopped;\n     }\n-\n-    void run()\n+    else if (state() != stopped)","path":"src/beast/beast/chrono/basic_seconds_clock.h","position":133,"original_position":133,"commit_id":"797cccfc3d550c04c8b1865c288e67136263c050","original_commit_id":"797cccfc3d550c04c8b1865c288e67136263c050","user":{"login":"rec","id":253362,"avatar_url":"https://avatars.githubusercontent.com/u/253362?","gravatar_id":"753ef975f85896eabdb64d9aa6ad4cbe","url":"https://api.github.com/users/rec","html_url":"https://github.com/rec","followers_url":"https://api.github.com/users/rec/followers","following_url":"https://api.github.com/users/rec/following{/other_user}","gists_url":"https://api.github.com/users/rec/gists{/gist_id}","starred_url":"https://api.github.com/users/rec/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rec/subscriptions","organizations_url":"https://api.github.com/users/rec/orgs","repos_url":"https://api.github.com/users/rec/repos","events_url":"https://api.github.com/users/rec/events{/privacy}","received_events_url":"https://api.github.com/users/rec/received_events","type":"User","site_admin":false},"body":"Aha, there are four states.  Strongly consider\r\n\r\nelse if (state() == started || state() == stopping())\r\n\r\nas a much clearer read (and also more likely to be correct if you move code around...)","created_at":"2014-07-16T04:47:19Z","updated_at":"2014-07-16T04:47:19Z","html_url":"https://github.com/ripple/rippled/pull/423#discussion_r14981161","pull_request_url":"https://api.github.com/repos/ripple/rippled/pulls/423","_links":{"self":{"href":"https://api.github.com/repos/ripple/rippled/pulls/comments/14981161"},"html":{"href":"https://github.com/ripple/rippled/pull/423#discussion_r14981161"},"pull_request":{"href":"https://api.github.com/repos/ripple/rippled/pulls/423"}}},"pull_request":{"url":"https://api.github.com/repos/ripple/rippled/pulls/423","id":17844123,"html_url":"https://github.com/ripple/rippled/pull/423","diff_url":"https://github.com/ripple/rippled/pull/423.diff","patch_url":"https://github.com/ripple/rippled/pull/423.patch","issue_url":"https://api.github.com/repos/ripple/rippled/issues/423","number":423,"state":"open","title":"Simplification of basic_seconds_clock.","user":{"login":"HowardHinnant","id":6708789,"avatar_url":"https://avatars.githubusercontent.com/u/6708789?","gravatar_id":"2a2941970f141aad669d13375dc57c4f","url":"https://api.github.com/users/HowardHinnant","html_url":"https://github.com/HowardHinnant","followers_url":"https://api.github.com/users/HowardHinnant/followers","following_url":"https://api.github.com/users/HowardHinnant/following{/other_user}","gists_url":"https://api.github.com/users/HowardHinnant/gists{/gist_id}","starred_url":"https://api.github.com/users/HowardHinnant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HowardHinnant/subscriptions","organizations_url":"https://api.github.com/users/HowardHinnant/orgs","repos_url":"https://api.github.com/users/HowardHinnant/repos","events_url":"https://api.github.com/users/HowardHinnant/events{/privacy}","received_events_url":"https://api.github.com/users/HowardHinnant/received_events","type":"User","site_admin":false},"body":"This eliminates an unnecessary vector of pointers from the basic_seconds_clock implementation.  This may allow us to remove the vc++ hack of stopping the clock at the end of main.","created_at":"2014-07-01T17:33:00Z","updated_at":"2014-07-16T04:47:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"18d31aef776430b356f930220dc5eddf3e4aca49","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ripple/rippled/pulls/423/commits","review_comments_url":"https://api.github.com/repos/ripple/rippled/pulls/423/comments","review_comment_url":"https://api.github.com/repos/ripple/rippled/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ripple/rippled/issues/423/comments","statuses_url":"https://api.github.com/repos/ripple/rippled/statuses/797cccfc3d550c04c8b1865c288e67136263c050","head":{"label":"HowardHinnant:clock","ref":"clock","sha":"797cccfc3d550c04c8b1865c288e67136263c050","user":{"login":"HowardHinnant","id":6708789,"avatar_url":"https://avatars.githubusercontent.com/u/6708789?","gravatar_id":"2a2941970f141aad669d13375dc57c4f","url":"https://api.github.com/users/HowardHinnant","html_url":"https://github.com/HowardHinnant","followers_url":"https://api.github.com/users/HowardHinnant/followers","following_url":"https://api.github.com/users/HowardHinnant/following{/other_user}","gists_url":"https://api.github.com/users/HowardHinnant/gists{/gist_id}","starred_url":"https://api.github.com/users/HowardHinnant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HowardHinnant/subscriptions","organizations_url":"https://api.github.com/users/HowardHinnant/orgs","repos_url":"https://api.github.com/users/HowardHinnant/repos","events_url":"https://api.github.com/users/HowardHinnant/events{/privacy}","received_events_url":"https://api.github.com/users/HowardHinnant/received_events","type":"User","site_admin":false},"repo":{"id":16925449,"name":"rippled","full_name":"HowardHinnant/rippled","owner":{"login":"HowardHinnant","id":6708789,"avatar_url":"https://avatars.githubusercontent.com/u/6708789?","gravatar_id":"2a2941970f141aad669d13375dc57c4f","url":"https://api.github.com/users/HowardHinnant","html_url":"https://github.com/HowardHinnant","followers_url":"https://api.github.com/users/HowardHinnant/followers","following_url":"https://api.github.com/users/HowardHinnant/following{/other_user}","gists_url":"https://api.github.com/users/HowardHinnant/gists{/gist_id}","starred_url":"https://api.github.com/users/HowardHinnant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HowardHinnant/subscriptions","organizations_url":"https://api.github.com/users/HowardHinnant/orgs","repos_url":"https://api.github.com/users/HowardHinnant/repos","events_url":"https://api.github.com/users/HowardHinnant/events{/privacy}","received_events_url":"https://api.github.com/users/HowardHinnant/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/HowardHinnant/rippled","description":"Ripple peer-to-peer network daemon","fork":true,"url":"https://api.github.com/repos/HowardHinnant/rippled","forks_url":"https://api.github.com/repos/HowardHinnant/rippled/forks","keys_url":"https://api.github.com/repos/HowardHinnant/rippled/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HowardHinnant/rippled/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HowardHinnant/rippled/teams","hooks_url":"https://api.github.com/repos/HowardHinnant/rippled/hooks","issue_events_url":"https://api.github.com/repos/HowardHinnant/rippled/issues/events{/number}","events_url":"https://api.github.com/repos/HowardHinnant/rippled/events","assignees_url":"https://api.github.com/repos/HowardHinnant/rippled/assignees{/user}","branches_url":"https://api.github.com/repos/HowardHinnant/rippled/branches{/branch}","tags_url":"https://api.github.com/repos/HowardHinnant/rippled/tags","blobs_url":"https://api.github.com/repos/HowardHinnant/rippled/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HowardHinnant/rippled/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HowardHinnant/rippled/git/refs{/sha}","trees_url":"https://api.github.com/repos/HowardHinnant/rippled/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HowardHinnant/rippled/statuses/{sha}","languages_url":"https://api.github.com/repos/HowardHinnant/rippled/languages","stargazers_url":"https://api.github.com/repos/HowardHinnant/rippled/stargazers","contributors_url":"https://api.github.com/repos/HowardHinnant/rippled/contributors","subscribers_url":"https://api.github.com/repos/HowardHinnant/rippled/subscribers","subscription_url":"https://api.github.com/repos/HowardHinnant/rippled/subscription","commits_url":"https://api.github.com/repos/HowardHinnant/rippled/commits{/sha}","git_commits_url":"https://api.github.com/repos/HowardHinnant/rippled/git/commits{/sha}","comments_url":"https://api.github.com/repos/HowardHinnant/rippled/comments{/number}","issue_comment_url":"https://api.github.com/repos/HowardHinnant/rippled/issues/comments/{number}","contents_url":"https://api.github.com/repos/HowardHinnant/rippled/contents/{+path}","compare_url":"https://api.github.com/repos/HowardHinnant/rippled/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HowardHinnant/rippled/merges","archive_url":"https://api.github.com/repos/HowardHinnant/rippled/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HowardHinnant/rippled/downloads","issues_url":"https://api.github.com/repos/HowardHinnant/rippled/issues{/number}","pulls_url":"https://api.github.com/repos/HowardHinnant/rippled/pulls{/number}","milestones_url":"https://api.github.com/repos/HowardHinnant/rippled/milestones{/number}","notifications_url":"https://api.github.com/repos/HowardHinnant/rippled/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HowardHinnant/rippled/labels{/name}","releases_url":"https://api.github.com/repos/HowardHinnant/rippled/releases{/id}","created_at":"2014-02-17T20:21:56Z","updated_at":"2014-07-02T23:08:30Z","pushed_at":"2014-07-15T21:05:02Z","git_url":"git://github.com/HowardHinnant/rippled.git","ssh_url":"git@github.com:HowardHinnant/rippled.git","clone_url":"https://github.com/HowardHinnant/rippled.git","svn_url":"https://github.com/HowardHinnant/rippled","homepage":"https://ripple.com","size":38023,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"ripple:develop","ref":"develop","sha":"418638ad16007b16e3da702c2f914f6814d9049e","user":{"login":"ripple","id":3165523,"avatar_url":"https://avatars.githubusercontent.com/u/3165523?","gravatar_id":"f6d67405ba8fc12a2d73e2131501a571","url":"https://api.github.com/users/ripple","html_url":"https://github.com/ripple","followers_url":"https://api.github.com/users/ripple/followers","following_url":"https://api.github.com/users/ripple/following{/other_user}","gists_url":"https://api.github.com/users/ripple/gists{/gist_id}","starred_url":"https://api.github.com/users/ripple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ripple/subscriptions","organizations_url":"https://api.github.com/users/ripple/orgs","repos_url":"https://api.github.com/users/ripple/repos","events_url":"https://api.github.com/users/ripple/events{/privacy}","received_events_url":"https://api.github.com/users/ripple/received_events","type":"Organization","site_admin":false},"repo":{"id":2724167,"name":"rippled","full_name":"ripple/rippled","owner":{"login":"ripple","id":3165523,"avatar_url":"https://avatars.githubusercontent.com/u/3165523?","gravatar_id":"f6d67405ba8fc12a2d73e2131501a571","url":"https://api.github.com/users/ripple","html_url":"https://github.com/ripple","followers_url":"https://api.github.com/users/ripple/followers","following_url":"https://api.github.com/users/ripple/following{/other_user}","gists_url":"https://api.github.com/users/ripple/gists{/gist_id}","starred_url":"https://api.github.com/users/ripple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ripple/subscriptions","organizations_url":"https://api.github.com/users/ripple/orgs","repos_url":"https://api.github.com/users/ripple/repos","events_url":"https://api.github.com/users/ripple/events{/privacy}","received_events_url":"https://api.github.com/users/ripple/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ripple/rippled","description":"Ripple peer-to-peer network daemon","fork":false,"url":"https://api.github.com/repos/ripple/rippled","forks_url":"https://api.github.com/repos/ripple/rippled/forks","keys_url":"https://api.github.com/repos/ripple/rippled/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ripple/rippled/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ripple/rippled/teams","hooks_url":"https://api.github.com/repos/ripple/rippled/hooks","issue_events_url":"https://api.github.com/repos/ripple/rippled/issues/events{/number}","events_url":"https://api.github.com/repos/ripple/rippled/events","assignees_url":"https://api.github.com/repos/ripple/rippled/assignees{/user}","branches_url":"https://api.github.com/repos/ripple/rippled/branches{/branch}","tags_url":"https://api.github.com/repos/ripple/rippled/tags","blobs_url":"https://api.github.com/repos/ripple/rippled/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ripple/rippled/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ripple/rippled/git/refs{/sha}","trees_url":"https://api.github.com/repos/ripple/rippled/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ripple/rippled/statuses/{sha}","languages_url":"https://api.github.com/repos/ripple/rippled/languages","stargazers_url":"https://api.github.com/repos/ripple/rippled/stargazers","contributors_url":"https://api.github.com/repos/ripple/rippled/contributors","subscribers_url":"https://api.github.com/repos/ripple/rippled/subscribers","subscription_url":"https://api.github.com/repos/ripple/rippled/subscription","commits_url":"https://api.github.com/repos/ripple/rippled/commits{/sha}","git_commits_url":"https://api.github.com/repos/ripple/rippled/git/commits{/sha}","comments_url":"https://api.github.com/repos/ripple/rippled/comments{/number}","issue_comment_url":"https://api.github.com/repos/ripple/rippled/issues/comments/{number}","contents_url":"https://api.github.com/repos/ripple/rippled/contents/{+path}","compare_url":"https://api.github.com/repos/ripple/rippled/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ripple/rippled/merges","archive_url":"https://api.github.com/repos/ripple/rippled/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ripple/rippled/downloads","issues_url":"https://api.github.com/repos/ripple/rippled/issues{/number}","pulls_url":"https://api.github.com/repos/ripple/rippled/pulls{/number}","milestones_url":"https://api.github.com/repos/ripple/rippled/milestones{/number}","notifications_url":"https://api.github.com/repos/ripple/rippled/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ripple/rippled/labels{/name}","releases_url":"https://api.github.com/repos/ripple/rippled/releases{/id}","created_at":"2011-11-07T04:40:15Z","updated_at":"2014-07-05T09:57:05Z","pushed_at":"2014-07-16T04:16:49Z","git_url":"git://github.com/ripple/rippled.git","ssh_url":"git@github.com:ripple/rippled.git","clone_url":"https://github.com/ripple/rippled.git","svn_url":"https://github.com/ripple/rippled","homepage":"https://ripple.com","size":59944,"stargazers_count":838,"watchers_count":838,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"forks_count":200,"mirror_url":null,"open_issues_count":126,"forks":200,"open_issues":126,"watchers":838,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/ripple/rippled/pulls/423"},"html":{"href":"https://github.com/ripple/rippled/pull/423"},"issue":{"href":"https://api.github.com/repos/ripple/rippled/issues/423"},"comments":{"href":"https://api.github.com/repos/ripple/rippled/issues/423/comments"},"review_comments":{"href":"https://api.github.com/repos/ripple/rippled/pulls/423/comments"},"review_comment":{"href":"https://api.github.com/repos/ripple/rippled/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ripple/rippled/pulls/423/commits"},"statuses":{"href":"https://api.github.com/repos/ripple/rippled/statuses/797cccfc3d550c04c8b1865c288e67136263c050"}}}}