Fix PR47707
[official-gcc.git] / libgo / runtime / go-rec-big.c
blob23d65296aa97ff3c5175ddc62fc17e361e15df8e
1 /* go-rec-big.c -- receive something larger than 64 bits 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 "go-panic.h"
10 #include "channel.h"
12 void
13 __go_receive_big (struct __go_channel *channel, void *val, _Bool for_select)
15 size_t alloc_size;
16 size_t offset;
18 if (channel == NULL)
19 __go_panic_msg ("receive from nil channel");
21 alloc_size = ((channel->element_size + sizeof (uint64_t) - 1)
22 / sizeof (uint64_t));
24 if (!__go_receive_acquire (channel, for_select))
26 __builtin_memset (val, 0, channel->element_size);
27 return;
30 offset = channel->next_fetch * alloc_size;
31 __builtin_memcpy (val, &channel->data[offset], channel->element_size);
33 __go_receive_release (channel);