bio
 
Loading...
Searching...
No Matches
Internal details

For porting to a new platform. More...

Modules

 Linux
 Linux implementation details.
 
 Windows
 Windows implementation details.
 
 FreeBSD
 FreeBSD implementation details.
 

Macros

#define BIO_DEFAULT_NUM_CLS_BUCKETS   4
 The default number of CLS hash buckets.
 
#define BIO_DEFAULT_THREAD_POOL_SIZE   2
 The default number of threads in the async thread pool.
 
#define BIO_DEFAULT_THREAD_POOL_QUEUE_SIZE   2
 The default queue size for the async thread pool.
 

Functions

void bio_platform_init (void)
 Initialize the platform layer.
 
void bio_platform_cleanup (void)
 Cleanup the platform layer.
 
void bio_platform_update (bio_time_t wait_timeout_ms, bool notifiable)
 Check on I/O completion status.
 
void bio_platform_notify (void)
 Make bio_platform_update return.
 
bio_time_t bio_platform_current_time_ms (void)
 Return the current time in milliseconds.
 
void bio_platform_begin_create_thread_pool (void)
 Called before the async thread pool is created.
 
void bio_platform_end_create_thread_pool (void)
 Called after the async thread pool is created.
 
void bio_platform_block_exit_signal (void)
 Block exit signals from the OS.
 
void bio_platform_unblock_exit_signal (void)
 Unblock exit signals from the OS.
 
void bio_handle_exit_signal (void)
 Callback for a platform implementation to notify bio of exit signal.
 
void bio_fs_init (void)
 Initialize the File I/O subsystem.
 
void bio_fs_cleanup (void)
 Cleanup the File I/O subsystem.
 
void bio_net_init (void)
 Initialize the Network I/O subsystem.
 
void bio_net_cleanup (void)
 Cleanup the Network I/O subsystem.
 

Detailed Description

For porting to a new platform.

For each platform, bio makes use of its specific async I/O API. To port to a new platform, all of the functions mentioned here must be implemented in addition to all File I/O and Network I/O functions.

The event loop and the async thread pool are largely platform-agnostic. All the platform-dependent details are abstracted into bio_platform_update and bio_platform_notify.

The I/O functions are usually implemented like this:

This would suspend the calling coroutine.

Later on, when all existing coroutines have yielded or suspended, bio will call bio_platform_update. The implementation should check for completed I/O requests there. Through the "userdata" feature often found in async I/O APIs, it will call bio_raise_signal to resume coroutines whose I/O requests have completed.

The async thread pool is handled through bio_platform_notify. Whenever a task has finished execution, bio will call bio_platform_notify from the worker thread, not the main thread. The implementation must have a way to make bio_platform_update return when signalled from a different thread regardless of whether an I/O event has occured. Async I/O APIs often have some sort of "user event" that can be posted from another thread for this purpose.

Macro Definition Documentation

◆ BIO_DEFAULT_NUM_CLS_BUCKETS

#define BIO_DEFAULT_NUM_CLS_BUCKETS   4

The default number of CLS hash buckets.

◆ BIO_DEFAULT_THREAD_POOL_QUEUE_SIZE

#define BIO_DEFAULT_THREAD_POOL_QUEUE_SIZE   2

The default queue size for the async thread pool.

◆ BIO_DEFAULT_THREAD_POOL_SIZE

#define BIO_DEFAULT_THREAD_POOL_SIZE   2

The default number of threads in the async thread pool.

Function Documentation

◆ bio_fs_cleanup()

void bio_fs_cleanup ( void  )

Cleanup the File I/O subsystem.

◆ bio_fs_init()

void bio_fs_init ( void  )

Initialize the File I/O subsystem.

◆ bio_handle_exit_signal()

void bio_handle_exit_signal ( void  )

Callback for a platform implementation to notify bio of exit signal.

◆ bio_net_cleanup()

void bio_net_cleanup ( void  )

Cleanup the Network I/O subsystem.

◆ bio_net_init()

void bio_net_init ( void  )

Initialize the Network I/O subsystem.

◆ bio_platform_begin_create_thread_pool()

void bio_platform_begin_create_thread_pool ( void  )

Called before the async thread pool is created.

◆ bio_platform_block_exit_signal()

void bio_platform_block_exit_signal ( void  )

Block exit signals from the OS.

Whenever a signal is received, instead, the implementation would call bio_handle_exit_signal from bio_platform_update.

◆ bio_platform_cleanup()

void bio_platform_cleanup ( void  )

Cleanup the platform layer.

◆ bio_platform_current_time_ms()

bio_time_t bio_platform_current_time_ms ( void  )

Return the current time in milliseconds.

See also
bio_current_time_ms

◆ bio_platform_end_create_thread_pool()

void bio_platform_end_create_thread_pool ( void  )

Called after the async thread pool is created.

◆ bio_platform_init()

void bio_platform_init ( void  )

Initialize the platform layer.

◆ bio_platform_notify()

void bio_platform_notify ( void  )

Make bio_platform_update return.

This function will always be called from the async thread pool. It must signal to bio_platform_update in the main thread to return regardless of I/O completion status.

◆ bio_platform_unblock_exit_signal()

void bio_platform_unblock_exit_signal ( void  )

Unblock exit signals from the OS.

Whenever a signal is received, exits without cleanup by default.

◆ bio_platform_update()

void bio_platform_update ( bio_time_t  wait_timeout_ms,
bool  notifiable 
)

Check on I/O completion status.

The event loop will call this function whenever all coroutines have yielded or suspended. This function should use the platform's polling API to check for completion status and raise the relevant I/O wait signals.

Parameters
wait_timeout_msHow much time to wait for I/O completion. This should be followed as closely as possible since bio relies on it for timing. If this is 0, the function should return as soon as there is no more pending I/O event. If this is -1, the function should wait indefinitely until there is at least one I/O event.
notifiableShould this wait be notifiable with bio_platform_notify. When this is false, this function was called at a time when there is no pending async task. It may choose to execute in a more efficient code path.