Blame sysdeps/nptl/aio_misc.h

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