PR debug/47106
[official-gcc.git] / libgo / runtime / chan.goc
blobda0bbfccb101a7f2f1b0cac475222619afcfc5cb
1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package runtime
6 #include "config.h"
7 #include "channel.h"
9 typedef _Bool bool;
10 typedef unsigned char byte;
11 typedef struct __go_channel chan;
13 /* Do a nonblocking channel receive.  */
15 func chanrecv2(c *chan, val *byte) (pres bool) {
16         if (c->element_size > 8) {
17                 return __go_receive_nonblocking_big(c, val);
18         } else {
19                 struct __go_receive_nonblocking_small rs;
20                 union {
21                         char b[8];
22                         uint64_t v;
23                 } u;
25                 rs = __go_receive_nonblocking_small (c);
26                 if (!rs.__success) {
27                         __builtin_memset(val, 0, c->element_size);
28                         return 0;
29                 }
30                 u.v = rs.__val;
31 #ifndef WORDS_BIGENDIAN
32                 __builtin_memcpy(val, u.b, c->element_size);
33 #else
34                 __builtin_memcpy(val, u.b + 8 - c->element_size,
35                                  c->element_size);
36 #endif
37                 return 1;
38         }