{"action":"created","comment":{"url":"https://api.github.com/repos/mono/mono/pulls/comments/47013723","id":47013723,"diff_hunk":"@@ -155,10 +157,376 @@ public void MarkDisposed ()\n \n \tinternal static class IOSelector\n \t{\n+\t\tstatic FileStream wakeup_pipes_rd;\n+\t\tstatic FileStream wakeup_pipes_wr;\n+\n+\t\tstatic Thread polling_thread;\n+\n+\t\tstatic readonly Update[] updates = new Update [32];\n+\t\tstatic int updates_last;\n+\n+\t\tstatic readonly byte[] send_buffer = new byte [1];\n+\t\tstatic readonly byte[] recv_buffer = new byte [updates.Length];\n+\n+\t\tstatic readonly IntPtr invalid_handle = new IntPtr (-1);\n+\n+\t\tstatic IOSelector ()\n+\t\t{\n+\t\t\tMonoIOError error;\n+\t\t\tIntPtr wakeup_pipes_rd_handle;\n+\t\t\tIntPtr wakeup_pipes_wr_handle;\n+\t\t\tif (!MonoIO.CreatePipe (out wakeup_pipes_rd_handle, out wakeup_pipes_wr_handle, out error))\n+\t\t\t\tthrow MonoIO.GetException (error);\n+\n+\t\t\twakeup_pipes_rd = new FileStream (new SafeFileHandle (wakeup_pipes_rd_handle, true), FileAccess.Read);\n+\t\t\twakeup_pipes_wr = new FileStream (new SafeFileHandle (wakeup_pipes_wr_handle, true), FileAccess.Write);\n+\n+\t\t\tpolling_thread = new Thread (PollingThread, Marshal.SizeOf (typeof (IntPtr)) * 32 * 1024);\n+\t\t\tpolling_thread.IsBackground = true;\n+\t\t\tpolling_thread.Start ();\n+\t\t}\n+\n+\t\tpublic static void Add (IntPtr handle, IOSelectorJob job)\n+\t\t{\n+\t\t\tif (Environment.HasShutdownStarted)\n+\t\t\t\treturn;\n+\n+\t\t\tlock (updates) {\n+\t\t\t\twhile (updates_last == updates.Length)\n+\t\t\t\t\tMonitor.Wait (updates);\n+\n+\t\t\t\tupdates [updates_last].type = UpdateType.Add;\n+\t\t\t\tupdates [updates_last].handle = handle;\n+\t\t\t\tupdates [updates_last].job = job;\n+\n+\t\t\t\tupdates_last += 1;\n+\n+\t\t\t\twakeup_pipes_wr.Write (send_buffer, 0, send_buffer.Length);\n+\t\t\t}\n+\t\t}\n+\n+\t\tpublic static void Remove (IntPtr handle)\n+\t\t{\n+\t\t\tif (Environment.HasShutdownStarted)\n+\t\t\t\treturn;\n+\n+\t\t\tlock (updates) {\n+\t\t\t\twhile (updates_last == updates.Length)\n+\t\t\t\t\tMonitor.Wait (updates);\n+\n+\t\t\t\tupdates [updates_last].type = UpdateType.Remove;\n+\t\t\t\tupdates [updates_last].handle = handle;\n+\n+\t\t\t\tupdates_last += 1;\n+\n+\t\t\t\twakeup_pipes_wr.Write (send_buffer, 0, send_buffer.Length);\n+\n+\t\t\t\tMonitor.Wait (updates);\n+\t\t\t}\n+\t\t}\n+\n+\t\tstatic bool FirstJobForOperation (List<IOSelectorJob> jobs, IOOperation operation, out IOSelectorJob job)\n+\t\t{\n+\t\t\tjob = default (IOSelectorJob);\n+\n+\t\t\tfor (int i = 0; i < jobs.Count; ++i) {\n+\t\t\t\tjob = jobs [i];\n+\t\t\t\tif ((job.Operation & operation) != 0) {\n+\t\t\t\t\tjobs.RemoveAt (i);\n+\t\t\t\t\treturn true;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tstatic int GetOperationsForJobs (List<IOSelectorJob> jobs)\n+\t\t{\n+\t\t\tint operations = 0;\n+\t\t\tfor (int i = 0; i < jobs.Count; ++i)\n+\t\t\t\toperations |= (int) jobs [i].Operation;\n+\n+\t\t\treturn operations;\n+\t\t}\n+\n+\t\tstatic void PollingThread ()\n+\t\t{\n+\t\t\tIntPtr backend = IntPtr.Zero;\n+\n+\t\t\ttry {\n+\t\t\t\tBackendInitialize (wakeup_pipes_rd.SafeFileHandle, out backend);\n+\n+\t\t\t\tDictionary<IntPtr, List<IOSelectorJob>> states = new Dictionary<IntPtr, List<IOSelectorJob>> ();\n+\t\t\t\tList<BackendUpdate> backend_updates = new List<BackendUpdate> ();\n+\t\t\t\tBackendEvent[] backend_events = new BackendEvent [8];\n+\n+\t\t\t\tfor (;;) {\n+\t\t\t\t\tlock (updates) {\n+\t\t\t\t\t\tfor (int i = 0; i < updates_last; ++i) {\n+\t\t\t\t\t\t\tUpdate u = updates [i];\n+\n+\t\t\t\t\t\t\tswitch (u.type) {\n+\t\t\t\t\t\t\tcase UpdateType.Empty: {\n+\t\t\t\t\t\t\t\tbreak;\n+\t\t\t\t\t\t\t}\n+\t\t\t\t\t\t\tcase UpdateType.Add: {\n+\t\t\t\t\t\t\t\tbool exists = states.ContainsKey (u.handle);\n+\t\t\t\t\t\t\t\tif (!exists)\n+\t\t\t\t\t\t\t\t\tstates.Add (u.handle, new List<IOSelectorJob> ());\n+\n+\t\t\t\t\t\t\t\tstates [u.handle].Add (u.job);\n+\n+\t\t\t\t\t\t\t\tint idx;\n+\t\t\t\t\t\t\t\tif ((idx = backend_updates.FindLastIndex (bu => bu.handle == u.handle)) == -1) {","path":"mcs/class/System/System/IOSelector.cs","position":174,"original_position":174,"commit_id":"3f5b30063d820d69e3d1c1a0b546c0af944020b7","original_commit_id":"3f5b30063d820d69e3d1c1a0b546c0af944020b7","user":{"login":"kumpera","id":5738,"avatar_url":"https://avatars.githubusercontent.com/u/5738?v=3","gravatar_id":"","url":"https://api.github.com/users/kumpera","html_url":"https://github.com/kumpera","followers_url":"https://api.github.com/users/kumpera/followers","following_url":"https://api.github.com/users/kumpera/following{/other_user}","gists_url":"https://api.github.com/users/kumpera/gists{/gist_id}","starred_url":"https://api.github.com/users/kumpera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kumpera/subscriptions","organizations_url":"https://api.github.com/users/kumpera/orgs","repos_url":"https://api.github.com/users/kumpera/repos","events_url":"https://api.github.com/users/kumpera/events{/privacy}","received_events_url":"https://api.github.com/users/kumpera/received_events","type":"User","site_admin":false},"body":"This introduces a heap allocated closure.","created_at":"2015-12-08T21:08:23Z","updated_at":"2015-12-08T21:08:23Z","html_url":"https://github.com/mono/mono/pull/2138#discussion_r47013723","pull_request_url":"https://api.github.com/repos/mono/mono/pulls/2138","_links":{"self":{"href":"https://api.github.com/repos/mono/mono/pulls/comments/47013723"},"html":{"href":"https://github.com/mono/mono/pull/2138#discussion_r47013723"},"pull_request":{"href":"https://api.github.com/repos/mono/mono/pulls/2138"}}},"pull_request":{"url":"https://api.github.com/repos/mono/mono/pulls/2138","id":47833513,"html_url":"https://github.com/mono/mono/pull/2138","diff_url":"https://github.com/mono/mono/pull/2138.diff","patch_url":"https://github.com/mono/mono/pull/2138.patch","issue_url":"https://api.github.com/repos/mono/mono/issues/2138","number":2138,"state":"open","locked":false,"title":"[threadpool-io] Move IOSelector to manage","user":{"login":"ludovic-henry","id":660779,"avatar_url":"https://avatars.githubusercontent.com/u/660779?v=3","gravatar_id":"","url":"https://api.github.com/users/ludovic-henry","html_url":"https://github.com/ludovic-henry","followers_url":"https://api.github.com/users/ludovic-henry/followers","following_url":"https://api.github.com/users/ludovic-henry/following{/other_user}","gists_url":"https://api.github.com/users/ludovic-henry/gists{/gist_id}","starred_url":"https://api.github.com/users/ludovic-henry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ludovic-henry/subscriptions","organizations_url":"https://api.github.com/users/ludovic-henry/orgs","repos_url":"https://api.github.com/users/ludovic-henry/repos","events_url":"https://api.github.com/users/ludovic-henry/events{/privacy}","received_events_url":"https://api.github.com/users/ludovic-henry/received_events","type":"User","site_admin":false},"body":null,"created_at":"2015-10-15T19:55:33Z","updated_at":"2015-12-08T21:08:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f0b39427396a24842674253fa2491c3f14fde985","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mono/mono/pulls/2138/commits","review_comments_url":"https://api.github.com/repos/mono/mono/pulls/2138/comments","review_comment_url":"https://api.github.com/repos/mono/mono/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mono/mono/issues/2138/comments","statuses_url":"https://api.github.com/repos/mono/mono/statuses/3f5b30063d820d69e3d1c1a0b546c0af944020b7","head":{"label":"ludovic-henry:threadpoolio-managed","ref":"threadpoolio-managed","sha":"3f5b30063d820d69e3d1c1a0b546c0af944020b7","user":{"login":"ludovic-henry","id":660779,"avatar_url":"https://avatars.githubusercontent.com/u/660779?v=3","gravatar_id":"","url":"https://api.github.com/users/ludovic-henry","html_url":"https://github.com/ludovic-henry","followers_url":"https://api.github.com/users/ludovic-henry/followers","following_url":"https://api.github.com/users/ludovic-henry/following{/other_user}","gists_url":"https://api.github.com/users/ludovic-henry/gists{/gist_id}","starred_url":"https://api.github.com/users/ludovic-henry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ludovic-henry/subscriptions","organizations_url":"https://api.github.com/users/ludovic-henry/orgs","repos_url":"https://api.github.com/users/ludovic-henry/repos","events_url":"https://api.github.com/users/ludovic-henry/events{/privacy}","received_events_url":"https://api.github.com/users/ludovic-henry/received_events","type":"User","site_admin":false},"repo":{"id":18306049,"name":"mono","full_name":"ludovic-henry/mono","owner":{"login":"ludovic-henry","id":660779,"avatar_url":"https://avatars.githubusercontent.com/u/660779?v=3","gravatar_id":"","url":"https://api.github.com/users/ludovic-henry","html_url":"https://github.com/ludovic-henry","followers_url":"https://api.github.com/users/ludovic-henry/followers","following_url":"https://api.github.com/users/ludovic-henry/following{/other_user}","gists_url":"https://api.github.com/users/ludovic-henry/gists{/gist_id}","starred_url":"https://api.github.com/users/ludovic-henry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ludovic-henry/subscriptions","organizations_url":"https://api.github.com/users/ludovic-henry/orgs","repos_url":"https://api.github.com/users/ludovic-henry/repos","events_url":"https://api.github.com/users/ludovic-henry/events{/privacy}","received_events_url":"https://api.github.com/users/ludovic-henry/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ludovic-henry/mono","description":"Mono open source ECMA CLI, C# and .NET implementation.","fork":true,"url":"https://api.github.com/repos/ludovic-henry/mono","forks_url":"https://api.github.com/repos/ludovic-henry/mono/forks","keys_url":"https://api.github.com/repos/ludovic-henry/mono/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ludovic-henry/mono/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ludovic-henry/mono/teams","hooks_url":"https://api.github.com/repos/ludovic-henry/mono/hooks","issue_events_url":"https://api.github.com/repos/ludovic-henry/mono/issues/events{/number}","events_url":"https://api.github.com/repos/ludovic-henry/mono/events","assignees_url":"https://api.github.com/repos/ludovic-henry/mono/assignees{/user}","branches_url":"https://api.github.com/repos/ludovic-henry/mono/branches{/branch}","tags_url":"https://api.github.com/repos/ludovic-henry/mono/tags","blobs_url":"https://api.github.com/repos/ludovic-henry/mono/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ludovic-henry/mono/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ludovic-henry/mono/git/refs{/sha}","trees_url":"https://api.github.com/repos/ludovic-henry/mono/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ludovic-henry/mono/statuses/{sha}","languages_url":"https://api.github.com/repos/ludovic-henry/mono/languages","stargazers_url":"https://api.github.com/repos/ludovic-henry/mono/stargazers","contributors_url":"https://api.github.com/repos/ludovic-henry/mono/contributors","subscribers_url":"https://api.github.com/repos/ludovic-henry/mono/subscribers","subscription_url":"https://api.github.com/repos/ludovic-henry/mono/subscription","commits_url":"https://api.github.com/repos/ludovic-henry/mono/commits{/sha}","git_commits_url":"https://api.github.com/repos/ludovic-henry/mono/git/commits{/sha}","comments_url":"https://api.github.com/repos/ludovic-henry/mono/comments{/number}","issue_comment_url":"https://api.github.com/repos/ludovic-henry/mono/issues/comments{/number}","contents_url":"https://api.github.com/repos/ludovic-henry/mono/contents/{+path}","compare_url":"https://api.github.com/repos/ludovic-henry/mono/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ludovic-henry/mono/merges","archive_url":"https://api.github.com/repos/ludovic-henry/mono/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ludovic-henry/mono/downloads","issues_url":"https://api.github.com/repos/ludovic-henry/mono/issues{/number}","pulls_url":"https://api.github.com/repos/ludovic-henry/mono/pulls{/number}","milestones_url":"https://api.github.com/repos/ludovic-henry/mono/milestones{/number}","notifications_url":"https://api.github.com/repos/ludovic-henry/mono/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ludovic-henry/mono/labels{/name}","releases_url":"https://api.github.com/repos/ludovic-henry/mono/releases{/id}","created_at":"2014-03-31T19:55:14Z","updated_at":"2015-05-01T16:19:32Z","pushed_at":"2015-12-08T20:49:47Z","git_url":"git://github.com/ludovic-henry/mono.git","ssh_url":"git@github.com:ludovic-henry/mono.git","clone_url":"https://github.com/ludovic-henry/mono.git","svn_url":"https://github.com/ludovic-henry/mono","homepage":"http://www.mono-project.com/","size":445182,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mono:master","ref":"master","sha":"a595d489fa64d8e213c74470f23c576296e2d548","user":{"login":"mono","id":53395,"avatar_url":"https://avatars.githubusercontent.com/u/53395?v=3","gravatar_id":"","url":"https://api.github.com/users/mono","html_url":"https://github.com/mono","followers_url":"https://api.github.com/users/mono/followers","following_url":"https://api.github.com/users/mono/following{/other_user}","gists_url":"https://api.github.com/users/mono/gists{/gist_id}","starred_url":"https://api.github.com/users/mono/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mono/subscriptions","organizations_url":"https://api.github.com/users/mono/orgs","repos_url":"https://api.github.com/users/mono/repos","events_url":"https://api.github.com/users/mono/events{/privacy}","received_events_url":"https://api.github.com/users/mono/received_events","type":"Organization","site_admin":false},"repo":{"id":791611,"name":"mono","full_name":"mono/mono","owner":{"login":"mono","id":53395,"avatar_url":"https://avatars.githubusercontent.com/u/53395?v=3","gravatar_id":"","url":"https://api.github.com/users/mono","html_url":"https://github.com/mono","followers_url":"https://api.github.com/users/mono/followers","following_url":"https://api.github.com/users/mono/following{/other_user}","gists_url":"https://api.github.com/users/mono/gists{/gist_id}","starred_url":"https://api.github.com/users/mono/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mono/subscriptions","organizations_url":"https://api.github.com/users/mono/orgs","repos_url":"https://api.github.com/users/mono/repos","events_url":"https://api.github.com/users/mono/events{/privacy}","received_events_url":"https://api.github.com/users/mono/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mono/mono","description":"Mono open source ECMA CLI, C# and .NET implementation.","fork":false,"url":"https://api.github.com/repos/mono/mono","forks_url":"https://api.github.com/repos/mono/mono/forks","keys_url":"https://api.github.com/repos/mono/mono/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mono/mono/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mono/mono/teams","hooks_url":"https://api.github.com/repos/mono/mono/hooks","issue_events_url":"https://api.github.com/repos/mono/mono/issues/events{/number}","events_url":"https://api.github.com/repos/mono/mono/events","assignees_url":"https://api.github.com/repos/mono/mono/assignees{/user}","branches_url":"https://api.github.com/repos/mono/mono/branches{/branch}","tags_url":"https://api.github.com/repos/mono/mono/tags","blobs_url":"https://api.github.com/repos/mono/mono/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mono/mono/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mono/mono/git/refs{/sha}","trees_url":"https://api.github.com/repos/mono/mono/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mono/mono/statuses/{sha}","languages_url":"https://api.github.com/repos/mono/mono/languages","stargazers_url":"https://api.github.com/repos/mono/mono/stargazers","contributors_url":"https://api.github.com/repos/mono/mono/contributors","subscribers_url":"https://api.github.com/repos/mono/mono/subscribers","subscription_url":"https://api.github.com/repos/mono/mono/subscription","commits_url":"https://api.github.com/repos/mono/mono/commits{/sha}","git_commits_url":"https://api.github.com/repos/mono/mono/git/commits{/sha}","comments_url":"https://api.github.com/repos/mono/mono/comments{/number}","issue_comment_url":"https://api.github.com/repos/mono/mono/issues/comments{/number}","contents_url":"https://api.github.com/repos/mono/mono/contents/{+path}","compare_url":"https://api.github.com/repos/mono/mono/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mono/mono/merges","archive_url":"https://api.github.com/repos/mono/mono/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mono/mono/downloads","issues_url":"https://api.github.com/repos/mono/mono/issues{/number}","pulls_url":"https://api.github.com/repos/mono/mono/pulls{/number}","milestones_url":"https://api.github.com/repos/mono/mono/milestones{/number}","notifications_url":"https://api.github.com/repos/mono/mono/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mono/mono/labels{/name}","releases_url":"https://api.github.com/repos/mono/mono/releases{/id}","created_at":"2010-07-22T18:06:36Z","updated_at":"2015-12-08T21:05:47Z","pushed_at":"2015-12-08T20:49:53Z","git_url":"git://github.com/mono/mono.git","ssh_url":"git@github.com:mono/mono.git","clone_url":"https://github.com/mono/mono.git","svn_url":"https://github.com/mono/mono","homepage":"http://www.mono-project.com/","size":481257,"stargazers_count":4092,"watchers_count":4092,"language":"C#","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":2019,"mirror_url":null,"open_issues_count":120,"forks":2019,"open_issues":120,"watchers":4092,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mono/mono/pulls/2138"},"html":{"href":"https://github.com/mono/mono/pull/2138"},"issue":{"href":"https://api.github.com/repos/mono/mono/issues/2138"},"comments":{"href":"https://api.github.com/repos/mono/mono/issues/2138/comments"},"review_comments":{"href":"https://api.github.com/repos/mono/mono/pulls/2138/comments"},"review_comment":{"href":"https://api.github.com/repos/mono/mono/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mono/mono/pulls/2138/commits"},"statuses":{"href":"https://api.github.com/repos/mono/mono/statuses/3f5b30063d820d69e3d1c1a0b546c0af944020b7"}}}}