OLD | NEW |
1 // Copyright 2013 The Go Authors. All rights reserved. | 1 // Copyright 2013 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "defs_GOOS_GOARCH.h" | 6 #include "defs_GOOS_GOARCH.h" |
7 #include "os_GOOS.h" | 7 #include "os_GOOS.h" |
8 | 8 |
9 #define DWORD_MAX 0xffffffff | 9 #define DWORD_MAX 0xffffffff |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 G* | 64 G* |
65 runtime·netpoll(bool block) | 65 runtime·netpoll(bool block) |
66 { | 66 { |
67 uint32 wait, qty, key; | 67 uint32 wait, qty, key; |
68 int32 mode, errno; | 68 int32 mode, errno; |
69 net_anOp *o; | 69 net_anOp *o; |
70 G *gp; | 70 G *gp; |
71 | 71 |
72 if(iocphandle == INVALID_HANDLE_VALUE) | 72 if(iocphandle == INVALID_HANDLE_VALUE) |
73 return nil; | 73 return nil; |
| 74 gp = nil; |
| 75 retry: |
74 o = nil; | 76 o = nil; |
75 errno = 0; | 77 errno = 0; |
76 qty = 0; | 78 qty = 0; |
77 wait = INFINITE; | 79 wait = INFINITE; |
78 if(!block) | 80 if(!block) |
79 // TODO(brainman): should use 0 here instead, but scheduler hogs
CPU | 81 // TODO(brainman): should use 0 here instead, but scheduler hogs
CPU |
80 wait = 1; | 82 wait = 1; |
81 // TODO(brainman): Need a loop here to fetch all pending notifications | 83 // TODO(brainman): Need a loop here to fetch all pending notifications |
82 // (or at least a batch). Scheduler will behave better if is given | 84 // (or at least a batch). Scheduler will behave better if is given |
83 // a batch of newly runnable goroutines. | 85 // a batch of newly runnable goroutines. |
(...skipping 13 matching lines...) Expand all Loading... |
97 } | 99 } |
98 if(o == nil) | 100 if(o == nil) |
99 runtime·throw("netpoll: GetQueuedCompletionStatus returned o ==
nil"); | 101 runtime·throw("netpoll: GetQueuedCompletionStatus returned o ==
nil"); |
100 mode = o->mode; | 102 mode = o->mode; |
101 if(mode != 'r' && mode != 'w') { | 103 if(mode != 'r' && mode != 'w') { |
102 runtime·printf("netpoll: GetQueuedCompletionStatus returned inva
lid mode=%d\n", mode); | 104 runtime·printf("netpoll: GetQueuedCompletionStatus returned inva
lid mode=%d\n", mode); |
103 runtime·throw("netpoll: GetQueuedCompletionStatus returned inval
id mode"); | 105 runtime·throw("netpoll: GetQueuedCompletionStatus returned inval
id mode"); |
104 } | 106 } |
105 o->errno = errno; | 107 o->errno = errno; |
106 o->qty = qty; | 108 o->qty = qty; |
107 gp = nil; | |
108 runtime·netpollready(&gp, (void*)o->runtimeCtx, mode); | 109 runtime·netpollready(&gp, (void*)o->runtimeCtx, mode); |
| 110 if(block && gp == nil) |
| 111 goto retry; |
109 return gp; | 112 return gp; |
110 } | 113 } |
OLD | NEW |