Fix PR47707
[official-gcc.git] / libgo / runtime / go-close.c
blobced742985f6e0b93c8b1fd01edb3a51acfee1859
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 "channel.h"
10 /* Close a channel. After a channel is closed, sends are no longer
11 permitted. Receives always return zero. */
13 void
14 __go_builtin_close (struct __go_channel *channel)
16 int i;
18 i = pthread_mutex_lock (&channel->lock);
19 __go_assert (i == 0);
21 while (channel->selected_for_send)
23 i = pthread_cond_wait (&channel->cond, &channel->lock);
24 __go_assert (i == 0);
27 channel->is_closed = 1;
29 i = pthread_cond_broadcast (&channel->cond);
30 __go_assert (i == 0);
32 __go_unlock_and_notify_selects (channel);