RTEMS CPU Kit with SuperCore  4.11.3
aio_misc.h
Go to the documentation of this file.
1 
9 /*
10  * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com>
11  *
12  * The license and distribution terms for this file may be
13  * found in the file LICENSE in this distribution or at
14  * http://www.rtems.org/license/LICENSE.
15  */
16 
17 #ifndef _AIO_MISC_H
18 #define _AIO_MISC_H
19 
20 #include <stdio.h>
21 #include <string.h>
22 #include <aio.h>
23 #include <pthread.h>
24 #include <rtems.h>
25 #include <rtems/chain.h>
26 #include <rtems/system.h>
27 #include <rtems/seterr.h>
28 
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33 
34  /* Actual request being processed */
35  typedef struct
36  {
37  rtems_chain_node next_prio; /* chain requests in order of priority */
38  int policy; /* If _POSIX_PRIORITIZED_IO and
39  _POSIX_PRIORITY_SCHEDULING are defined */
40  int priority; /* see above */
41  pthread_t caller_thread; /* used for notification */
42  struct aiocb *aiocbp; /* aio control block */
44 
45  typedef struct
46  {
47  rtems_chain_node next_fd; /* order fd chains in queue */
48  rtems_chain_control perfd; /* chain of requests for this fd */
49  int fildes; /* file descriptor to be processed */
50  int new_fd; /* if this is a newly created chain */
51  pthread_mutex_t mutex;
52  pthread_cond_t cond;
53 
55 
56  typedef struct
57  {
58  pthread_mutex_t mutex;
59  pthread_cond_t new_req;
60  pthread_attr_t attr;
61 
62  rtems_chain_control work_req; /* chains being worked by active threads */
63  rtems_chain_control idle_req; /* fd chains waiting to be processed */
64  unsigned int initialized; /* specific value if queue is initialized */
65  int active_threads; /* the number of active threads */
66  int idle_threads; /* number of idle threads */
67 
69 
70 extern rtems_aio_queue aio_request_queue;
71 
72 #define AIO_QUEUE_INITIALIZED 0xB00B
73 
74 #ifndef AIO_MAX_THREADS
75 #define AIO_MAX_THREADS 5
76 #endif
77 
78 #ifndef AIO_MAX_QUEUE_SIZE
79 #define AIO_MAX_QUEUE_SIZE 30
80 #endif
81 
82 int rtems_aio_init (void);
83 int rtems_aio_enqueue (rtems_aio_request *req);
84 rtems_aio_request_chain *rtems_aio_search_fd
85 (
86  rtems_chain_control *chain,
87  int fildes,
88  int create
89 );
90 void rtems_aio_remove_fd (rtems_aio_request_chain *r_chain);
91 int rtems_aio_remove_req (rtems_chain_control *chain,
92  struct aiocb *aiocbp);
93 
94 #ifdef RTEMS_DEBUG
95 #include <assert.h>
96 
97 #define AIO_assert(_x) assert(_x)
98 #define AIO_printf(_x) printf(_x)
99 #else
100 #define AIO_assert(_x)
101 #define AIO_printf(_x)
102 #endif
103 
104 #define rtems_aio_set_errno_return_minus_one( _error, _aiocbp ) \
105  do { (_aiocbp)->error_code = (_error); \
106  (_aiocbp)->return_value = -1; \
107  rtems_set_errno_and_return_minus_one (_error);} while(0)
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif
This is used to manage each element (node) which is placed on a chain.
Definition: chain.h:65
Data which Ease the Burden of Consistently Setting Errno.
This is used to manage a chain.
Definition: chain.h:83
POSIX Threads Private Support.
Definition: aio_misc.h:56
Definition: aio_misc.h:35
Information Included in Every Function in the Executive.
Definition: aio_misc.h:45
Chain API.
POSIX Asynchronous Input and Output.
Definition: mutex.h:5