1 /* go-chan-len.c -- the len function applied to 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. */
12 /* Return the len function applied to a channel--the number of
13 elements in the buffer. This could be done inline but I'm doing it
14 as a function for now to make it easy to change the channel
18 __go_chan_len (struct __go_channel *channel)
26 i = pthread_mutex_lock (&channel->lock);
29 if (channel->num_entries == 0)
31 else if (channel->next_fetch == channel->next_store)
34 ret = ((channel->next_store + channel->num_entries - channel->next_fetch)
35 % channel->num_entries);
37 i = pthread_mutex_unlock (&channel->lock);