Back to index

glibc  2.9
aio_misc.h
Go to the documentation of this file.
00001 /* Copyright (C) 1997,1999,2000,2001,2003,2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef _AIO_MISC_H
00020 #define _AIO_MISC_H  1
00021 
00022 #include <aio.h>
00023 #include <pthread.h>
00024 
00025 
00026 /* Extend the operation enum.  */
00027 enum
00028 {
00029   LIO_DSYNC = LIO_NOP + 1,
00030   LIO_SYNC,
00031   LIO_READ64 = LIO_READ | 128,
00032   LIO_WRITE64 = LIO_WRITE | 128
00033 };
00034 
00035 
00036 /* Union of the two request types.  */
00037 typedef union
00038   {
00039     struct aiocb aiocb;
00040     struct aiocb64 aiocb64;
00041   } aiocb_union;
00042 
00043 
00044 /* Used to synchronize.  */
00045 struct waitlist
00046   {
00047     struct waitlist *next;
00048 
00049     /* The next two fields is used in synchronous `lio_listio' operations.  */
00050 #ifndef DONT_NEED_AIO_MISC_COND
00051     pthread_cond_t *cond;
00052 #endif
00053     int *result;
00054 
00055     volatile int *counterp;
00056     /* The next field is used in asynchronous `lio_listio' operations.  */
00057     struct sigevent *sigevp;
00058 #ifdef BROKEN_THREAD_SIGNALS
00059     /* XXX See requestlist, it's used to work around the broken signal
00060        handling in Linux.  */
00061     pid_t caller_pid;
00062 #endif
00063   };
00064 
00065 
00066 /* Status of a request.  */
00067 enum
00068 {
00069   no,
00070   queued,
00071   yes,
00072   allocated,
00073   done
00074 };
00075 
00076 
00077 /* Used to queue requests..  */
00078 struct requestlist
00079   {
00080     int running;
00081 
00082     struct requestlist *last_fd;
00083     struct requestlist *next_fd;
00084     struct requestlist *next_prio;
00085     struct requestlist *next_run;
00086 
00087     /* Pointer to the actual data.  */
00088     aiocb_union *aiocbp;
00089 
00090 #ifdef BROKEN_THREAD_SIGNALS
00091     /* PID of the initiator thread.
00092        XXX This is only necessary for the broken signal handling on Linux.  */
00093     pid_t caller_pid;
00094 #endif
00095 
00096     /* List of waiting processes.  */
00097     struct waitlist *waiting;
00098   };
00099 
00100 
00101 /* Lock for global I/O list of requests.  */
00102 extern pthread_mutex_t __aio_requests_mutex attribute_hidden;
00103 
00104 
00105 /* Enqueue request.  */
00106 extern struct requestlist *__aio_enqueue_request (aiocb_union *aiocbp,
00107                                             int operation)
00108      attribute_hidden internal_function;
00109 
00110 /* Find request entry for given AIO control block.  */
00111 extern struct requestlist *__aio_find_req (aiocb_union *elem)
00112      attribute_hidden internal_function;
00113 
00114 /* Find request entry for given file descriptor.  */
00115 extern struct requestlist *__aio_find_req_fd (int fildes)
00116      attribute_hidden internal_function;
00117 
00118 /* Remove request from the list.  */
00119 extern void __aio_remove_request (struct requestlist *last,
00120                               struct requestlist *req, int all)
00121      attribute_hidden internal_function;
00122 
00123 /* Release the entry for the request.  */
00124 extern void __aio_free_request (struct requestlist *req)
00125      attribute_hidden internal_function;
00126 
00127 /* Notify initiator of request and tell this everybody listening.  */
00128 extern void __aio_notify (struct requestlist *req)
00129      attribute_hidden internal_function;
00130 
00131 /* Notify initiator of request.  */
00132 #ifdef BROKEN_THREAD_SIGNALS
00133 extern int __aio_notify_only (struct sigevent *sigev, pid_t caller_pid)
00134      attribute_hidden internal_function;
00135 #else
00136 extern int __aio_notify_only (struct sigevent *sigev)
00137      attribute_hidden internal_function;
00138 #endif
00139 
00140 /* Send the signal.  */
00141 extern int __aio_sigqueue (int sig, const union sigval val, pid_t caller_pid)
00142      attribute_hidden internal_function;
00143 
00144 #endif /* aio_misc.h */