diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libgo/runtime/go-new-channel.c | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libgo/runtime/go-new-channel.c')
-rw-r--r-- | libgo/runtime/go-new-channel.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/libgo/runtime/go-new-channel.c b/libgo/runtime/go-new-channel.c new file mode 100644 index 000000000..d57f52c6c --- /dev/null +++ b/libgo/runtime/go-new-channel.c @@ -0,0 +1,57 @@ +/* go-new-channel.c -- allocate a new channel. + + Copyright 2009 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. */ + +#include <stddef.h> + +#include "go-alloc.h" +#include "go-assert.h" +#include "go-panic.h" +#include "channel.h" + +struct __go_channel* +__go_new_channel (size_t element_size, size_t entries) +{ + struct __go_channel* ret; + size_t alloc_size; + int i; + + if ((size_t) (int) entries != entries || entries > (size_t) -1 / element_size) + __go_panic_msg ("chan size out of range"); + + alloc_size = (element_size + sizeof (uint64_t) - 1) / sizeof (uint64_t); + + /* We use a circular buffer which means that when next_fetch == + next_store we don't know whether the buffer is empty or full. So + we allocate an extra space, and always leave a space open. + FIXME. */ + if (entries != 0) + ++entries; + + ret = (struct __go_channel*) __go_alloc (sizeof (struct __go_channel) + + ((entries == 0 ? 1 : entries) + * alloc_size + * sizeof (uint64_t))); + i = pthread_mutex_init (&ret->lock, NULL); + __go_assert (i == 0); + i = pthread_cond_init (&ret->cond, NULL); + __go_assert (i == 0); + ret->element_size = element_size; + ret->closed_op_count = 0; + ret->waiting_to_send = 0; + ret->waiting_to_receive = 0; + ret->selected_for_send = 0; + ret->selected_for_receive = 0; + ret->is_closed = 0; + ret->saw_close = 0; + ret->select_send_queue = NULL; + ret->select_receive_queue = NULL; + ret->select_mutex = NULL; + ret->select_cond = NULL; + ret->num_entries = entries; + ret->next_store = 0; + ret->next_fetch = 0; + return ret; +} |