GATE
coroutines.h File Reference

Support for coroutines. More...

#include "gate/gate_core_api.h"
#include "gate/gatetypes.h"

Typedefs

typedef gate_intptr_t gate_coroutine_id_t
 
typedef gate_entrypoint_t gate_coroutine_function_t
 

Functions

GATE_CORE_API gate_bool_t gate_coroutine_supported ()
 Returns TRUE if coroutines are supported on this platform.
 
GATE_CORE_API gate_result_t gate_coroutine_run (gate_coroutine_function_t func, void *param)
 Starts a coroutine session and executes the first given coroutine.
 
GATE_CORE_API gate_bool_t gate_coroutine_enabled ()
 Returns if a coroutine session is already running.
 
GATE_CORE_API gate_result_t gate_coroutine_get_current (gate_coroutine_id_t *ptr_id)
 Returns the ID of the currently running coroutine.
 
GATE_CORE_API gate_result_t gate_coroutine_yield ()
 Yields execution of current coroutine and switches to the next coroutine.
 
GATE_CORE_API gate_result_t gate_coroutine_sleep (gate_uint32_t milliseconds)
 Sleeps within the coroutine the defined amount of milliseconds (may causing switches to other routines)
 
GATE_CORE_API gate_result_t gate_coroutine_create (gate_coroutine_function_t func, void *param, gate_coroutine_id_t *ptr_id)
 Creates a new (suspended) coroutine.
 
GATE_CORE_API gate_result_t gate_coroutine_switch_to (gate_coroutine_id_t id)
 Suspends the current coroutine and switches to the given coroutine to continue exection of its code.
 
GATE_CORE_API gate_result_t gate_coroutine_await (gate_coroutine_id_t id, gate_result_t *ptr_coroutine_result)
 Awaits the completion of a coroutine.
 

Detailed Description

Support for coroutines.

Typedef Documentation

◆ gate_coroutine_function_t

coroutine entry point function signature

◆ gate_coroutine_id_t

unique ID to identify a created coroutine

Function Documentation

◆ gate_coroutine_await()

GATE_CORE_API gate_result_t gate_coroutine_await ( gate_coroutine_id_t id,
gate_result_t * ptr_coroutine_result )

Awaits the completion of a coroutine.

Parameters
[in]idcoroutine ID to be awaited
[in]ptr_coroutine_resultpointer to receive result returned from entry function
Returns
GATE_RESULT_* result code

◆ gate_coroutine_create()

GATE_CORE_API gate_result_t gate_coroutine_create ( gate_coroutine_function_t func,
void * param,
gate_coroutine_id_t * ptr_id )

Creates a new (suspended) coroutine.

Parameters
[in]funcentry point function of new coroutine
[in]paramparameter to be used in first coroutine entry point
[in]ptr_idpointer to ID that is overwritten with the new created coroutine.
Returns
GATE_RESULT_* result code

◆ gate_coroutine_enabled()

GATE_CORE_API gate_bool_t gate_coroutine_enabled ( )

Returns if a coroutine session is already running.

Returns
TRUE/FALSE indicating a running coroutine

◆ gate_coroutine_get_current()

GATE_CORE_API gate_result_t gate_coroutine_get_current ( gate_coroutine_id_t * ptr_id)

Returns the ID of the currently running coroutine.

Parameters
[in]ptr_idPointer to ID to be overwritten with the current coroutine ID
Returns
GATE_RESULT_* result code

◆ gate_coroutine_run()

GATE_CORE_API gate_result_t gate_coroutine_run ( gate_coroutine_function_t func,
void * param )

Starts a coroutine session and executes the first given coroutine.

Parameters
[in]funcfunction to be executed as first coroutine in a session
[in]paramparameter to be used in first coroutine entry point
Returns
GATE_RESULT_* result code

◆ gate_coroutine_sleep()

GATE_CORE_API gate_result_t gate_coroutine_sleep ( gate_uint32_t milliseconds)

Sleeps within the coroutine the defined amount of milliseconds (may causing switches to other routines)

Parameters
[in]millisecondstime duration to sleep in milliseconds
Returns
GATE_RESULT_* result code

◆ gate_coroutine_supported()

GATE_CORE_API gate_bool_t gate_coroutine_supported ( )

Returns TRUE if coroutines are supported on this platform.

Returns
TRUE/FALSE indicating support for coroutines on this platform

◆ gate_coroutine_switch_to()

GATE_CORE_API gate_result_t gate_coroutine_switch_to ( gate_coroutine_id_t id)

Suspends the current coroutine and switches to the given coroutine to continue exection of its code.

Parameters
[in]idcoroutine ID to be switched to
Returns
GATE_RESULT_* result code

◆ gate_coroutine_yield()

GATE_CORE_API gate_result_t gate_coroutine_yield ( )

Yields execution of current coroutine and switches to the next coroutine.

Returns
GATE_RESULT_* result code