diff options
author | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
---|---|---|
committer | Tianon Gravi <admwiggin@gmail.com> | 2015-01-15 11:54:00 -0700 |
commit | f154da9e12608589e8d5f0508f908a0c3e88a1bb (patch) | |
tree | f8255d51e10c6f1e0ed69702200b966c9556a431 /src/runtime/chan.h | |
parent | 8d8329ed5dfb9622c82a9fbec6fd99a580f9c9f6 (diff) | |
download | golang-upstream/1.4.tar.gz |
Imported Upstream version 1.4upstream/1.4
Diffstat (limited to 'src/runtime/chan.h')
-rw-r--r-- | src/runtime/chan.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/runtime/chan.h b/src/runtime/chan.h new file mode 100644 index 000000000..c34ff1533 --- /dev/null +++ b/src/runtime/chan.h @@ -0,0 +1,68 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#define MAXALIGN 8 + +typedef struct WaitQ WaitQ; +typedef struct Select Select; +typedef struct Scase Scase; + +struct WaitQ +{ + SudoG* first; + SudoG* last; +}; + +struct Hchan +{ + uintgo qcount; // total data in the q + uintgo dataqsiz; // size of the circular q + byte* buf; + uint16 elemsize; + uint32 closed; + Type* elemtype; // element type + uintgo sendx; // send index + uintgo recvx; // receive index + WaitQ recvq; // list of recv waiters + WaitQ sendq; // list of send waiters + Mutex lock; +}; + +// Buffer follows Hchan immediately in memory. +// chanbuf(c, i) is pointer to the i'th slot in the buffer. +#define chanbuf(c, i) ((byte*)((c)->buf)+(uintptr)(c)->elemsize*(i)) + +enum +{ + debug = 0, + + // Scase.kind + CaseRecv, + CaseSend, + CaseDefault, +}; + +// Known to compiler. +// Changes here must also be made in src/cmd/gc/select.c's selecttype. +struct Scase +{ + void* elem; // data element + Hchan* chan; // chan + uintptr pc; // return pc + uint16 kind; + uint16 so; // vararg of selected bool + bool* receivedp; // pointer to received bool (recv2) + int64 releasetime; +}; + +// Known to compiler. +// Changes here must also be made in src/cmd/gc/select.c's selecttype. +struct Select +{ + uint16 tcase; // total count of scase[] + uint16 ncase; // currently filled scase[] + uint16* pollorder; // case poll order + Hchan** lockorder; // channel lock order + Scase scase[1]; // one per case (in order of appearance) +}; |