RTEMS 6.1-rc2
Loading...
Searching...
No Matches
aio_misc.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com>
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _AIO_MISC_H
37#define _AIO_MISC_H
38
39#include <stdio.h>
40#include <string.h>
41#include <aio.h>
42#include <pthread.h>
43#include <rtems.h>
44#include <rtems/chain.h>
45#include <rtems/seterr.h>
46
47#ifdef __cplusplus
48extern "C"
49{
50#endif
51
52 /* Actual request being processed */
53 typedef struct
54 {
55 rtems_chain_node next_prio; /* chain requests in order of priority */
56 int policy; /* If _POSIX_PRIORITIZED_IO and
57 _POSIX_PRIORITY_SCHEDULING are defined */
58 int priority; /* see above */
59 pthread_t caller_thread; /* used for notification */
60 struct aiocb *aiocbp; /* aio control block */
62
63 typedef struct
64 {
65 rtems_chain_node next_fd; /* order fd chains in queue */
66 rtems_chain_control perfd; /* chain of requests for this fd */
67 int fildes; /* file descriptor to be processed */
68 int new_fd; /* if this is a newly created chain */
69 pthread_mutex_t mutex;
70 pthread_cond_t cond;
71
73
74 typedef struct
75 {
76 pthread_mutex_t mutex;
77 pthread_cond_t new_req;
78 pthread_attr_t attr;
79
80 rtems_chain_control work_req; /* chains being worked by active threads */
81 rtems_chain_control idle_req; /* fd chains waiting to be processed */
82 unsigned int initialized; /* specific value if queue is initialized */
83 int active_threads; /* the number of active threads */
84 int idle_threads; /* number of idle threads */
85
87
88extern rtems_aio_queue aio_request_queue;
89
90#define AIO_QUEUE_INITIALIZED 0xB00B
91
92#ifndef AIO_MAX_THREADS
93#define AIO_MAX_THREADS 5
94#endif
95
96#ifndef AIO_MAX_QUEUE_SIZE
97#define AIO_MAX_QUEUE_SIZE 30
98#endif
99
100int rtems_aio_init (void);
101int rtems_aio_enqueue (rtems_aio_request *req);
102rtems_aio_request_chain *rtems_aio_search_fd
103(
104 rtems_chain_control *chain,
105 int fildes,
106 int create
107);
108void rtems_aio_remove_fd (rtems_aio_request_chain *r_chain);
109int rtems_aio_remove_req (rtems_chain_control *chain,
110 struct aiocb *aiocbp);
111
112#ifdef RTEMS_DEBUG
113#include <assert.h>
114
115#define AIO_assert(_x) assert(_x)
116#define AIO_printf(_x) printf(_x)
117#else
118#define AIO_assert(_x)
119#define AIO_printf(_x)
120#endif
121
122#define rtems_aio_set_errno_return_minus_one( _error, _aiocbp ) \
123 do { (_aiocbp)->error_code = (_error); \
124 (_aiocbp)->return_value = -1; \
125 rtems_set_errno_and_return_minus_one (_error);} while(0)
126
127#ifdef __cplusplus
128}
129#endif
130
131#endif
POSIX Asynchronous Input and Output.
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
Definition: mutex.h:4
Definition: aio_misc.h:75
Definition: aio_misc.h:64
Definition: aio_misc.h:54
This union represents a chain control block.
Definition: chain.h:96