* g++.dg/pph/c120060625-1.cc: New.
[official-gcc.git] / libgo / runtime / go-rec-nb-big.c
blob8c315b19af73777767b497c5bd21121f1b8be174
1 /* go-rec-nb-big.c -- nonblocking receive of something big on a channel.
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 #include <stdint.h>
9 #include "channel.h"
11 /* Return true if a value was received, false if not. */
13 _Bool
14 __go_receive_nonblocking_big (struct __go_channel* channel, void *val,
15 _Bool *closed)
17 uintptr_t element_size;
18 size_t alloc_size;
19 size_t offset;
21 element_size = channel->element_type->__size;
22 alloc_size = (element_size + sizeof (uint64_t) - 1) / sizeof (uint64_t);
24 int data = __go_receive_nonblocking_acquire (channel);
25 if (data != RECEIVE_NONBLOCKING_ACQUIRE_DATA)
27 __builtin_memset (val, 0, element_size);
28 if (closed != NULL)
29 *closed = data == RECEIVE_NONBLOCKING_ACQUIRE_CLOSED;
30 return 0;
33 offset = channel->next_fetch * alloc_size;
34 __builtin_memcpy (val, &channel->data[offset], element_size);
36 __go_receive_release (channel);
38 return 1;