RTEMS 6.1-rc6
Loading...
Searching...
No Matches
aio_misc.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
13/*
14 * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com>
15 *
16 * COPYRIGHT (c) 1989-2011.
17 * On-Line Applications Research Corporation (OAR).
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
21 * are met:
22 * 1. Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 * 2. Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifndef _AIO_MISC_H
42#define _AIO_MISC_H
43
44#include <string.h>
45#include <signal.h>
46#include <aio.h>
47#include <pthread.h>
48#include <stdatomic.h>
49#include <rtems.h>
50#include <rtems/chain.h>
51#include <rtems/seterr.h>
52
53#ifdef RTEMS_DEBUG
54#include <stdio.h>
55#endif
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
64#define AIO_OP_READ 0
65
67#define AIO_OP_WRITE 1
68
70#define AIO_OP_SYNC 2
71
73#define AIO_OP_DSYNC 3
74
75/*
76 * Constants to track return status
77 */
78
80#define AIO_RETURNED 0
81
83#define AIO_NOTRETURNED 1
84
88#define AIO_LIO_NO_NOTIFY 0
89
91#define AIO_LIO_SIGEV 1
92
94#define AIO_LIO_EVENT 2
95
100typedef union
101{
103 struct sigevent *sigp;
104
107
109
113typedef struct
114{
115 pthread_mutex_t mutex;
116
119
122
125
126} listcb;
127
131typedef struct
132{
135
138
141
143 pthread_t caller_thread;
144
147
149 struct aiocb *aiocbp;
150
153
155
159typedef struct
160{
163
166
169
172
173 pthread_mutex_t mutex;
174 pthread_cond_t cond;
175
177
181typedef struct
182{
183 pthread_mutex_t mutex;
184 pthread_cond_t new_req;
185 pthread_attr_t attr;
186
189
192
194 unsigned int initialized;
195
198
201
203 atomic_int queued_requests;
204
206
207extern rtems_aio_queue aio_request_queue;
208
209#define AIO_QUEUE_INITIALIZED 0xB00B
210
211#ifndef AIO_MAX_THREADS
212#define AIO_MAX_THREADS 5
213#endif
214
215#ifndef AIO_LISTIO_MAX
216#define AIO_LISTIO_MAX 20
217#endif
218
219#ifndef RTEMS_AIO_MAX
220#define RTEMS_AIO_MAX 100
221#endif
222
229int rtems_aio_init( void );
230
239
254 rtems_chain_control *chain,
255 int fildes,
256 int create
257);
258
265
276 rtems_chain_control *chain,
277 struct aiocb *aiocbp
278);
279
289int rtems_aio_check_sigevent( struct sigevent *sigp );
290
299rtems_aio_request *init_write_req( struct aiocb* aiocbp );
300
309rtems_aio_request *init_read_req( struct aiocb* aiocbp );
310
316void rtems_aio_completed_list_op( listcb *listcbp );
317
318#ifdef RTEMS_DEBUG
319#include <assert.h>
320
321#define AIO_assert(_x) assert(_x)
322#define AIO_printf(_x) printf(_x)
323#else
324#define AIO_assert(_x)
325#define AIO_printf(_x)
326#endif
327
328#ifdef __cplusplus
329}
330#endif
331
332#endif
333
POSIX Asynchronous I/O Support.
void rtems_aio_remove_fd(rtems_aio_request_chain *r_chain)
Removes all the requests in a FD chain.
Definition: aio_misc.c:373
rtems_aio_request_chain * rtems_aio_search_fd(rtems_chain_control *chain, int fildes, int create)
Search for and create a chain of requests for a given file descriptor.
Definition: aio_misc.c:285
int rtems_aio_init(void)
Initialize the request queue for AIO Operations.
Definition: aio_misc.c:116
int rtems_aio_check_sigevent(struct sigevent *sigp)
Checks the validity of a sigevent struct.
Definition: aio_misc.c:525
int rtems_aio_remove_req(rtems_chain_control *chain, struct aiocb *aiocbp)
Remove request from given chain.
Definition: aio_misc.c:392
int rtems_aio_enqueue(rtems_aio_request *req)
Enqueue requests, and creates threads to process them.
Definition: aio_misc.c:421
rtems_aio_request * init_write_req(struct aiocb *aiocbp)
initializes a read rtems_aio_request
Definition: aio_misc.c:163
rtems_aio_request * init_read_req(struct aiocb *aiocbp)
initializes a write rtems_aio_request
Definition: aio_misc.c:210
void rtems_aio_completed_list_op(listcb *listcbp)
updates listcb after op completion
Definition: aio_misc.c:257
This header file provides the interfaces of the Assert Handler.
This header file provides the Chains API.
POSIX Threads Private Support.
This header file defines the RTEMS Classic API.
This header file defines macros to set errno and return minus one.
This structure represents a chain node.
Definition: chain.h:78
Control block for every list enqueued with lio_listio()
Definition: aio_misc.h:114
lio_notification_union lio_notification
event to do at list completion
Definition: aio_misc.h:124
int requests_left
number of requests left to complete the list
Definition: aio_misc.h:118
int notification_type
type of notification
Definition: aio_misc.h:121
Definition: mutex.h:4
The queue of all the requests in progress and waiting to be processed.
Definition: aio_misc.h:182
int idle_threads
The number of idle threads.
Definition: aio_misc.h:200
rtems_chain_control work_req
Chains being worked by active threads.
Definition: aio_misc.h:188
int active_threads
The number of active threads.
Definition: aio_misc.h:197
rtems_chain_control idle_req
Chains waiting to be processed.
Definition: aio_misc.h:191
atomic_int queued_requests
The number of queued requests.
Definition: aio_misc.h:203
unsigned int initialized
Specific value if queue is initialized.
Definition: aio_misc.h:194
A chain of requests for the same FD.
Definition: aio_misc.h:160
rtems_chain_control perfd
Chain of requests for this fd.
Definition: aio_misc.h:165
rtems_chain_node next_fd
Order fd chains in queue.
Definition: aio_misc.h:162
int new_fd
Indicates if this is a newly created chain.
Definition: aio_misc.h:171
int fildes
File descriptor to be processed.
Definition: aio_misc.h:168
The request being processed.
Definition: aio_misc.h:132
rtems_chain_node next_prio
Chain requests in order of priority.
Definition: aio_misc.h:134
listcb * listcbp
pointer to list control block
Definition: aio_misc.h:146
int op_type
Operation type.
Definition: aio_misc.h:152
int priority
see above
Definition: aio_misc.h:140
int policy
If _POSIX_PRIORITIZED_IO and _POSIX_PRIORITY_SCHEDULING are defined.
Definition: aio_misc.h:137
struct aiocb * aiocbp
Aio control block.
Definition: aio_misc.h:149
pthread_t caller_thread
Used for notification.
Definition: aio_misc.h:143
This union represents a chain control block.
Definition: chain.h:96
holds a pointer to a sigevent struct or a thread id
Definition: aio_misc.h:101
int task_id
id of the thread that called lio_listio()
Definition: aio_misc.h:106
struct sigevent * sigp
pointer to the sigevent for notification
Definition: aio_misc.h:103