GATE
runnables.h File Reference

Encapsulation of executable codes by runnable interface. More...

#include "gate/gate_core_api.h"
#include "gate/delegates.h"
#include "gate/objects.h"
#include "gate/synchronization.h"

Classes

struct  gate_runnable_storage_class
 
struct  gate_task_storage_class
 

Macros

#define GATE_RUNNABLE_DISPATCHER_FUNC_NAME(disp_name)   disp_name ## _gate_func_runnable_dispatcher
 
#define GATE_RUNNABLE_DISPATCHER_DECLARE_3(disp_name, type1, type2, type3)
 
#define GATE_RUNNABLE_DISPATCHER_CREATE_3(disp_name, func_ptr, arg1, arg2, arg3)
 
#define GATE_INTERFACE_NAME_TASK   GATE_INTERFACE_NAME_RUNNABLE GATE_INTERFACE_NAME_SEPARATOR "task"
 
#define GATE_TASK_STATUS_PREPARED   1
 
#define GATE_TASK_STATUS_RUNNING   2
 
#define GATE_TASK_STATUS_COMPLETED   3
 
#define GATE_TASK_STATUS_CANCELED   4
 
#define GATE_TASK_STATUS_FAILED   5
 
#define gate_task_run(obj)   (obj)->vtbl->run((obj))
 
#define gate_task_cancel(obj)   (obj)->vtbl->cancel((obj))
 
#define gate_task_get_status(obj)   (obj)->vtbl->get_status((obj))
 
#define gate_task_completed(obj)   (obj)->vtbl->completed((obj))
 
#define gate_task_get_result(obj, ptr_task_result, ptr_task_data)   (obj)->vtbl->get_result((obj), (ptr_task_result), (ptr_task_data))
 
#define gate_task_wait(obj)   (obj)->vtbl->wait((obj))
 
#define gate_task_timed_wait(obj, timeout_ms)   (obj)->vtbl->timed_wait((obj), (timeout_ms))
 
#define GATE_TASK_DISPATCHER_FUNC_NAME(disp_name)   disp_name ## _gate_func_task_dispatcher
 
#define GATE_TASK_DISPATCHER_DECLARE_2(disp_name, out_type, t1, t2)
 
#define GATE_TASK_DISPATCHER_CREATE_2(disp_name, func_ptr, out_type, a1, a2)
 
#define GATE_TASK_DISPATCHER_DECLARE_3(disp_name, out_type, t1, t2, t3)
 
#define GATE_TASK_DISPATCHER_CREATE_3(disp_name, func_ptr, out_type, a1, a2, a3)
 

Typedefs

typedef struct gate_runnable_storage_class gate_runnable_storage_t
 
typedef gate_result_t(* gate_runnable_dispatcher_t) (gate_runnable_storage_t const *runnable_storage_ptr)
 
typedef struct gate_task_storage_class gate_task_storage_t
 
typedef gate_result_t(* gate_task_dispatcher_t) (gate_task_storage_t const *task_storage_ptr)
 
typedef void(* gate_task_dispatcher_destructor_t) (gate_task_storage_t *task_destructor_ptr)
 

Functions

GATE_CORE_API gate_runnable_tgate_runnable_dispatcher_create (void *func_ptr, gate_size_t func_ptr_size, gate_runnable_dispatcher_t dispatcher,...)
 Creates a.
 
 GATE_INTERFACE (gate_task)
 
GATE_CORE_API gate_task_tgate_task_dispatcher_create (void *func_ptr, gate_size_t func_ptr_size, gate_task_dispatcher_t dispatcher, gate_size_t ret_type_size,...)
 
GATE_CORE_API gate_result_t gate_runasync (gate_runnable_t *ptr_runnable)
 

Detailed Description

Encapsulation of executable codes by runnable interface.

Macro Definition Documentation

◆ GATE_RUNNABLE_DISPATCHER_CREATE_3

#define GATE_RUNNABLE_DISPATCHER_CREATE_3 ( disp_name,
func_ptr,
arg1,
arg2,
arg3 )
Value:
gate_runnable_dispatcher_create(func_ptr, sizeof(func_ptr), GATE_RUNNABLE_DISPATCHER_FUNC_NAME(disp_name), \
(&(arg1)), sizeof(arg1), \
(&(arg2)), sizeof(arg2), \
(&(arg3)), sizeof(arg3), \
NULL)
GATE_CORE_API gate_runnable_t * gate_runnable_dispatcher_create(void *func_ptr, gate_size_t func_ptr_size, gate_runnable_dispatcher_t dispatcher,...)
Creates a.
Definition runnables.c:139

◆ GATE_RUNNABLE_DISPATCHER_DECLARE_3

#define GATE_RUNNABLE_DISPATCHER_DECLARE_3 ( disp_name,
type1,
type2,
type3 )
Value:
typedef gate_result_t(* disp_name ## _runnable_func_callback_t)(type1 arg1, type2 arg2, type3 arg3); \
static gate_result_t GATE_RUNNABLE_DISPATCHER_FUNC_NAME(disp_name) (gate_runnable_storage_t const* runnable_storage_ptr) \
{ \
gate_result_t result; \
disp_name ## _runnable_func_callback_t callback = NULL; \
type1 * ptr_arg1 = ( type1 * )runnable_storage_ptr->params[0]; \
type2 * ptr_arg2 = ( type2 * )runnable_storage_ptr->params[1]; \
type3 * ptr_arg3 = ( type3 * )runnable_storage_ptr->params[2]; \
gate_mem_copy(&callback, &runnable_storage_ptr->function_storage, sizeof(callback)); \
result = callback(*ptr_arg1, *ptr_arg2, *ptr_arg3); \
return result; \
}
int gate_result_t
Definition gatetypes.h:593
Definition runnables.h:52

◆ GATE_TASK_DISPATCHER_CREATE_2

#define GATE_TASK_DISPATCHER_CREATE_2 ( disp_name,
func_ptr,
out_type,
a1,
a2 )
Value:
gate_task_dispatcher_create(func_ptr, sizeof(func_ptr), GATE_TASK_DISPATCHER_FUNC_NAME(disp_name), \
sizeof(out_type), \
(&a1), sizeof(a1), \
(&a2), sizeof(a2), \
NULL)

◆ GATE_TASK_DISPATCHER_CREATE_3

#define GATE_TASK_DISPATCHER_CREATE_3 ( disp_name,
func_ptr,
out_type,
a1,
a2,
a3 )
Value:
gate_task_dispatcher_create(func_ptr, sizeof(func_ptr), GATE_TASK_DISPATCHER_FUNC_NAME(disp_name), \
sizeof(out_type), \
(&a1), sizeof(a1), \
(&a2), sizeof(a2), \
(&a3), sizeof(a3), \
NULL)

◆ GATE_TASK_DISPATCHER_DECLARE_2

#define GATE_TASK_DISPATCHER_DECLARE_2 ( disp_name,
out_type,
t1,
t2 )
Value:
typedef gate_result_t(* disp_name ## _task_func_callback_t)(out_type* ptr_ret, t1 a1, t2 a2); \
static gate_result_t GATE_TASK_DISPATCHER_FUNC_NAME(disp_name) (gate_task_storage_t const* storage_ptr) \
{ \
gate_result_t result; \
disp_name ## _task_func_callback_t callback = NULL; \
out_type * ptr_ret = ( out_type * )storage_ptr->params[0]; \
t1 * ptr_arg1 = ( t1 * )storage_ptr->params[1]; \
t2 * ptr_arg2 = ( t2 * )storage_ptr->params[2]; \
gate_mem_copy(&callback, &storage_ptr->function_storage, sizeof(callback)); \
result = callback(ptr_ret, *ptr_arg1, *ptr_arg2); \
return result; \
}
Definition runnables.h:201

◆ GATE_TASK_DISPATCHER_DECLARE_3

#define GATE_TASK_DISPATCHER_DECLARE_3 ( disp_name,
out_type,
t1,
t2,
t3 )
Value:
typedef gate_result_t(* disp_name ## _task_func_callback_t)(out_type* ptr_ret, t1 a1, t2 a2, t3 a3); \
static gate_result_t GATE_TASK_DISPATCHER_FUNC_NAME(disp_name) (gate_task_storage_t const* storage_ptr) \
{ \
gate_result_t result; \
disp_name ## _task_func_callback_t callback = NULL; \
out_type * ptr_ret = ( out_type * )storage_ptr->params[0]; \
t1 * ptr_arg1 = ( t1 * )storage_ptr->params[1]; \
t2 * ptr_arg2 = ( t2 * )storage_ptr->params[2]; \
t3 * ptr_arg3 = ( t3 * )storage_ptr->params[3]; \
gate_mem_copy(&callback, &storage_ptr->function_storage, sizeof(callback)); \
result = callback(type_ret, *ptr_arg1, *ptr_arg2, *ptr_arg3); \
return result; \
}

Function Documentation

◆ gate_runnable_dispatcher_create()

GATE_CORE_API gate_runnable_t * gate_runnable_dispatcher_create ( void * func_ptr,
gate_size_t func_ptr_size,
gate_runnable_dispatcher_t dispatcher,
... )

Creates a.

See also
gate_runnable_t object from a target function, a dispatcher and pairs

This function stores all given arguments in a runnable object and uses a dispatcher function generated by GATE_RUNNABLE_DISPATCHER_DECLARE_N() to invoke a target function with the preserved arguments.

Parameters
[in]func_ptrPointer to target function pointer to be called by runnable instance
[in]func_ptr_sizeSize of target function pointer to be called
[in]dispatcherPointer to dispatcher function that calls target function with stored parameters
[in]...Pairs of pointers to arguments and their sizes, e.g.: (int)1, sizeof(int), "hello", sizeof(char const*)
Returns
pointer to allocated gate_runnable_t instance, or NULL in case of allocation failure