fs::Aio
- Inherits: api::ExecutionContext
public
Types
#
AiocbListusing fs::Aio::AiocbList = var::Vector<struct aiocb *>
Type: var::Vector< struct aiocb * >
Friends
#
hal::DeviceObjectfriend class hal::DeviceObject
Type: class
Parameters:
hal::DeviceObject
Functions
#
Aio()=defaultfs::Aio::Aio ()=default
#
Aio(var::View view, off_t location=0)inline
explicit
fs::Aio::Aio (var::View view, off_t location=0)
#
buffer() constinline
volatile void * fs::Aio::buffer () const
Type: volatile void *
#
DetailsReturns the buffer pointer.
#
error()inline
int fs::Aio::error ()
Type: int
#
DetailsReturns the error number of the operation.
#
is_busy() constinline
bool fs::Aio::is_busy () const
Type: bool
#
DetailsReturns true if operation is still in progress.
#
is_done() constinline
bool fs::Aio::is_done () const
Type: bool
#
DetailsReturns true if operation is complete.
#
nbytes() constinline
int fs::Aio::nbytes () const
Type: int
#
DetailsReturns the number of bytes to transfer.
#
offset() constinline
int fs::Aio::offset () const
Type: int
#
DetailsReturns the offset (or channel for Dac, Adc, Pwm, etc).
#
refer_to(var::View item)inline
Aio & fs::Aio::refer_to (var::View item)
Type: Aio &
Parameters:
- var::View
item
#
DetailsSets the buffer pointer.
#
ret()inline
int fs::Aio::ret ()
Type: int
#
DetailsReturns the return value of the operation.
#
set_location(int location)inline
Aio & fs::Aio::set_location (int location)
Type: Aio &
Parameters:
int
location
#
set_offset(int offset)inline
Aio & fs::Aio::set_offset (int offset)
Type: Aio &
Parameters:
int
offset
#
DetailsSets the offset (or channcel for Dac, Adc, Pwm, etc).
#
set_signal(int number, int value)inline
Aio & fs::Aio::set_signal (int number, int value)
Type: Aio &
Parameters:
int
number
int
value
#
DetailsCauses the calling thread to receive a signal when the operation completes.
Returns:
Zero on success
#
set_signal_number(int number)inline
Aio & fs::Aio::set_signal_number (int number)
Type: Aio &
Parameters:
int
number
#
set_signal_value(int value)inline
Aio & fs::Aio::set_signal_value (int value)
Type: Aio &
Parameters:
int
value
#
suspend(const chrono::MicroTime &timeout=chrono::MicroTime(0))inline
Aio & fs::Aio::suspend (const chrono::MicroTime &timeout=chrono::MicroTime(0))
Type: Aio &
Parameters:
- const chrono::MicroTime &
timeout
#
DetailsBlocks until the operation completes or timeout is reached.
Static Functions
#
suspend(const AiocbList &list, const chrono::MicroTime &timeout=chrono::MicroTime(0))inline
static int fs::Aio::suspend (const AiocbList &list, const chrono::MicroTime &timeout=chrono::MicroTime(0))
Type: int
Parameters:
- const AiocbList &
list
- const chrono::MicroTime &
timeout
#
DetailsBlocks until all transfers in list have completed or timeout is reached.Asynchronous IO Class.
Details
The Asynchronous IO class is used for performing asynchronous operations on hardware devices. When calling synchronous IO, the read/write function is called and then returns when the operation is complete. With Asynchronous IO, the read/write function returns immediately and the Aio class can be used to see when the operation completes.On Stratify OS, synchronous operations will always cause the running thread to yield the processor. This can be avoided by using the Aio class. Consider the following example:
#include <hal.hpp>#include <sys.hpp>#include <var.hpp>
int main(int argc, char * argv[]){ String buf = "Hello World!\n"; Uart uart(0); //we will read/write data to UART port 0 [Aio](classfs_1_1_aio#classfs_1_1_aio_1a74204e8c98038bcaf5d6b9b181dcff9e) aio(buf.data(), buf.size()); //aio uses buf as it's data
uart.init(); //init the UART with default settings
//First a synchronous write uart.write(buf.c_str(), buf.size()); //this will return when the bytesare written //While bytes are writing, the processor will be used on another thread
//Now the AIO version uart.write(aio); //This thread keeps the processor -- so we can do something else in parallel
while( aio.done() == false ){ Timer::wait_milliseconds(5); //wait for the operation to complete }
return 0;}