{"action":"closed","number":6287,"pull_request":{"url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6287","id":37770350,"html_url":"https://github.com/bitcoin/bitcoin/pull/6287","diff_url":"https://github.com/bitcoin/bitcoin/pull/6287.diff","patch_url":"https://github.com/bitcoin/bitcoin/pull/6287.patch","issue_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/6287","number":6287,"state":"closed","locked":false,"title":"Clang lock debug","user":{"login":"theuni","id":417043,"avatar_url":"https://avatars.githubusercontent.com/u/417043?v=3","gravatar_id":"","url":"https://api.github.com/users/theuni","html_url":"https://github.com/theuni","followers_url":"https://api.github.com/users/theuni/followers","following_url":"https://api.github.com/users/theuni/following{/other_user}","gists_url":"https://api.github.com/users/theuni/gists{/gist_id}","starred_url":"https://api.github.com/users/theuni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theuni/subscriptions","organizations_url":"https://api.github.com/users/theuni/orgs","repos_url":"https://api.github.com/users/theuni/repos","events_url":"https://api.github.com/users/theuni/events{/privacy}","received_events_url":"https://api.github.com/users/theuni/received_events","type":"User","site_admin":false},"body":"This is part of a much larger networking refactor.\r\n\r\nAfter spending a while looking at different approaches for cleaning up the networking code, it's become apparent that some functions/classes are going to have to drop cs_main in favor of using their own fine-grained locks.\r\n\r\nBreaking up cs_main would be a monstrous task, and would likely be even harder to review.\r\n\r\nAs a first step, I've fixed up our locking so that LOCK() and friends play nicely with clang's -Wthread-safety static-analysis option. This will allow us to document locking assumptions while verifying them at the same time. I added https://github.com/bitcoin/bitcoin/commit/a794284e61988a226ea39327449be9906a1b5abd as an example of how this is useful.\r\n\r\nMy goal is to add the EXCLUSIVE_LOCKS_REQUIRED(cs_main)/GUARDED_BY(cs_main) as needed for functions that need to be broken out of the cs_main lock, that way locking changes can be verified much more easily.\r\n\r\nTo test:\r\n```bash\r\n./configure CXXFLAGS=\"-O2 -g -Wthread-safety\" CXX=clang++ CC=clang\r\n```\r\nTo see an example of a failure in action, comment out ```LOCK(cs_main);``` in ```FinalizeNode()```. The result should be something like:\r\n```\r\nmain.cpp:293:5: warning: calling function 'EraseOrphansFor' requires exclusive lock on 'cs_main' [-Wthread-safety-analysis]\r\n    EraseOrphansFor(nodeid);\r\n```","created_at":"2015-06-16T08:27:18Z","updated_at":"2015-07-23T16:45:38Z","closed_at":"2015-07-23T16:45:38Z","merged_at":"2015-07-23T16:45:38Z","merge_commit_sha":"170f0cc3b24ef446b1745938eea88a9c2092f485","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6287/commits","review_comments_url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6287/comments","review_comment_url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/6287/comments","statuses_url":"https://api.github.com/repos/bitcoin/bitcoin/statuses/a794284e61988a226ea39327449be9906a1b5abd","head":{"label":"theuni:clang-lock-debug","ref":"clang-lock-debug","sha":"a794284e61988a226ea39327449be9906a1b5abd","user":{"login":"theuni","id":417043,"avatar_url":"https://avatars.githubusercontent.com/u/417043?v=3","gravatar_id":"","url":"https://api.github.com/users/theuni","html_url":"https://github.com/theuni","followers_url":"https://api.github.com/users/theuni/followers","following_url":"https://api.github.com/users/theuni/following{/other_user}","gists_url":"https://api.github.com/users/theuni/gists{/gist_id}","starred_url":"https://api.github.com/users/theuni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theuni/subscriptions","organizations_url":"https://api.github.com/users/theuni/orgs","repos_url":"https://api.github.com/users/theuni/repos","events_url":"https://api.github.com/users/theuni/events{/privacy}","received_events_url":"https://api.github.com/users/theuni/received_events","type":"User","site_admin":false},"repo":{"id":10302141,"name":"bitcoin","full_name":"theuni/bitcoin","owner":{"login":"theuni","id":417043,"avatar_url":"https://avatars.githubusercontent.com/u/417043?v=3","gravatar_id":"","url":"https://api.github.com/users/theuni","html_url":"https://github.com/theuni","followers_url":"https://api.github.com/users/theuni/followers","following_url":"https://api.github.com/users/theuni/following{/other_user}","gists_url":"https://api.github.com/users/theuni/gists{/gist_id}","starred_url":"https://api.github.com/users/theuni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theuni/subscriptions","organizations_url":"https://api.github.com/users/theuni/orgs","repos_url":"https://api.github.com/users/theuni/repos","events_url":"https://api.github.com/users/theuni/events{/privacy}","received_events_url":"https://api.github.com/users/theuni/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/theuni/bitcoin","description":"Bitcoin integration/staging tree","fork":true,"url":"https://api.github.com/repos/theuni/bitcoin","forks_url":"https://api.github.com/repos/theuni/bitcoin/forks","keys_url":"https://api.github.com/repos/theuni/bitcoin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/theuni/bitcoin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/theuni/bitcoin/teams","hooks_url":"https://api.github.com/repos/theuni/bitcoin/hooks","issue_events_url":"https://api.github.com/repos/theuni/bitcoin/issues/events{/number}","events_url":"https://api.github.com/repos/theuni/bitcoin/events","assignees_url":"https://api.github.com/repos/theuni/bitcoin/assignees{/user}","branches_url":"https://api.github.com/repos/theuni/bitcoin/branches{/branch}","tags_url":"https://api.github.com/repos/theuni/bitcoin/tags","blobs_url":"https://api.github.com/repos/theuni/bitcoin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/theuni/bitcoin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/theuni/bitcoin/git/refs{/sha}","trees_url":"https://api.github.com/repos/theuni/bitcoin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/theuni/bitcoin/statuses/{sha}","languages_url":"https://api.github.com/repos/theuni/bitcoin/languages","stargazers_url":"https://api.github.com/repos/theuni/bitcoin/stargazers","contributors_url":"https://api.github.com/repos/theuni/bitcoin/contributors","subscribers_url":"https://api.github.com/repos/theuni/bitcoin/subscribers","subscription_url":"https://api.github.com/repos/theuni/bitcoin/subscription","commits_url":"https://api.github.com/repos/theuni/bitcoin/commits{/sha}","git_commits_url":"https://api.github.com/repos/theuni/bitcoin/git/commits{/sha}","comments_url":"https://api.github.com/repos/theuni/bitcoin/comments{/number}","issue_comment_url":"https://api.github.com/repos/theuni/bitcoin/issues/comments{/number}","contents_url":"https://api.github.com/repos/theuni/bitcoin/contents/{+path}","compare_url":"https://api.github.com/repos/theuni/bitcoin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/theuni/bitcoin/merges","archive_url":"https://api.github.com/repos/theuni/bitcoin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/theuni/bitcoin/downloads","issues_url":"https://api.github.com/repos/theuni/bitcoin/issues{/number}","pulls_url":"https://api.github.com/repos/theuni/bitcoin/pulls{/number}","milestones_url":"https://api.github.com/repos/theuni/bitcoin/milestones{/number}","notifications_url":"https://api.github.com/repos/theuni/bitcoin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/theuni/bitcoin/labels{/name}","releases_url":"https://api.github.com/repos/theuni/bitcoin/releases{/id}","created_at":"2013-05-26T18:55:06Z","updated_at":"2015-06-19T06:21:05Z","pushed_at":"2015-07-22T18:37:29Z","git_url":"git://github.com/theuni/bitcoin.git","ssh_url":"git@github.com:theuni/bitcoin.git","clone_url":"https://github.com/theuni/bitcoin.git","svn_url":"https://github.com/theuni/bitcoin","homepage":"http://www.bitcoin.org","size":63203,"stargazers_count":2,"watchers_count":2,"language":"C++","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":2,"default_branch":"trivial-next"}},"base":{"label":"bitcoin:master","ref":"master","sha":"11edb0de5b2b14ef2108bae41e1eae4ad51a3efe","user":{"login":"bitcoin","id":528860,"avatar_url":"https://avatars.githubusercontent.com/u/528860?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoin","html_url":"https://github.com/bitcoin","followers_url":"https://api.github.com/users/bitcoin/followers","following_url":"https://api.github.com/users/bitcoin/following{/other_user}","gists_url":"https://api.github.com/users/bitcoin/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoin/subscriptions","organizations_url":"https://api.github.com/users/bitcoin/orgs","repos_url":"https://api.github.com/users/bitcoin/repos","events_url":"https://api.github.com/users/bitcoin/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoin/received_events","type":"Organization","site_admin":false},"repo":{"id":1181927,"name":"bitcoin","full_name":"bitcoin/bitcoin","owner":{"login":"bitcoin","id":528860,"avatar_url":"https://avatars.githubusercontent.com/u/528860?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoin","html_url":"https://github.com/bitcoin","followers_url":"https://api.github.com/users/bitcoin/followers","following_url":"https://api.github.com/users/bitcoin/following{/other_user}","gists_url":"https://api.github.com/users/bitcoin/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoin/subscriptions","organizations_url":"https://api.github.com/users/bitcoin/orgs","repos_url":"https://api.github.com/users/bitcoin/repos","events_url":"https://api.github.com/users/bitcoin/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bitcoin/bitcoin","description":"Bitcoin Core integration/staging tree","fork":false,"url":"https://api.github.com/repos/bitcoin/bitcoin","forks_url":"https://api.github.com/repos/bitcoin/bitcoin/forks","keys_url":"https://api.github.com/repos/bitcoin/bitcoin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bitcoin/bitcoin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bitcoin/bitcoin/teams","hooks_url":"https://api.github.com/repos/bitcoin/bitcoin/hooks","issue_events_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/events{/number}","events_url":"https://api.github.com/repos/bitcoin/bitcoin/events","assignees_url":"https://api.github.com/repos/bitcoin/bitcoin/assignees{/user}","branches_url":"https://api.github.com/repos/bitcoin/bitcoin/branches{/branch}","tags_url":"https://api.github.com/repos/bitcoin/bitcoin/tags","blobs_url":"https://api.github.com/repos/bitcoin/bitcoin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bitcoin/bitcoin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bitcoin/bitcoin/git/refs{/sha}","trees_url":"https://api.github.com/repos/bitcoin/bitcoin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bitcoin/bitcoin/statuses/{sha}","languages_url":"https://api.github.com/repos/bitcoin/bitcoin/languages","stargazers_url":"https://api.github.com/repos/bitcoin/bitcoin/stargazers","contributors_url":"https://api.github.com/repos/bitcoin/bitcoin/contributors","subscribers_url":"https://api.github.com/repos/bitcoin/bitcoin/subscribers","subscription_url":"https://api.github.com/repos/bitcoin/bitcoin/subscription","commits_url":"https://api.github.com/repos/bitcoin/bitcoin/commits{/sha}","git_commits_url":"https://api.github.com/repos/bitcoin/bitcoin/git/commits{/sha}","comments_url":"https://api.github.com/repos/bitcoin/bitcoin/comments{/number}","issue_comment_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/comments{/number}","contents_url":"https://api.github.com/repos/bitcoin/bitcoin/contents/{+path}","compare_url":"https://api.github.com/repos/bitcoin/bitcoin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bitcoin/bitcoin/merges","archive_url":"https://api.github.com/repos/bitcoin/bitcoin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bitcoin/bitcoin/downloads","issues_url":"https://api.github.com/repos/bitcoin/bitcoin/issues{/number}","pulls_url":"https://api.github.com/repos/bitcoin/bitcoin/pulls{/number}","milestones_url":"https://api.github.com/repos/bitcoin/bitcoin/milestones{/number}","notifications_url":"https://api.github.com/repos/bitcoin/bitcoin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bitcoin/bitcoin/labels{/name}","releases_url":"https://api.github.com/repos/bitcoin/bitcoin/releases{/id}","created_at":"2010-12-19T15:16:43Z","updated_at":"2015-07-23T15:07:24Z","pushed_at":"2015-07-23T16:45:29Z","git_url":"git://github.com/bitcoin/bitcoin.git","ssh_url":"git@github.com:bitcoin/bitcoin.git","clone_url":"https://github.com/bitcoin/bitcoin.git","svn_url":"https://github.com/bitcoin/bitcoin","homepage":"https://bitcoin.org/en/download","size":130698,"stargazers_count":7210,"watchers_count":7210,"language":"C++","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":5037,"mirror_url":null,"open_issues_count":440,"forks":5037,"open_issues":440,"watchers":7210,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6287"},"html":{"href":"https://github.com/bitcoin/bitcoin/pull/6287"},"issue":{"href":"https://api.github.com/repos/bitcoin/bitcoin/issues/6287"},"comments":{"href":"https://api.github.com/repos/bitcoin/bitcoin/issues/6287/comments"},"review_comments":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6287/comments"},"review_comment":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6287/commits"},"statuses":{"href":"https://api.github.com/repos/bitcoin/bitcoin/statuses/a794284e61988a226ea39327449be9906a1b5abd"}},"merged":true,"mergeable":null,"mergeable_state":"unknown","merged_by":{"login":"laanwj","id":126646,"avatar_url":"https://avatars.githubusercontent.com/u/126646?v=3","gravatar_id":"","url":"https://api.github.com/users/laanwj","html_url":"https://github.com/laanwj","followers_url":"https://api.github.com/users/laanwj/followers","following_url":"https://api.github.com/users/laanwj/following{/other_user}","gists_url":"https://api.github.com/users/laanwj/gists{/gist_id}","starred_url":"https://api.github.com/users/laanwj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laanwj/subscriptions","organizations_url":"https://api.github.com/users/laanwj/orgs","repos_url":"https://api.github.com/users/laanwj/repos","events_url":"https://api.github.com/users/laanwj/events{/privacy}","received_events_url":"https://api.github.com/users/laanwj/received_events","type":"User","site_admin":false},"comments":12,"review_comments":0,"commits":3,"additions":15,"deletions":14,"changed_files":5}}