OSDN Git Service

PR go/47910
[pf3gnuchains/gcc-fork.git] / libgo / runtime / go-closed.c
1 /* go-closed.c -- the builtin closed function.
2
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.  */
6
7 #include "go-assert.h"
8 #include "channel.h"
9
10 /* Return whether a channel is closed.  We only return true after at
11    least one nil value has been read from the channel.  */
12
13 _Bool
14 __go_builtin_closed (struct __go_channel *channel)
15 {
16   int i;
17   _Bool ret;
18
19   i = pthread_mutex_lock (&channel->lock);
20   __go_assert (i == 0);
21
22   while (channel->selected_for_receive)
23     {
24       i = pthread_cond_wait (&channel->cond, &channel->lock);
25       __go_assert (i == 0);
26     }
27
28   ret = channel->saw_close;
29
30   i = pthread_mutex_unlock (&channel->lock);
31   __go_assert (i == 0);
32
33   return ret;
34 }