Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Side by Side Diff: src/pkg/runtime/netpoll.goc

Issue 56060043: code review 56060043: undo CL 45770044 / d795425bfa18 (Closed)
Patch Set: diff -r d795425bfa18 https://dvyukov%40google.com@code.google.com/p/go/ Created 11 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/runtime/mgc0.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // +build darwin dragonfly freebsd linux netbsd openbsd solaris windows 5 // +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
6 6
7 package net 7 package net
8 8
9 #include "runtime.h" 9 #include "runtime.h"
10 #include "defs_GOOS_GOARCH.h" 10 #include "defs_GOOS_GOARCH.h"
(...skipping 16 matching lines...) Expand all
27 // the goroutine commits to park by changing the state to G pointer, 27 // the goroutine commits to park by changing the state to G pointer,
28 // or, alternatively, concurrent io notification changes the state to REA DY, 28 // or, alternatively, concurrent io notification changes the state to REA DY,
29 // or, alternatively, concurrent timeout/close changes the state to nil. 29 // or, alternatively, concurrent timeout/close changes the state to nil.
30 // G pointer - the goroutine is blocked on the semaphore; 30 // G pointer - the goroutine is blocked on the semaphore;
31 // io notification or timeout/close changes the state to READY or ni l respectively 31 // io notification or timeout/close changes the state to READY or ni l respectively
32 // and unparks the goroutine. 32 // and unparks the goroutine.
33 // nil - nothing of the above. 33 // nil - nothing of the above.
34 #define READY ((G*)1) 34 #define READY ((G*)1)
35 #define WAIT ((G*)2) 35 #define WAIT ((G*)2)
36 36
37 enum
38 {
39 PollBlockSize = 4*1024,
40 };
41
42 struct PollDesc 37 struct PollDesc
43 { 38 {
44 PollDesc* link; // in pollcache, protected by pollcache.Lock 39 PollDesc* link; // in pollcache, protected by pollcache.Lock
45 40
46 // The lock protects pollOpen, pollSetDeadline, pollUnblock and deadline impl operations. 41 // The lock protects pollOpen, pollSetDeadline, pollUnblock and deadline impl operations.
47 // This fully covers seq, rt and wt variables. fd is constant throughout the PollDesc lifetime. 42 // This fully covers seq, rt and wt variables. fd is constant throughout the PollDesc lifetime.
48 // pollReset, pollWait, pollWaitCanceled and runtime·netpollready (IO re diness notification) 43 // pollReset, pollWait, pollWaitCanceled and runtime·netpollready (IO re diness notification)
49 // proceed w/o taking the lock. So closing, rg, rd, wg and wd are manipu lated 44 // proceed w/o taking the lock. So closing, rg, rd, wg and wd are manipu lated
50 // in a lock-free way by all operations. 45 // in a lock-free way by all operations.
51 Lock; // protectes the following fields 46 Lock; // protectes the following fields
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 415 }
421 416
422 static PollDesc* 417 static PollDesc*
423 allocPollDesc(void) 418 allocPollDesc(void)
424 { 419 {
425 PollDesc *pd; 420 PollDesc *pd;
426 uint32 i, n; 421 uint32 i, n;
427 422
428 runtime·lock(&pollcache); 423 runtime·lock(&pollcache);
429 if(pollcache.first == nil) { 424 if(pollcache.first == nil) {
430 » » n = PollBlockSize/sizeof(*pd); 425 » » n = PageSize/sizeof(*pd);
431 if(n == 0) 426 if(n == 0)
432 n = 1; 427 n = 1;
433 // Must be in non-GC memory because can be referenced 428 // Must be in non-GC memory because can be referenced
434 // only from epoll/kqueue internals. 429 // only from epoll/kqueue internals.
435 pd = runtime·persistentalloc(n*sizeof(*pd), 0, &mstats.other_sys ); 430 pd = runtime·persistentalloc(n*sizeof(*pd), 0, &mstats.other_sys );
436 for(i = 0; i < n; i++) { 431 for(i = 0; i < n; i++) {
437 pd[i].link = pollcache.first; 432 pd[i].link = pollcache.first;
438 pollcache.first = &pd[i]; 433 pollcache.first = &pd[i];
439 } 434 }
440 } 435 }
441 pd = pollcache.first; 436 pd = pollcache.first;
442 pollcache.first = pd->link; 437 pollcache.first = pd->link;
443 runtime·unlock(&pollcache); 438 runtime·unlock(&pollcache);
444 return pd; 439 return pd;
445 } 440 }
OLDNEW
« no previous file with comments | « src/pkg/runtime/mgc0.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b