{"action":"opened","number":1496,"pull_request":{"url":"https://api.github.com/repos/OpenZWave/open-zwave/pulls/1496","id":184939650,"html_url":"https://github.com/OpenZWave/open-zwave/pull/1496","diff_url":"https://github.com/OpenZWave/open-zwave/pull/1496.diff","patch_url":"https://github.com/OpenZWave/open-zwave/pull/1496.patch","issue_url":"https://api.github.com/repos/OpenZWave/open-zwave/issues/1496","number":1496,"state":"open","locked":false,"title":"Allow RemoveWatcher to be called from a watcher callback","user":{"login":"DvdGiessen","id":954385,"avatar_url":"https://avatars0.githubusercontent.com/u/954385?v=4","gravatar_id":"","url":"https://api.github.com/users/DvdGiessen","html_url":"https://github.com/DvdGiessen","followers_url":"https://api.github.com/users/DvdGiessen/followers","following_url":"https://api.github.com/users/DvdGiessen/following{/other_user}","gists_url":"https://api.github.com/users/DvdGiessen/gists{/gist_id}","starred_url":"https://api.github.com/users/DvdGiessen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DvdGiessen/subscriptions","organizations_url":"https://api.github.com/users/DvdGiessen/orgs","repos_url":"https://api.github.com/users/DvdGiessen/repos","events_url":"https://api.github.com/users/DvdGiessen/events{/privacy}","received_events_url":"https://api.github.com/users/DvdGiessen/received_events","type":"User","site_admin":false},"body":"Right now, it is not possible to remove a watcher from from the callback itself, because this causes the iterator in `NotifyWatchers` to be invalidated. In other words, there are scenario's in which it is unsafe to call `RemoveWatcher`.\r\n\r\nAs an example, it is currently not possible to write code like below without causing a fatal crash (simplified example):\r\n```cpp\r\nvoid OnNotification ( Notification const* _notification, void* _context ) {\r\n    // Do something we only need to do once\r\n    // ...\r\n\r\n    // We no longer need notifications, remove this watcher\r\n    Manager::Get()->RemoveWatcher( OnNotification, NULL );\r\n}\r\n\r\nManager::Get()->AddWatcher( OnNotification, NULL );\r\n```\r\n\r\nIn this simplified example it is of course a bit silly to want to remove the watcher, but in a more complex application it may make sense to remove watchers like this. Right now, an application creator could write some workaround code to be able to remove the watcher, but that introduces additional complexity for them solely to deal with an internal limitation of the library.\r\n\r\nThis proposed change removes this limitation by updating the `NotifyWatchers` iterator when removing a watcher, thus making the `RemoveWatcher` method safe to call even from a watcher callback.\r\n\r\nNote that I opted to use a list of iterators instead of a single property for holding the current iterator, as that ensures this piece of code will not break when (possibly due to future changes) `NotifyWatchers` is called recursively. The overhead of using a list is expected to be negligible. Also, due to both methods locking the NotificationMutex this change is thread-safe.","created_at":"2018-04-30T12:06:00Z","updated_at":"2018-04-30T12:06:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/OpenZWave/open-zwave/pulls/1496/commits","review_comments_url":"https://api.github.com/repos/OpenZWave/open-zwave/pulls/1496/comments","review_comment_url":"https://api.github.com/repos/OpenZWave/open-zwave/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OpenZWave/open-zwave/issues/1496/comments","statuses_url":"https://api.github.com/repos/OpenZWave/open-zwave/statuses/7def699f408dede697adf2a54ea5a66c21471eab","head":{"label":"DvdGiessen:watcher-removal-during-iteration","ref":"watcher-removal-during-iteration","sha":"7def699f408dede697adf2a54ea5a66c21471eab","user":{"login":"DvdGiessen","id":954385,"avatar_url":"https://avatars0.githubusercontent.com/u/954385?v=4","gravatar_id":"","url":"https://api.github.com/users/DvdGiessen","html_url":"https://github.com/DvdGiessen","followers_url":"https://api.github.com/users/DvdGiessen/followers","following_url":"https://api.github.com/users/DvdGiessen/following{/other_user}","gists_url":"https://api.github.com/users/DvdGiessen/gists{/gist_id}","starred_url":"https://api.github.com/users/DvdGiessen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DvdGiessen/subscriptions","organizations_url":"https://api.github.com/users/DvdGiessen/orgs","repos_url":"https://api.github.com/users/DvdGiessen/repos","events_url":"https://api.github.com/users/DvdGiessen/events{/privacy}","received_events_url":"https://api.github.com/users/DvdGiessen/received_events","type":"User","site_admin":false},"repo":{"id":128825849,"name":"open-zwave","full_name":"DvdGiessen/open-zwave","owner":{"login":"DvdGiessen","id":954385,"avatar_url":"https://avatars0.githubusercontent.com/u/954385?v=4","gravatar_id":"","url":"https://api.github.com/users/DvdGiessen","html_url":"https://github.com/DvdGiessen","followers_url":"https://api.github.com/users/DvdGiessen/followers","following_url":"https://api.github.com/users/DvdGiessen/following{/other_user}","gists_url":"https://api.github.com/users/DvdGiessen/gists{/gist_id}","starred_url":"https://api.github.com/users/DvdGiessen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DvdGiessen/subscriptions","organizations_url":"https://api.github.com/users/DvdGiessen/orgs","repos_url":"https://api.github.com/users/DvdGiessen/repos","events_url":"https://api.github.com/users/DvdGiessen/events{/privacy}","received_events_url":"https://api.github.com/users/DvdGiessen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/DvdGiessen/open-zwave","description":"a C++ library to control Z-Wave Networks via a USB Z-Wave Controller. ","fork":true,"url":"https://api.github.com/repos/DvdGiessen/open-zwave","forks_url":"https://api.github.com/repos/DvdGiessen/open-zwave/forks","keys_url":"https://api.github.com/repos/DvdGiessen/open-zwave/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DvdGiessen/open-zwave/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DvdGiessen/open-zwave/teams","hooks_url":"https://api.github.com/repos/DvdGiessen/open-zwave/hooks","issue_events_url":"https://api.github.com/repos/DvdGiessen/open-zwave/issues/events{/number}","events_url":"https://api.github.com/repos/DvdGiessen/open-zwave/events","assignees_url":"https://api.github.com/repos/DvdGiessen/open-zwave/assignees{/user}","branches_url":"https://api.github.com/repos/DvdGiessen/open-zwave/branches{/branch}","tags_url":"https://api.github.com/repos/DvdGiessen/open-zwave/tags","blobs_url":"https://api.github.com/repos/DvdGiessen/open-zwave/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DvdGiessen/open-zwave/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DvdGiessen/open-zwave/git/refs{/sha}","trees_url":"https://api.github.com/repos/DvdGiessen/open-zwave/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DvdGiessen/open-zwave/statuses/{sha}","languages_url":"https://api.github.com/repos/DvdGiessen/open-zwave/languages","stargazers_url":"https://api.github.com/repos/DvdGiessen/open-zwave/stargazers","contributors_url":"https://api.github.com/repos/DvdGiessen/open-zwave/contributors","subscribers_url":"https://api.github.com/repos/DvdGiessen/open-zwave/subscribers","subscription_url":"https://api.github.com/repos/DvdGiessen/open-zwave/subscription","commits_url":"https://api.github.com/repos/DvdGiessen/open-zwave/commits{/sha}","git_commits_url":"https://api.github.com/repos/DvdGiessen/open-zwave/git/commits{/sha}","comments_url":"https://api.github.com/repos/DvdGiessen/open-zwave/comments{/number}","issue_comment_url":"https://api.github.com/repos/DvdGiessen/open-zwave/issues/comments{/number}","contents_url":"https://api.github.com/repos/DvdGiessen/open-zwave/contents/{+path}","compare_url":"https://api.github.com/repos/DvdGiessen/open-zwave/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DvdGiessen/open-zwave/merges","archive_url":"https://api.github.com/repos/DvdGiessen/open-zwave/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DvdGiessen/open-zwave/downloads","issues_url":"https://api.github.com/repos/DvdGiessen/open-zwave/issues{/number}","pulls_url":"https://api.github.com/repos/DvdGiessen/open-zwave/pulls{/number}","milestones_url":"https://api.github.com/repos/DvdGiessen/open-zwave/milestones{/number}","notifications_url":"https://api.github.com/repos/DvdGiessen/open-zwave/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DvdGiessen/open-zwave/labels{/name}","releases_url":"https://api.github.com/repos/DvdGiessen/open-zwave/releases{/id}","deployments_url":"https://api.github.com/repos/DvdGiessen/open-zwave/deployments","created_at":"2018-04-09T19:52:01Z","updated_at":"2018-04-30T11:07:14Z","pushed_at":"2018-04-30T11:15:37Z","git_url":"git://github.com/DvdGiessen/open-zwave.git","ssh_url":"git@github.com:DvdGiessen/open-zwave.git","clone_url":"https://github.com/DvdGiessen/open-zwave.git","svn_url":"https://github.com/DvdGiessen/open-zwave","homepage":"http://www.openzwave.net/","size":109229,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":false,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"OpenZWave:master","ref":"master","sha":"c8441b106a41fe2577481d92faf5da69b74f5c23","user":{"login":"OpenZWave","id":7971916,"avatar_url":"https://avatars3.githubusercontent.com/u/7971916?v=4","gravatar_id":"","url":"https://api.github.com/users/OpenZWave","html_url":"https://github.com/OpenZWave","followers_url":"https://api.github.com/users/OpenZWave/followers","following_url":"https://api.github.com/users/OpenZWave/following{/other_user}","gists_url":"https://api.github.com/users/OpenZWave/gists{/gist_id}","starred_url":"https://api.github.com/users/OpenZWave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OpenZWave/subscriptions","organizations_url":"https://api.github.com/users/OpenZWave/orgs","repos_url":"https://api.github.com/users/OpenZWave/repos","events_url":"https://api.github.com/users/OpenZWave/events{/privacy}","received_events_url":"https://api.github.com/users/OpenZWave/received_events","type":"Organization","site_admin":false},"repo":{"id":32202720,"name":"open-zwave","full_name":"OpenZWave/open-zwave","owner":{"login":"OpenZWave","id":7971916,"avatar_url":"https://avatars3.githubusercontent.com/u/7971916?v=4","gravatar_id":"","url":"https://api.github.com/users/OpenZWave","html_url":"https://github.com/OpenZWave","followers_url":"https://api.github.com/users/OpenZWave/followers","following_url":"https://api.github.com/users/OpenZWave/following{/other_user}","gists_url":"https://api.github.com/users/OpenZWave/gists{/gist_id}","starred_url":"https://api.github.com/users/OpenZWave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OpenZWave/subscriptions","organizations_url":"https://api.github.com/users/OpenZWave/orgs","repos_url":"https://api.github.com/users/OpenZWave/repos","events_url":"https://api.github.com/users/OpenZWave/events{/privacy}","received_events_url":"https://api.github.com/users/OpenZWave/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/OpenZWave/open-zwave","description":"a C++ library to control Z-Wave Networks via a USB Z-Wave Controller. ","fork":false,"url":"https://api.github.com/repos/OpenZWave/open-zwave","forks_url":"https://api.github.com/repos/OpenZWave/open-zwave/forks","keys_url":"https://api.github.com/repos/OpenZWave/open-zwave/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OpenZWave/open-zwave/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OpenZWave/open-zwave/teams","hooks_url":"https://api.github.com/repos/OpenZWave/open-zwave/hooks","issue_events_url":"https://api.github.com/repos/OpenZWave/open-zwave/issues/events{/number}","events_url":"https://api.github.com/repos/OpenZWave/open-zwave/events","assignees_url":"https://api.github.com/repos/OpenZWave/open-zwave/assignees{/user}","branches_url":"https://api.github.com/repos/OpenZWave/open-zwave/branches{/branch}","tags_url":"https://api.github.com/repos/OpenZWave/open-zwave/tags","blobs_url":"https://api.github.com/repos/OpenZWave/open-zwave/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OpenZWave/open-zwave/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OpenZWave/open-zwave/git/refs{/sha}","trees_url":"https://api.github.com/repos/OpenZWave/open-zwave/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OpenZWave/open-zwave/statuses/{sha}","languages_url":"https://api.github.com/repos/OpenZWave/open-zwave/languages","stargazers_url":"https://api.github.com/repos/OpenZWave/open-zwave/stargazers","contributors_url":"https://api.github.com/repos/OpenZWave/open-zwave/contributors","subscribers_url":"https://api.github.com/repos/OpenZWave/open-zwave/subscribers","subscription_url":"https://api.github.com/repos/OpenZWave/open-zwave/subscription","commits_url":"https://api.github.com/repos/OpenZWave/open-zwave/commits{/sha}","git_commits_url":"https://api.github.com/repos/OpenZWave/open-zwave/git/commits{/sha}","comments_url":"https://api.github.com/repos/OpenZWave/open-zwave/comments{/number}","issue_comment_url":"https://api.github.com/repos/OpenZWave/open-zwave/issues/comments{/number}","contents_url":"https://api.github.com/repos/OpenZWave/open-zwave/contents/{+path}","compare_url":"https://api.github.com/repos/OpenZWave/open-zwave/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OpenZWave/open-zwave/merges","archive_url":"https://api.github.com/repos/OpenZWave/open-zwave/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OpenZWave/open-zwave/downloads","issues_url":"https://api.github.com/repos/OpenZWave/open-zwave/issues{/number}","pulls_url":"https://api.github.com/repos/OpenZWave/open-zwave/pulls{/number}","milestones_url":"https://api.github.com/repos/OpenZWave/open-zwave/milestones{/number}","notifications_url":"https://api.github.com/repos/OpenZWave/open-zwave/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OpenZWave/open-zwave/labels{/name}","releases_url":"https://api.github.com/repos/OpenZWave/open-zwave/releases{/id}","deployments_url":"https://api.github.com/repos/OpenZWave/open-zwave/deployments","created_at":"2015-03-14T08:38:14Z","updated_at":"2018-04-28T19:52:59Z","pushed_at":"2018-04-30T11:45:53Z","git_url":"git://github.com/OpenZWave/open-zwave.git","ssh_url":"git@github.com:OpenZWave/open-zwave.git","clone_url":"https://github.com/OpenZWave/open-zwave.git","svn_url":"https://github.com/OpenZWave/open-zwave","homepage":"http://www.openzwave.net/","size":109817,"stargazers_count":560,"watchers_count":560,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":false,"has_wiki":true,"has_pages":false,"forks_count":480,"mirror_url":null,"archived":false,"open_issues_count":129,"license":null,"forks":480,"open_issues":129,"watchers":560,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/OpenZWave/open-zwave/pulls/1496"},"html":{"href":"https://github.com/OpenZWave/open-zwave/pull/1496"},"issue":{"href":"https://api.github.com/repos/OpenZWave/open-zwave/issues/1496"},"comments":{"href":"https://api.github.com/repos/OpenZWave/open-zwave/issues/1496/comments"},"review_comments":{"href":"https://api.github.com/repos/OpenZWave/open-zwave/pulls/1496/comments"},"review_comment":{"href":"https://api.github.com/repos/OpenZWave/open-zwave/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OpenZWave/open-zwave/pulls/1496/commits"},"statuses":{"href":"https://api.github.com/repos/OpenZWave/open-zwave/statuses/7def699f408dede697adf2a54ea5a66c21471eab"}},"author_association":"NONE","merged":false,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"maintainer_can_modify":true,"commits":1,"additions":16,"deletions":5,"changed_files":2}}
{"actor":{"display_login":"DvdGiessen"}}