OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 "type.h" | 6 #include "type.h" |
7 | 7 |
8 static int32 debug = 0; | 8 static int32 debug = 0; |
9 | 9 |
10 enum | 10 enum |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 Scase* scase[1]; // one per case | 79 Scase* scase[1]; // one per case |
80 }; | 80 }; |
81 | 81 |
82 static SudoG* dequeue(WaitQ*, Hchan*); | 82 static SudoG* dequeue(WaitQ*, Hchan*); |
83 static void enqueue(WaitQ*, SudoG*); | 83 static void enqueue(WaitQ*, SudoG*); |
84 static SudoG* allocsg(Hchan*); | 84 static SudoG* allocsg(Hchan*); |
85 static void freesg(Hchan*, SudoG*); | 85 static void freesg(Hchan*, SudoG*); |
86 static uint32 gcd(uint32, uint32); | 86 static uint32 gcd(uint32, uint32); |
87 static uint32 fastrand1(void); | 87 static uint32 fastrand1(void); |
88 static uint32 fastrand2(void); | 88 static uint32 fastrand2(void); |
| 89 static void destroychan(Hchan*); |
89 | 90 |
90 Hchan* | 91 Hchan* |
91 makechan(Type *elem, uint32 hint) | 92 makechan(Type *elem, uint32 hint) |
92 { | 93 { |
93 Hchan *c; | 94 Hchan *c; |
94 int32 i; | 95 int32 i; |
95 | 96 |
96 if(elem->alg >= nelem(algarray)) { | 97 if(elem->alg >= nelem(algarray)) { |
97 printf("chan(alg=%d)\n", elem->alg); | 98 printf("chan(alg=%d)\n", elem->alg); |
98 throw("runtime.makechan: unsupported elem type"); | 99 throw("runtime.makechan: unsupported elem type"); |
99 } | 100 } |
100 | 101 |
101 c = mal(sizeof(*c)); | 102 c = mal(sizeof(*c)); |
| 103 addfinalizer(c, destroychan, 0); |
102 | 104 |
103 c->elemsize = elem->size; | 105 c->elemsize = elem->size; |
104 c->elemalg = &algarray[elem->alg]; | 106 c->elemalg = &algarray[elem->alg]; |
105 c->elemalign = elem->align; | 107 c->elemalign = elem->align; |
106 | 108 |
107 if(hint > 0) { | 109 if(hint > 0) { |
108 Link *d, *b, *e; | 110 Link *d, *b, *e; |
109 | 111 |
110 // make a circular q | 112 // make a circular q |
111 b = nil; | 113 b = nil; |
(...skipping 22 matching lines...) Expand all Loading... |
134 prints("; elemalign="); | 136 prints("; elemalign="); |
135 ·printint(elem->align); | 137 ·printint(elem->align); |
136 prints("; dataqsiz="); | 138 prints("; dataqsiz="); |
137 ·printint(c->dataqsiz); | 139 ·printint(c->dataqsiz); |
138 prints("\n"); | 140 prints("\n"); |
139 } | 141 } |
140 | 142 |
141 return c; | 143 return c; |
142 } | 144 } |
143 | 145 |
| 146 static void |
| 147 destroychan(Hchan *c) |
| 148 { |
| 149 destroylock(&c->Lock); |
| 150 } |
| 151 |
| 152 |
144 // makechan(elemsize uint32, elemalg uint32, hint uint32) (hchan *chan any); | 153 // makechan(elemsize uint32, elemalg uint32, hint uint32) (hchan *chan any); |
145 void | 154 void |
146 ·makechan(Type *elem, uint32 hint, Hchan *ret) | 155 ·makechan(Type *elem, uint32 hint, Hchan *ret) |
147 { | 156 { |
148 ret = makechan(elem, hint); | 157 ret = makechan(elem, hint); |
149 FLUSH(&ret); | 158 FLUSH(&ret); |
150 } | 159 } |
151 | 160 |
152 static void | 161 static void |
153 incerr(Hchan* c) | 162 incerr(Hchan* c) |
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 static uint32 | 1085 static uint32 |
1077 fastrand2(void) | 1086 fastrand2(void) |
1078 { | 1087 { |
1079 static uint32 x = 0x49f6428aUL; | 1088 static uint32 x = 0x49f6428aUL; |
1080 | 1089 |
1081 x += x; | 1090 x += x; |
1082 if(x & 0x80000000L) | 1091 if(x & 0x80000000L) |
1083 x ^= 0xfafd871bUL; | 1092 x ^= 0xfafd871bUL; |
1084 return x; | 1093 return x; |
1085 } | 1094 } |
OLD | NEW |