예제 #1
0
void
chanrecv (unsigned char *ch, unsigned char *val, _Bool *selected,
	  _Bool *received)
{
  struct __go_channel *channel = (struct __go_channel *) ch;

  if (channel->element_size <= sizeof (uint64_t))
    {
      union
      {
	char b[sizeof (uint64_t)];
	uint64_t v;
      } u;

      if (selected == NULL)
	u.v = __go_receive_small_closed (channel, 0, received);
      else
	{
	  struct __go_receive_nonblocking_small s;

	  s = __go_receive_nonblocking_small (channel);
	  *selected = s.__success || s.__closed;
	  if (received != NULL)
	    *received = s.__success;
	  u.v = s.__val;
	}

#ifndef WORDS_BIGENDIAN
      __builtin_memcpy (val, u.b, channel->element_size);
#else
      __builtin_memcpy (val, u.b + sizeof (uint64_t) - channel->element_size,
			channel->element_size);
#endif
    }
  else
    {
      if (selected == NULL)
	{
	  _Bool success;

	  success = __go_receive_big (channel, val, 0);
	  if (received != NULL)
	    *received = success;
	}
      else
	{
	  _Bool got;
	  _Bool closed;

	  got = __go_receive_nonblocking_big (channel, val, &closed);
	  *selected = got || closed;
	  if (received != NULL)
	    *received = got;
	}
    }
}
void
chanrecv (unsigned char *ch, unsigned char *val, _Bool *pres)
{
  struct __go_channel *channel = (struct __go_channel *) ch;

  if (channel->element_size <= sizeof (uint64_t))
    {
      union
      {
	char b[sizeof (uint64_t)];
	uint64_t v;
      } u;

      if (pres == NULL)
	u.v = __go_receive_small (channel, 0);
      else
	{
	  struct __go_receive_nonblocking_small s;

	  s = __go_receive_nonblocking_small (channel);
	  *pres = s.__success;
	  if (!s.__success)
	    return;
	  u.v = s.__val;
	}

#ifndef WORDS_BIGENDIAN
      __builtin_memcpy (val, u.b, channel->element_size);
#else
      __builtin_memcpy (val, u.b + sizeof (uint64_t) - channel->element_size,
			channel->element_size);
#endif
    }
  else
    {
      if (pres == NULL)
	__go_receive_big (channel, val, 0);
      else
	*pres = __go_receive_nonblocking_big (channel, val);
    }
}