2010-12-03 05:34:57 +01:00
|
|
|
// 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;
|
|
|
|
|
2011-03-25 06:14:57 +01:00
|
|
|
/* Do a channel receive with closed status. */
|
2010-12-03 05:34:57 +01:00
|
|
|
|
2011-03-24 07:01:27 +01:00
|
|
|
func chanrecv2(c *chan, val *byte) (received bool) {
|
2011-05-20 02:18:15 +02:00
|
|
|
uintptr_t element_size = c->element_type->__size;
|
|
|
|
if (element_size > 8) {
|
2011-03-24 07:01:27 +01:00
|
|
|
return __go_receive_big(c, val, 0);
|
2010-12-03 05:34:57 +01:00
|
|
|
} else {
|
|
|
|
union {
|
|
|
|
char b[8];
|
|
|
|
uint64_t v;
|
|
|
|
} u;
|
|
|
|
|
2011-03-24 07:01:27 +01:00
|
|
|
u.v = __go_receive_small_closed(c, 0, &received);
|
2010-12-03 05:34:57 +01:00
|
|
|
#ifndef WORDS_BIGENDIAN
|
2011-05-20 02:18:15 +02:00
|
|
|
__builtin_memcpy(val, u.b, element_size);
|
2010-12-03 05:34:57 +01:00
|
|
|
#else
|
2011-05-20 02:18:15 +02:00
|
|
|
__builtin_memcpy(val, u.b + 8 - element_size, element_size);
|
2010-12-03 05:34:57 +01:00
|
|
|
#endif
|
2011-03-24 07:01:27 +01:00
|
|
|
return received;
|
2010-12-03 05:34:57 +01:00
|
|
|
}
|
|
|
|
}
|
2011-03-25 06:14:57 +01:00
|
|
|
|
|
|
|
/* Do a channel receive with closed status for a select statement. */
|
|
|
|
|
|
|
|
func chanrecv3(c *chan, val *byte) (received bool) {
|
2011-05-20 02:18:15 +02:00
|
|
|
uintptr_t element_size = c->element_type->__size;
|
|
|
|
if (element_size > 8) {
|
2011-03-25 06:14:57 +01:00
|
|
|
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
|
2011-05-20 02:18:15 +02:00
|
|
|
__builtin_memcpy(val, u.b, element_size);
|
2011-03-25 06:14:57 +01:00
|
|
|
#else
|
2011-05-20 02:18:15 +02:00
|
|
|
__builtin_memcpy(val, u.b + 8 - element_size, element_size);
|
2011-03-25 06:14:57 +01:00
|
|
|
#endif
|
|
|
|
return received;
|
|
|
|
}
|
|
|
|
}
|