1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright 2010 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.
package runtime
#include "config.h"
#include "channel.h"
#define nil NULL
typedef _Bool bool;
typedef unsigned char byte;
typedef struct __go_channel chan;
/* Do a channel receive with closed status. */
func chanrecv2(c *chan, val *byte) (received bool) {
uintptr_t element_size = c == nil ? 0 : c->element_type->__size;
if (element_size > 8) {
return __go_receive_big(c, val, 0);
} else {
union {
char b[8];
uint64_t v;
} u;
u.v = __go_receive_small_closed(c, 0, &received);
#ifndef WORDS_BIGENDIAN
__builtin_memcpy(val, u.b, element_size);
#else
__builtin_memcpy(val, u.b + 8 - element_size, element_size);
#endif
return received;
}
}
/* Do a channel receive with closed status for a select statement. */
func chanrecv3(c *chan, val *byte) (received bool) {
uintptr_t element_size = c->element_type->__size;
if (element_size > 8) {
return __go_receive_big(c, val, 1);
} else {
union {
char b[8];
uint64_t v;
} u;
u.v = __go_receive_small_closed(c, 1, &received);
#ifndef WORDS_BIGENDIAN
__builtin_memcpy(val, u.b, element_size);
#else
__builtin_memcpy(val, u.b + 8 - element_size, element_size);
#endif
return received;
}
}
|