Blame sysdeps/nptl/aio_misc.h

Packit Service 82fcde
/* Copyright (C) 2006-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
/* We define a special synchronization primitive for AIO.  POSIX
Packit Service 82fcde
   conditional variables would be ideal but the pthread_cond_*wait
Packit Service 82fcde
   operations do not return on EINTR.  This is a requirement for
Packit Service 82fcde
   correct aio_suspend and lio_listio implementations.  */
Packit Service 82fcde
Packit Service 82fcde
#include <assert.h>
Packit Service 82fcde
#include <nptl/pthreadP.h>
Packit Service 82fcde
#include <futex-internal.h>
Packit Service 82fcde
Packit Service 82fcde
#define DONT_NEED_AIO_MISC_COND	1
Packit Service 82fcde
Packit Service 82fcde
#define AIO_MISC_NOTIFY(waitlist) \
Packit Service 82fcde
  do {									      \
Packit Service 82fcde
    if (*waitlist->counterp > 0 && --*waitlist->counterp == 0)		      \
Packit Service 82fcde
      futex_wake ((unsigned int *) waitlist->counterp, 1, FUTEX_PRIVATE);     \
Packit Service 82fcde
  } while (0)
Packit Service 82fcde
Packit Service 82fcde
#define AIO_MISC_WAIT(result, futex, timeout, cancel)			      \
Packit Service 82fcde
  do {									      \
Packit Service 82fcde
    volatile unsigned int *futexaddr = &futex;				      \
Packit Service 82fcde
    unsigned int oldval = futex;					      \
Packit Service 82fcde
									      \
Packit Service 82fcde
    if (oldval != 0)							      \
Packit Service 82fcde
      {									      \
Packit Service 82fcde
	pthread_mutex_unlock (&__aio_requests_mutex);			      \
Packit Service 82fcde
									      \
Packit Service 82fcde
	int oldtype;							      \
Packit Service 82fcde
	if (cancel)							      \
Packit Service 82fcde
	  oldtype = LIBC_CANCEL_ASYNC ();				      \
Packit Service 82fcde
									      \
Packit Service 82fcde
	int status;							      \
Packit Service 82fcde
	do								      \
Packit Service 82fcde
	  {								      \
Packit Service 82fcde
	    status = futex_reltimed_wait ((unsigned int *) futexaddr, oldval, \
Packit Service 82fcde
					  timeout, FUTEX_PRIVATE);	      \
Packit Service 82fcde
	    if (status != EAGAIN)					      \
Packit Service 82fcde
	      break;							      \
Packit Service 82fcde
									      \
Packit Service 82fcde
	    oldval = *futexaddr;					      \
Packit Service 82fcde
	  }								      \
Packit Service 82fcde
	while (oldval != 0);						      \
Packit Service 82fcde
									      \
Packit Service 82fcde
	if (cancel)							      \
Packit Service 82fcde
	  LIBC_CANCEL_RESET (oldtype);					      \
Packit Service 82fcde
									      \
Packit Service 82fcde
	if (status == EINTR)						      \
Packit Service 82fcde
	  result = EINTR;						      \
Packit Service 82fcde
	else if (status == ETIMEDOUT)					      \
Packit Service 82fcde
	  result = EAGAIN;						      \
Packit Service 82fcde
	else								      \
Packit Service 82fcde
	  assert (status == 0 || status == EAGAIN);			      \
Packit Service 82fcde
									      \
Packit Service 82fcde
	pthread_mutex_lock (&__aio_requests_mutex);			      \
Packit Service 82fcde
      }									      \
Packit Service 82fcde
  } while (0)
Packit Service 82fcde
Packit Service 82fcde
#include_next <aio_misc.h>