RTEMS CPU Kit with SuperCore  4.10.99.0
rtems/posix/aio_misc.h
Go to the documentation of this file.
00001 
00009 /*
00010  * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com> 
00011  * 
00012  * The license and distribution terms for this file may be
00013  * found in the file LICENSE in this distribution or at
00014  * http://www.rtems.com/license/LICENSE.
00015  */
00016 
00017 #ifndef _AIO_MISC_H
00018 #define _AIO_MISC_H
00019 
00020 #include <stdio.h>
00021 #include <string.h>
00022 #include <aio.h>
00023 #include <pthread.h>
00024 #include <rtems.h>
00025 #include <rtems/chain.h>
00026 #include <rtems/system.h>
00027 #include <rtems/seterr.h>
00028   
00029 #ifdef __cplusplus
00030 extern "C"
00031 {
00032 #endif
00033 
00034   /* Actual request being processed */
00035   typedef struct
00036   {
00037     rtems_chain_node next_prio; /* chain requests in order of priority */
00038     int policy;                 /* If _POSIX_PRIORITIZED_IO and 
00039                                    _POSIX_PRIORITY_SCHEDULING are defined */ 
00040     int priority;               /* see above */
00041     pthread_t caller_thread;    /* used for notification */
00042     struct aiocb *aiocbp;       /* aio control block */
00043   } rtems_aio_request;
00044 
00045   typedef struct
00046   {
00047     rtems_chain_node next_fd;   /* order fd chains in queue */
00048     rtems_chain_control perfd;  /* chain of requests for this fd */
00049     int fildes;                 /* file descriptor to be processed */
00050     int new_fd;                 /* if this is a newly created chain */
00051     pthread_mutex_t mutex;      
00052     pthread_cond_t cond;
00053 
00054   } rtems_aio_request_chain;
00055 
00056   typedef struct
00057   {
00058     pthread_mutex_t mutex;
00059     pthread_cond_t new_req;
00060     pthread_attr_t attr;
00061 
00062     rtems_chain_control work_req; /* chains being worked by active threads */
00063     rtems_chain_control idle_req; /* fd chains waiting to be processed */
00064     unsigned int initialized;     /* specific value if queue is initialized */
00065     int active_threads;           /* the number of active threads */
00066     int idle_threads;             /* number of idle threads */
00067 
00068   } rtems_aio_queue;
00069 
00070 extern rtems_aio_queue aio_request_queue;
00071 
00072 #define AIO_QUEUE_INITIALIZED 0xB00B
00073 
00074 #ifndef AIO_MAX_THREADS
00075 #define AIO_MAX_THREADS 5
00076 #endif
00077 
00078 #ifndef AIO_MAX_QUEUE_SIZE
00079 #define AIO_MAX_QUEUE_SIZE 30
00080 #endif
00081 
00082 int rtems_aio_init (void);
00083 int rtems_aio_enqueue (rtems_aio_request *req);
00084 rtems_aio_request_chain *rtems_aio_search_fd 
00085 (
00086   rtems_chain_control *chain,
00087   int fildes,
00088   int create
00089 );
00090 void rtems_aio_remove_fd (rtems_aio_request_chain *r_chain);
00091 int rtems_aio_remove_req (rtems_chain_control *chain,
00092                                  struct aiocb *aiocbp);
00093 
00094 #ifdef RTEMS_DEBUG
00095 #include <assert.h>
00096 
00097 #define AIO_assert(_x) assert(_x)
00098 #define AIO_printf(_x) printf(_x)
00099 #else
00100 #define AIO_assert(_x)
00101 #define AIO_printf(_x)
00102 #endif
00103 
00104 #define rtems_aio_set_errno_return_minus_one( _error, _aiocbp ) \
00105   do { (_aiocbp)->error_code = (_error);                        \
00106     (_aiocbp)->return_value = -1;                               \
00107     rtems_set_errno_and_return_minus_one (_error);} while(0)
00108 
00109 #ifdef __cplusplus
00110 }
00111 #endif
00112 
00113 #endif