xref: /aosp_15_r20/frameworks/av/media/mtp/PosixAsyncIO.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1*ec779b8eSAndroid Build Coastguard Worker /*
2*ec779b8eSAndroid Build Coastguard Worker  * Copyright (C) 2016 The Android Open Source Project
3*ec779b8eSAndroid Build Coastguard Worker  *
4*ec779b8eSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*ec779b8eSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*ec779b8eSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*ec779b8eSAndroid Build Coastguard Worker  *
8*ec779b8eSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*ec779b8eSAndroid Build Coastguard Worker  *
10*ec779b8eSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*ec779b8eSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*ec779b8eSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*ec779b8eSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*ec779b8eSAndroid Build Coastguard Worker  * limitations under the License.
15*ec779b8eSAndroid Build Coastguard Worker  */
16*ec779b8eSAndroid Build Coastguard Worker 
17*ec779b8eSAndroid Build Coastguard Worker #ifndef _POSIXASYNCIO_H
18*ec779b8eSAndroid Build Coastguard Worker #define _POSIXASYNCIO_H
19*ec779b8eSAndroid Build Coastguard Worker 
20*ec779b8eSAndroid Build Coastguard Worker #include <condition_variable>
21*ec779b8eSAndroid Build Coastguard Worker #include <mutex>
22*ec779b8eSAndroid Build Coastguard Worker #include <sys/cdefs.h>
23*ec779b8eSAndroid Build Coastguard Worker #include <sys/types.h>
24*ec779b8eSAndroid Build Coastguard Worker #include <time.h>
25*ec779b8eSAndroid Build Coastguard Worker #include <unistd.h>
26*ec779b8eSAndroid Build Coastguard Worker 
27*ec779b8eSAndroid Build Coastguard Worker /**
28*ec779b8eSAndroid Build Coastguard Worker  * Provides a subset of POSIX aio operations.
29*ec779b8eSAndroid Build Coastguard Worker  */
30*ec779b8eSAndroid Build Coastguard Worker 
31*ec779b8eSAndroid Build Coastguard Worker struct aiocb {
32*ec779b8eSAndroid Build Coastguard Worker     int aio_fildes;
33*ec779b8eSAndroid Build Coastguard Worker     void *aio_buf;
34*ec779b8eSAndroid Build Coastguard Worker 
35*ec779b8eSAndroid Build Coastguard Worker     off64_t aio_offset;
36*ec779b8eSAndroid Build Coastguard Worker     size_t aio_nbytes;
37*ec779b8eSAndroid Build Coastguard Worker 
38*ec779b8eSAndroid Build Coastguard Worker     // Used internally
39*ec779b8eSAndroid Build Coastguard Worker     bool read;
40*ec779b8eSAndroid Build Coastguard Worker     bool queued;
41*ec779b8eSAndroid Build Coastguard Worker     ssize_t ret;
42*ec779b8eSAndroid Build Coastguard Worker     int error;
43*ec779b8eSAndroid Build Coastguard Worker 
44*ec779b8eSAndroid Build Coastguard Worker     std::mutex lock;
45*ec779b8eSAndroid Build Coastguard Worker     std::condition_variable cv;
46*ec779b8eSAndroid Build Coastguard Worker 
47*ec779b8eSAndroid Build Coastguard Worker     aiocb();
48*ec779b8eSAndroid Build Coastguard Worker     ~aiocb();
49*ec779b8eSAndroid Build Coastguard Worker };
50*ec779b8eSAndroid Build Coastguard Worker 
51*ec779b8eSAndroid Build Coastguard Worker // Submit a request for IO to be completed
52*ec779b8eSAndroid Build Coastguard Worker int aio_read(struct aiocb *);
53*ec779b8eSAndroid Build Coastguard Worker int aio_write(struct aiocb *);
54*ec779b8eSAndroid Build Coastguard Worker 
55*ec779b8eSAndroid Build Coastguard Worker // Suspend current thread until given IO is complete, at which point
56*ec779b8eSAndroid Build Coastguard Worker // its return value and any errors can be accessed
57*ec779b8eSAndroid Build Coastguard Worker // All submitted requests must have a corresponding suspend.
58*ec779b8eSAndroid Build Coastguard Worker // aiocb->aio_buf must refer to valid memory until after the suspend call
59*ec779b8eSAndroid Build Coastguard Worker int aio_suspend(struct aiocb *[], int, const struct timespec *);
60*ec779b8eSAndroid Build Coastguard Worker int aio_error(const struct aiocb *);
61*ec779b8eSAndroid Build Coastguard Worker ssize_t aio_return(struct aiocb *);
62*ec779b8eSAndroid Build Coastguard Worker 
63*ec779b8eSAndroid Build Coastguard Worker // Helper method for setting aiocb members
64*ec779b8eSAndroid Build Coastguard Worker void aio_prepare(struct aiocb *, void*, size_t, off64_t);
65*ec779b8eSAndroid Build Coastguard Worker 
66*ec779b8eSAndroid Build Coastguard Worker #endif // POSIXASYNCIO_H
67*ec779b8eSAndroid Build Coastguard Worker 
68