aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime/go-send-nb-small.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/runtime/go-send-nb-small.c')
-rw-r--r--libgo/runtime/go-send-nb-small.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/libgo/runtime/go-send-nb-small.c b/libgo/runtime/go-send-nb-small.c
index f23ae01..5c49a67 100644
--- a/libgo/runtime/go-send-nb-small.c
+++ b/libgo/runtime/go-send-nb-small.c
@@ -10,9 +10,11 @@
#include "go-panic.h"
#include "channel.h"
-/* Prepare to send something on a nonblocking channel. */
+/* Prepare to send something on a nonblocking channel. Return true if
+ we acquired the channel, false if we did not acquire it because
+ there is no space to send a value. */
-int
+_Bool
__go_send_nonblocking_acquire (struct __go_channel *channel)
{
int i;
@@ -29,16 +31,9 @@ __go_send_nonblocking_acquire (struct __go_channel *channel)
if (channel->is_closed)
{
- ++channel->closed_op_count;
- if (channel->closed_op_count >= MAX_CLOSED_OPERATIONS)
- {
- i = pthread_mutex_unlock (&channel->lock);
- __go_assert (i == 0);
- __go_panic_msg ("too many operations on closed channel");
- }
i = pthread_mutex_unlock (&channel->lock);
__go_assert (i == 0);
- return SEND_NONBLOCKING_ACQUIRE_CLOSED;
+ __go_panic_msg ("send on closed channel");
}
if (channel->num_entries > 0)
@@ -87,10 +82,10 @@ __go_send_nonblocking_acquire (struct __go_channel *channel)
i = pthread_mutex_unlock (&channel->lock);
__go_assert (i == 0);
- return SEND_NONBLOCKING_ACQUIRE_NOSPACE;
+ return 0;
}
- return SEND_NONBLOCKING_ACQUIRE_SPACE;
+ return 1;
}
/* Send something 64 bits or smaller on a channel. */
@@ -100,9 +95,8 @@ __go_send_nonblocking_small (struct __go_channel *channel, uint64_t val)
{
__go_assert (channel->element_size <= sizeof (uint64_t));
- int data = __go_send_nonblocking_acquire (channel);
- if (data != SEND_NONBLOCKING_ACQUIRE_SPACE)
- return data == SEND_NONBLOCKING_ACQUIRE_CLOSED;
+ if (!__go_send_nonblocking_acquire (channel))
+ return 0;
channel->data[channel->next_store] = val;