gcc/libgo/runtime/chan.goc

34 lines
753 B
Plaintext
Raw Normal View History

// 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"
typedef _Bool bool;
typedef unsigned char byte;
typedef struct __go_channel chan;
/* Do a nonblocking channel receive. */
func chanrecv2(c *chan, val *byte) (received bool) {
if (c->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, c->element_size);
#else
__builtin_memcpy(val, u.b + 8 - c->element_size,
c->element_size);
#endif
return received;
}
}