Update gcc/ChangeLog for r174861.
[official-gcc.git] / libgo / runtime / go-close.c
blob44533ebe4c7ff96439d80b97d5a0fcb3b6e6acaf
1 /* go-close.c -- the builtin close function.
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 "go-assert.h"
8 #include "go-panic.h"
9 #include "channel.h"
11 /* Close a channel. After a channel is closed, sends are no longer
12 permitted. Receives always return zero. */
14 void
15 __go_builtin_close (struct __go_channel *channel)
17 int i;
19 i = pthread_mutex_lock (&channel->lock);
20 __go_assert (i == 0);
22 while (channel->selected_for_send)
24 i = pthread_cond_wait (&channel->cond, &channel->lock);
25 __go_assert (i == 0);
28 if (channel->is_closed)
30 i = pthread_mutex_unlock (&channel->lock);
31 __go_assert (i == 0);
32 __go_panic_msg ("close of closed channel");
35 channel->is_closed = 1;
37 i = pthread_cond_broadcast (&channel->cond);
38 __go_assert (i == 0);
40 __go_unlock_and_notify_selects (channel);