RTEMS 7.0-rc1
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
96/* Constants needed by aio_suspend() */
97
99#define AIO_SIGNALED 1
100
105typedef union
106{
108 struct sigevent *sigp;
109
112
114
118typedef struct
119{
120 pthread_mutex_t mutex;
121
124
127
130
131} listcb;
132
136typedef struct
137{
138 pthread_mutex_t mutex;
139
142
145
148
150
154typedef struct
155{
158
161
164
166 pthread_t caller_thread;
167
170
173
175 struct aiocb *aiocbp;
176
179
181
185typedef struct
186{
189
192
195
198
199 pthread_mutex_t mutex;
200 pthread_cond_t cond;
201
203
207typedef struct
208{
209 pthread_mutex_t mutex;
210 pthread_cond_t new_req;
211 pthread_attr_t attr;
212
215
218
220 unsigned int initialized;
221
224
227
229 atomic_int queued_requests;
230
232
233extern rtems_aio_queue aio_request_queue;
234
235#define AIO_QUEUE_INITIALIZED 0xB00B
236
237#ifndef AIO_MAX_THREADS
238#define AIO_MAX_THREADS 5
239#endif
240
241#ifndef AIO_LISTIO_MAX
242#define AIO_LISTIO_MAX 20
243#endif
244
245#ifndef RTEMS_AIO_MAX
246#define RTEMS_AIO_MAX 100
247#endif
248
255int rtems_aio_init( void );
256
265
280 rtems_chain_control *chain,
281 int fildes,
282 int create
283);
284
291
302 rtems_chain_control *chain,
303 struct aiocb *aiocbp
304);
305
315int rtems_aio_check_sigevent( struct sigevent *sigp );
316
325rtems_aio_request *init_write_req( struct aiocb* aiocbp );
326
335rtems_aio_request *init_read_req( struct aiocb* aiocbp );
336
342void rtems_aio_completed_list_op( listcb *listcbp );
343
350
359 const struct aiocb* aiocbp,
360 rtems_chain_control *fd_chain
361);
362
363#ifdef RTEMS_DEBUG
364#include <assert.h>
365
366#define AIO_assert(_x) assert(_x)
367#define AIO_printf(_x) printf(_x)
368#else
369#define AIO_assert(_x)
370#define AIO_printf(_x)
371#endif
372
373#ifdef __cplusplus
374}
375#endif
376
377#endif
378
POSIX Asynchronous I/O Support.
rtems_aio_request * rtems_aio_search_in_chain(const struct aiocb *aiocbp, rtems_chain_control *fd_chain)
Search a request in an fd chain.
Definition: aio_misc.c:875
void rtems_aio_remove_fd(rtems_aio_request_chain *r_chain)
Removes all the requests in a FD chain.
Definition: aio_misc.c:423
void rtems_aio_update_suspendcbp(rtems_aio_suspendcb *suspendcbp)
updates suspendcb after related op completion
Definition: aio_misc.c:288
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:325
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:569
int rtems_aio_remove_req(rtems_chain_control *chain, struct aiocb *aiocbp)
Remove request from given chain.
Definition: aio_misc.c:442
int rtems_aio_enqueue(rtems_aio_request *req)
Enqueue requests, and creates threads to process them.
Definition: aio_misc.c:465
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:211
void rtems_aio_completed_list_op(listcb *listcbp)
updates listcb after op completion
Definition: aio_misc.c:259
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:119
lio_notification_union lio_notification
event to do at list completion
Definition: aio_misc.h:129
int requests_left
number of requests left to complete the list
Definition: aio_misc.h:123
int notification_type
type of notification
Definition: aio_misc.h:126
Definition: mutex.h:4
The queue of all the requests in progress and waiting to be processed.
Definition: aio_misc.h:208
int idle_threads
The number of idle threads.
Definition: aio_misc.h:226
rtems_chain_control work_req
Chains being worked by active threads.
Definition: aio_misc.h:214
int active_threads
The number of active threads.
Definition: aio_misc.h:223
rtems_chain_control idle_req
Chains waiting to be processed.
Definition: aio_misc.h:217
atomic_int queued_requests
The number of queued requests.
Definition: aio_misc.h:229
unsigned int initialized
Specific value if queue is initialized.
Definition: aio_misc.h:220
A chain of requests for the same FD.
Definition: aio_misc.h:186
rtems_chain_control perfd
Chain of requests for this fd.
Definition: aio_misc.h:191
rtems_chain_node next_fd
Order fd chains in queue.
Definition: aio_misc.h:188
int new_fd
Indicates if this is a newly created chain.
Definition: aio_misc.h:197
int fildes
File descriptor to be processed.
Definition: aio_misc.h:194
The request being processed.
Definition: aio_misc.h:155
rtems_chain_node next_prio
Chain requests in order of priority.
Definition: aio_misc.h:157
listcb * listcbp
pointer to list control block
Definition: aio_misc.h:169
int op_type
Operation type.
Definition: aio_misc.h:178
rtems_aio_suspendcb * suspendcbp
pointer to suspend control block
Definition: aio_misc.h:172
int priority
see above
Definition: aio_misc.h:163
int policy
If _POSIX_PRIORITIZED_IO and _POSIX_PRIORITY_SCHEDULING are defined.
Definition: aio_misc.h:160
struct aiocb * aiocbp
Aio control block.
Definition: aio_misc.h:175
pthread_t caller_thread
Used for notification.
Definition: aio_misc.h:166
Control block for every list involved in a aio_suspend() call.
Definition: aio_misc.h:137
int task_id
id of the thread that called aio_suspend()
Definition: aio_misc.h:144
int requests_left
number of requests left to complete the list
Definition: aio_misc.h:141
int notified
controls if the notification already happend
Definition: aio_misc.h:147
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:106
int task_id
id of the thread that called lio_listio()
Definition: aio_misc.h:111
struct sigevent * sigp
pointer to the sigevent for notification
Definition: aio_misc.h:108