libaramid
Portable Multiprocessing Library for C
Classes | Macros | Typedefs | Enumerations | Functions
aramid.h File Reference

libaramid public API header More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Classes

struct  TAG_ARMD_MemoryAllocator
 Abstract memory allocator. More...
 
struct  TAG_ARMD_Timespec
 
struct  TAG_ARMD_LogElement
 

Macros

#define ARMD_EXTERN_C
 
#define ARMD_LOGGER_LOG_FORMAT_ATTRIBUTE
 
#define armd_log_fatal(logger, format, ...)
 
#define armd_log_error(logger, format, ...)
 
#define armd_log_warn(logger, format, ...)
 
#define armd_log_info(logger, format, ...)
 
#define armd_log_debug(logger, format, ...)
 
#define armd_log_trace(logger, format, ...)
 

Typedefs

typedef size_t ARMD_Size
 Size type.
 
typedef int ARMD_Bool
 Boolean type.
 
typedef double ARMD_Real
 Floating point value type.
 
typedef uint64_t ARMD_Handle
 Handle type.
 
typedef struct TAG_ARMD_Job ARMD_Job
 Aramid Job. More...
 
typedef struct TAG_ARMD_Procedure ARMD_Procedure
 Aramid Procedure. More...
 
typedef void *(* ARMD_MemoryAllocatorAllocateFunc) (void *context, ARMD_Size size)
 Memory allocation function interface. More...
 
typedef void(* ARMD_MemoryAllocatorFreeFunc) (void *context, void *buf)
 Memory free function interface. More...
 
typedef struct TAG_ARMD_MemoryAllocator ARMD_MemoryAllocator
 Abstract memory allocator. More...
 
typedef struct TAG_ARMD_MemoryRegion ARMD_MemoryRegion
 Memory region. More...
 
typedef struct TAG_ARMD_Context ARMD_Context
 The execution engine. More...
 
typedef void(* ARMD_PromiseCallbackFunc) (ARMD_Handle handle, void *callback_context, int has_error)
 Promise callback. More...
 
typedef enum TAG_ARMD_ContinuationResult ARMD_ContinuationResult
 Continuation Status.
 
typedef ARMD_ContinuationResult(* ARMD_ContinuationFunc) (ARMD_Job *job, const void *constants, void *args, void *frame, const void *continuation_constants, void *continuation_frame)
 Continuation Function. More...
 
typedef ARMD_ContinuationResult(* ARMD_ErrorTrapFunc) (ARMD_Job *job, const void *constants, void *args, void *frame, const void *continuation_constants, void *continuation_frame)
 Error Trap Function.
 
typedef void(* ARMD_ContinuationConstantsDestroyer) (ARMD_MemoryAllocator *memory_region, void *continuation_constants)
 Continuation Constant Destroyer.
 
typedef void *(* ARMD_ContinuationFrameCreator) (ARMD_MemoryRegion *memory_region)
 Continuation Frame Creator. More...
 
typedef void(* ARMD_ContinuationFrameDestroyer) (ARMD_MemoryRegion *memory_region, void *continuation_frame)
 Continuation Frame Destroyer. More...
 
typedef int(* ARMD_SingleContinuationFunc) (ARMD_Job *job, const void *constants, void *args, void *frame)
 Single Continuation Function. More...
 
typedef ARMD_Size(* ARMD_SequentialForCountFunc) (void *args, void *frame)
 Sequential-For Count Function. More...
 
typedef int(* ARMD_SequentialForContinuationFunc) (ARMD_Job *job, const void *constants, void *args, void *frame, ARMD_Size index)
 Sequential-For Continuation Function. More...
 
typedef ARMD_Size(* ARMD_ParallelForCountFunc) (void *args, void *frame)
 Parallel-For Count Function. More...
 
typedef int(* ARMD_ParallelForContinuationFunc) (ARMD_Job *job, const void *constants, void *args, void *frame, ARMD_Size index)
 Parallel-For Continuation Function. More...
 
typedef ARMD_Bool(* ARMD_SetupFunc) (ARMD_Job *job, const void *constants, void *args, void *frame, int dependency_has_error)
 Setup Function. More...
 
typedef void(* ARMD_UnwindFunc) (ARMD_Job *job, const void *constants, void *args, void *frame)
 Unwind Function. More...
 
typedef struct TAG_ARMD_ProcedureBuilder ARMD_ProcedureBuilder
 Builder object for ARMD_Procedure.
 
typedef struct TAG_ARMD_Timespec ARMD_Timespec
 
typedef enum TAG_ARMD_LogLevel ARMD_LogLevel
 
typedef struct TAG_ARMD_Logger ARMD_Logger
 
typedef struct TAG_ARMD_LogElement ARMD_LogElement
 
typedef void(* ARMD_LoggerCallbackFunc) (void *context, ARMD_Logger *logger)
 

Enumerations

enum  TAG_ARMD_ContinuationResult { ARMD_ContinuationResult_Error, ARMD_ContinuationResult_Ended, ARMD_ContinuationResult_Repeat }
 Continuation Status.
 
enum  TAG_ARMD_LogLevel {
  ARMD_LogLevel_Fatal, ARMD_LogLevel_Error, ARMD_LogLevel_Warn, ARMD_LogLevel_Info,
  ARMD_LogLevel_Debug, ARMD_LogLevel_Trace
}
 

Functions

ARMD_EXTERN_C void * armd_memory_allocator_allocate (const ARMD_MemoryAllocator *allocator, ARMD_Size size)
 Allocates memory area with ARMD_MemoryAllocator. More...
 
ARMD_EXTERN_C void armd_memory_allocator_free (const ARMD_MemoryAllocator *allocator, void *buf)
 Free memory area allocated with ARMD_MemoryAllocator. More...
 
ARMD_EXTERN_C void armd_memory_allocator_init_default (ARMD_MemoryAllocator *memory_allocator)
 Initialize ARMD_MemoryAllocator with default value. More...
 
ARMD_EXTERN_C ARMD_MemoryRegionarmd_memory_region_create (const ARMD_MemoryAllocator *memory_allocator)
 Create ARMD_MemoryRegion. More...
 
ARMD_EXTERN_C ARMD_Size armd_memory_region_destroy (ARMD_MemoryRegion *memory_region)
 Destroy ARMD_MemoryRegion. More...
 
ARMD_EXTERN_C void * armd_memory_region_allocate (ARMD_MemoryRegion *memory_region, ARMD_Size size)
 Allocates memory area with ARMD_MemoryRegion. More...
 
ARMD_EXTERN_C void armd_memory_region_free (ARMD_MemoryRegion *memory_region, void *buf)
 Free memory area allocated with ARMD_MemoryRegion. More...
 
ARMD_EXTERN_C char * armd_memory_region_strdup (ARMD_MemoryRegion *memory_region, const char *str)
 strdup for memory_region
 
ARMD_EXTERN_C ARMD_Contextarmd_context_create (const ARMD_MemoryAllocator *memory_allocator, ARMD_Size num_executors)
 Create ARMD_Context. More...
 
ARMD_EXTERN_C int armd_context_destroy (ARMD_Context *context)
 Destroy ARMD_Context. More...
 
ARMD_EXTERN_C ARMD_Handle armd_invoke (ARMD_Context *context, ARMD_Procedure *procedure, void *args, ARMD_Size num_dependencies, const ARMD_Handle *dependencies)
 Invoke procedure. More...
 
ARMD_EXTERN_C int armd_await (ARMD_Context *context, ARMD_Handle handle)
 Await promise. More...
 
ARMD_EXTERN_C int armd_detach (ARMD_Context *context, ARMD_Handle handle)
 Detach promise. More...
 
ARMD_EXTERN_C int armd_await_all (ARMD_Context *context)
 Await all promise.
 
ARMD_EXTERN_C int armd_add_promise_callback (ARMD_Context *context, ARMD_Handle handle, void *callback_context, ARMD_PromiseCallbackFunc callback_func)
 Add callback to the promise. More...
 
ARMD_EXTERN_C ARMD_Size armd_job_get_num_executors (ARMD_Job *job)
 Get the number of executors in the ARMD_Context via ARMD_Job. More...
 
ARMD_EXTERN_C ARMD_Size armd_job_get_executor_id (ARMD_Job *job)
 Get the executor id via ARMD_Job. More...
 
ARMD_EXTERN_C int armd_fork (ARMD_Job *parent_job, ARMD_Procedure *procedure, void *args)
 Fork and invoke procedure. More...
 
ARMD_EXTERN_C int armd_fork_with_id (ARMD_Size executor_id, ARMD_Job *parent_job, ARMD_Procedure *procedure, void *args)
 Fork and invoke procedure specifying the executor. More...
 
ARMD_EXTERN_C ARMD_ProcedureBuilderarmd_procedure_builder_create (const ARMD_MemoryAllocator *memory_allocator, ARMD_Size constant_size, ARMD_Size frame_size)
 Create ARMD_ProcedureBuilder. More...
 
ARMD_EXTERN_C int armd_procedure_builder_destroy (ARMD_ProcedureBuilder *procedure_builder)
 Destroy ARMD_ProcedureBuilder without building ARMD_Procedure. More...
 
ARMD_EXTERN_C ARMD_Procedurearmd_procedure_builder_build_and_destroy (ARMD_ProcedureBuilder *procedure_builder)
 Build ARMD_Procedure and destroy ARMD_ProcedureBuilder. More...
 
ARMD_EXTERN_C void * armd_procedure_builder_get_constants (ARMD_ProcedureBuilder *procedure_builder)
 Get the pointer to constant table. More...
 
ARMD_EXTERN_C ARMD_MemoryAllocator armd_procedure_builder_get_memory_allocator (ARMD_ProcedureBuilder *procedure_builder)
 Get the memory allocator used in ARMD_ProcedureBuilder. More...
 
ARMD_EXTERN_C int armd_then (ARMD_ProcedureBuilder *procedure_builder, ARMD_ContinuationFunc continuation_func, void *continuation_constants, ARMD_ContinuationConstantsDestroyer continuation_constants_destroyer, ARMD_ErrorTrapFunc error_trap_func, ARMD_ContinuationFrameCreator continuation_frame_creator, ARMD_ContinuationFrameDestroyer continuation_frame_destroyer)
 Appends a versatile continuation to the procedure. More...
 
ARMD_EXTERN_C int armd_then_single (ARMD_ProcedureBuilder *procedure_builder, ARMD_SingleContinuationFunc single_continuation_func)
 Appends a single continuation to the procedure. More...
 
ARMD_EXTERN_C int armd_then_sequential_for (ARMD_ProcedureBuilder *procedure_builder, ARMD_SequentialForCountFunc sequential_for_count_func, ARMD_SequentialForContinuationFunc sequential_for_continuation_func)
 Appends a sequential-for continuation to the procedure. More...
 
ARMD_EXTERN_C int armd_then_parallel_for (ARMD_ProcedureBuilder *procedure_builder, ARMD_ParallelForCountFunc parallel_for_count_func, ARMD_ParallelForContinuationFunc parallel_for_continuation_func)
 Appends a parallel-for continuation to the procedure.
 
int armd_setup (ARMD_ProcedureBuilder *builder, ARMD_SetupFunc setup_func)
 Add unwind callback to the procedure. More...
 
ARMD_EXTERN_C int armd_unwind (ARMD_ProcedureBuilder *procedure_builder, ARMD_UnwindFunc unwind_func)
 Add unwind callback to the procedure. More...
 
ARMD_EXTERN_C int armd_procedure_destroy (ARMD_Procedure *procedure)
 Destroy ARMD_Procedure. More...
 
ARMD_EXTERN_C void * armd_procedure_get_constants (ARMD_Procedure *procedure)
 Get the pointer to constant table. More...
 
ARMD_EXTERN_C int armd_get_time (ARMD_Timespec *result)
 
ARMD_EXTERN_C char * armd_format_time_iso8601 (ARMD_MemoryRegion *memory_region, const ARMD_Timespec *timespec)
 
ARMD_EXTERN_C ARMD_Logger * armd_logger_create (ARMD_MemoryRegion *memory_region, ARMD_LogLevel level)
 
ARMD_EXTERN_C void armd_logger_increment_reference_count (ARMD_Logger *logger)
 
ARMD_EXTERN_C ARMD_Bool armd_logger_decrement_reference_count (ARMD_Logger *logger)
 
ARMD_EXTERN_C void armd_logger_set_callback (ARMD_Logger *logger, ARMD_LoggerCallbackFunc callback_func, void *callback_context)
 
ARMD_EXTERN_C void armd_logger_set_stdout_callback (ARMD_Logger *logger)
 
ARMD_EXTERN_C void armd_logger_set_stderr_callback (ARMD_Logger *logger)
 
ARMD_EXTERN_C ARMD_MemoryRegionarmd_logger_get_memory_region (ARMD_Logger *logger)
 
ARMD_EXTERN_C int armd_logger_get_log_element (ARMD_Logger *logger, ARMD_LogElement **log_element)
 
ARMD_EXTERN_C void armd_logger_destroy_log_element (ARMD_Logger *logger, ARMD_LogElement *log_element)
 
ARMD_EXTERN_C void armd_logger_log_string (ARMD_Logger *logger, ARMD_LogLevel level, const char *filename, ARMD_Size lineno, char *message)
 
ARMD_EXTERN_C void armd_logger_log_format (ARMD_Logger *logger, ARMD_LogLevel level, const char *filename, ARMD_Size lineno, const char *format,...) ARMD_LOGGER_LOG_FORMAT_ATTRIBUTE
 

Detailed Description

libaramid public API header

Macro Definition Documentation

◆ armd_log_debug

#define armd_log_debug (   logger,
  format,
  ... 
)
Value:
armd_logger_log_format(logger, ARMD_LogLevel_Debug, __FILE__, __LINE__, \
format, __VA_ARGS__)

◆ armd_log_error

#define armd_log_error (   logger,
  format,
  ... 
)
Value:
armd_logger_log_format(logger, ARMD_LogLevel_Error, __FILE__, __LINE__, \
format, __VA_ARGS__)

◆ armd_log_fatal

#define armd_log_fatal (   logger,
  format,
  ... 
)
Value:
armd_logger_log_format(logger, ARMD_LogLevel_Fatal, __FILE__, __LINE__, \
format, __VA_ARGS__)

◆ armd_log_info

#define armd_log_info (   logger,
  format,
  ... 
)
Value:
armd_logger_log_format(logger, ARMD_LogLevel_Info, __FILE__, __LINE__, \
format, __VA_ARGS__)

◆ armd_log_trace

#define armd_log_trace (   logger,
  format,
  ... 
)
Value:
armd_logger_log_format(logger, ARMD_LogLevel_Trace, __FILE__, __LINE__, \
format, __VA_ARGS__)

◆ armd_log_warn

#define armd_log_warn (   logger,
  format,
  ... 
)
Value:
armd_logger_log_format(logger, ARMD_LogLevel_Warn, __FILE__, __LINE__, \
format, __VA_ARGS__)

Typedef Documentation

◆ ARMD_Context

typedef struct TAG_ARMD_Context ARMD_Context

The execution engine.

The global state for execution engine. It contains native threads, job deque, promise manager and so on. Most your API calls are done against this structure.

◆ ARMD_ContinuationFrameCreator

typedef void*(* ARMD_ContinuationFrameCreator) (ARMD_MemoryRegion *memory_region)

Continuation Frame Creator.

This function allocates and initializes continuation frame.

Parameters
memory_regionThe memory region for the continuation frame to live in
Returns
The new continuation frame. You can return NULL if failed.

◆ ARMD_ContinuationFrameDestroyer

typedef void(* ARMD_ContinuationFrameDestroyer) (ARMD_MemoryRegion *memory_region, void *continuation_frame)

Continuation Frame Destroyer.

This function allocates and initializes continuation frame.

Parameters
memory_regionThe memory region in which the continuation frame lives
continuation_frameThe continuation frame to be freed

◆ ARMD_ContinuationFunc

typedef ARMD_ContinuationResult(* ARMD_ContinuationFunc) (ARMD_Job *job, const void *constants, void *args, void *frame, const void *continuation_constants, void *continuation_frame)

Continuation Function.

This is something like functions but consists of many continuations which are represented with many fragment functions. The procedure also has meta infomation to execute in the thread pool.

◆ ARMD_Job

typedef struct TAG_ARMD_Job ARMD_Job

Aramid Job.

This is used when implementing ARMD_Procedure

◆ ARMD_MemoryAllocator

Abstract memory allocator.

It provides the capability of switching malloc implementation or injecting your own memory allocation algorithm. this struct is used not like a reference but like a value. That is, the members of ARMD_MemoryAllocator are copied into another ARMD_MemoryAllocator.

◆ ARMD_MemoryAllocatorAllocateFunc

typedef void*(* ARMD_MemoryAllocatorAllocateFunc) (void *context, ARMD_Size size)

Memory allocation function interface.

Parameters
contextMemory allocator context. See ARMD_MemoryAllocator::context
sizeAllocation size in bytes. It can be zero but not recommended.
Returns
The pointer to allocated memory. You can return NULL if failed.

◆ ARMD_MemoryAllocatorFreeFunc

typedef void(* ARMD_MemoryAllocatorFreeFunc) (void *context, void *buf)

Memory free function interface.

Parameters
contextMemory allocator context. See ARMD_MemoryAllocator::context
bufThe pointer to free. It must be the same pointer returned by ARMD_MemoryAllocatorAllocateFunc,

◆ ARMD_MemoryRegion

typedef struct TAG_ARMD_MemoryRegion ARMD_MemoryRegion

Memory region.

It provides region-based memory management functionality. It is also called memory zone or arena in some projects. Memory areas allocated in the region can be freed in a batch or it enables to detect memory leakage in fine granularity. In contrast to ARMD_MemoryAllocator, this struct is used as a reference.

◆ ARMD_ParallelForContinuationFunc

typedef int(* ARMD_ParallelForContinuationFunc) (ARMD_Job *job, const void *constants, void *args, void *frame, ARMD_Size index)

Parallel-For Continuation Function.

The simplified continuation function to be used in armd_then_parallel_for. It omits continuation_constants and continuation_frame and it receives the repetition counter as Public API.

◆ ARMD_ParallelForCountFunc

typedef ARMD_Size(* ARMD_ParallelForCountFunc) (void *args, void *frame)

Parallel-For Count Function.

The delegate used to get the number of times to run repeatedly

◆ ARMD_Procedure

typedef struct TAG_ARMD_Procedure ARMD_Procedure

Aramid Procedure.

This is something like functions but consists of many continuations which are represented with many fragment functions. The procedure also has meta infomation to execute in the thread pool.

◆ ARMD_PromiseCallbackFunc

typedef void(* ARMD_PromiseCallbackFunc) (ARMD_Handle handle, void *callback_context, int has_error)

Promise callback.

The function called when promise resolved. See armd_add_promise_callback.

◆ ARMD_SequentialForContinuationFunc

typedef int(* ARMD_SequentialForContinuationFunc) (ARMD_Job *job, const void *constants, void *args, void *frame, ARMD_Size index)

Sequential-For Continuation Function.

The simplified continuation function to be used in armd_then_sequential_for. It omits continuation_constants and continuation_frame and it receives the repetition counter as Public API.

◆ ARMD_SequentialForCountFunc

typedef ARMD_Size(* ARMD_SequentialForCountFunc) (void *args, void *frame)

Sequential-For Count Function.

The delegate used to get the number of times to run repeatedly

◆ ARMD_SetupFunc

typedef ARMD_Bool(* ARMD_SetupFunc) (ARMD_Job *job, const void *constants, void *args, void *frame, int dependency_has_error)

Setup Function.

The simplified continuation function to be used in armd_then_sequential_for. It omits continuation_constants and continuation_frame and it receives the repetition counter as Public API.

◆ ARMD_SingleContinuationFunc

typedef int(* ARMD_SingleContinuationFunc) (ARMD_Job *job, const void *constants, void *args, void *frame)

Single Continuation Function.

The simplified continuation function to be used in armd_then_single. It omits continuation_constants, continuation_frame, and the ability to run repeatedly.

◆ ARMD_UnwindFunc

typedef void(* ARMD_UnwindFunc) (ARMD_Job *job, const void *constants, void *args, void *frame)

Unwind Function.

The simplified continuation function to be used in armd_then_sequential_for. It omits continuation_constants and continuation_frame and it receives the repetition counter as Public API.

Function Documentation

◆ armd_add_promise_callback()

ARMD_EXTERN_C int armd_add_promise_callback ( ARMD_Context context,
ARMD_Handle  handle,
void *  callback_context,
ARMD_PromiseCallbackFunc  callback_func 
)

Add callback to the promise.

Add a function to be called when the promise being resolved. Note that the thread which invokes the callback is not indeterminate and the promise_callback may be invoked immediately. Many API in libaramid is not reentrant. If you calls any API of libaramid in this callback, a deadlock may occur.

◆ armd_await()

ARMD_EXTERN_C int armd_await ( ARMD_Context context,
ARMD_Handle  handle 
)

Await promise.

This function locks the caller thread and it will not return until the promise is completed.

Parameters
contextThe ARMD_Context which promise belongs to
handleThe ARMD_Handle of the promise to be awaited
Returns
Status code, 0 if succeeded, non-zero if otherwise

◆ armd_context_create()

ARMD_EXTERN_C ARMD_Context* armd_context_create ( const ARMD_MemoryAllocator memory_allocator,
ARMD_Size  num_executors 
)

Create ARMD_Context.

Parameters
memory_allocatorThe memory allocator used everywhere related to this context
num_executorsThe number of executors, in other words, concurrency
Returns
The new ARMD_Context. NULL if failed.

◆ armd_context_destroy()

ARMD_EXTERN_C int armd_context_destroy ( ARMD_Context context)

Destroy ARMD_Context.

Parameters
contextThe ARMD_Context to destroy
Returns
Status code, 0 if succeeded, non-zero if otherwise

◆ armd_detach()

ARMD_EXTERN_C int armd_detach ( ARMD_Context context,
ARMD_Handle  handle 
)

Detach promise.

This function detaches the job.

Parameters
contextThe ARMD_Context which promise belongs to
handleThe ARMD_Handle of the promise to be detached
Returns
Status code, 0 if succeeded, non-zero if otherwise

◆ armd_fork()

ARMD_EXTERN_C int armd_fork ( ARMD_Job parent_job,
ARMD_Procedure procedure,
void *  args 
)

Fork and invoke procedure.

This function forks the thread of execution and invoke the procedure in it. The new job is queued into the current executor. Note that the job created by this API is reassigned to another executor by work-stealing system.

Parameters
parent_jobThe current ARMD_Job
procedureThe ARMD_Procedure to run
argsThe arguments to pass into ARMD_Procedure
Returns
Status code, 0 if succeeded, non-zero if otherwise

◆ armd_fork_with_id()

ARMD_EXTERN_C int armd_fork_with_id ( ARMD_Size  executor_id,
ARMD_Job parent_job,
ARMD_Procedure procedure,
void *  args 
)

Fork and invoke procedure specifying the executor.

This function forks the thread of execution and invoke the procedure in it. The new job is queued into the executor specified with executor_id. Note that the job created by this API is reassigned to another executor by work-stealing system.

Parameters
executor_idThe id of executor to run procedure in
parent_jobThe current ARMD_Job
procedureThe ARMD_Procedure to run
argsThe arguments to pass into ARMD_Procedure
Returns
Status code, 0 if succeeded, non-zero if otherwise

◆ armd_invoke()

ARMD_EXTERN_C ARMD_Handle armd_invoke ( ARMD_Context context,
ARMD_Procedure procedure,
void *  args,
ARMD_Size  num_dependencies,
const ARMD_Handle dependencies 
)

Invoke procedure.

Parameters
contextThe ARMD_Context to run the procedure in
procedureThe ARMD_Procedure to run
argsThe arguments to pass into ARMD_Procedure
num_dependenciesThe number of elements in dependencies
dependenciesThe array of handles of dependent promises, this should be a valid pointer even if num_dependencies == 0
Returns
The new handle of promise, 0 if failure

◆ armd_job_get_executor_id()

ARMD_EXTERN_C ARMD_Size armd_job_get_executor_id ( ARMD_Job job)

Get the executor id via ARMD_Job.

This function returns the id of executors which is running the job. This is useful for implementing your ARMD_Procedure.

Parameters
jobThe current ARMD_Job
Returns
The executor id

◆ armd_job_get_num_executors()

ARMD_EXTERN_C ARMD_Size armd_job_get_num_executors ( ARMD_Job job)

Get the number of executors in the ARMD_Context via ARMD_Job.

This function returns the number of executors in the ARMD_Context which the job belongs to. This is useful for implementing your ARMD_Procedure.

Parameters
jobThe current ARMD_Job
Returns
The number of executors

◆ armd_memory_allocator_allocate()

ARMD_EXTERN_C void* armd_memory_allocator_allocate ( const ARMD_MemoryAllocator allocator,
ARMD_Size  size 
)

Allocates memory area with ARMD_MemoryAllocator.

Parameters
allocatorThe memory allocator
sizeAllocation size in bytes. It can be zero but not recommended.
Returns
The pointer to allocated memory area. NULL if failed.

◆ armd_memory_allocator_free()

ARMD_EXTERN_C void armd_memory_allocator_free ( const ARMD_MemoryAllocator allocator,
void *  buf 
)

Free memory area allocated with ARMD_MemoryAllocator.

Parameters
allocatorThe memory allocator. It must be the same allocator used on allocation.
bufThe pointer to free. It must be the same pointer returned by armd_memory_allocator_allocate.

◆ armd_memory_allocator_init_default()

ARMD_EXTERN_C void armd_memory_allocator_init_default ( ARMD_MemoryAllocator memory_allocator)

Initialize ARMD_MemoryAllocator with default value.

It initializes ARMD_MemoryAllocator to use the system's malloc and free from stdlib.h

Parameters
memory_allocatorThe memory allocator to initialize

◆ armd_memory_region_allocate()

ARMD_EXTERN_C void* armd_memory_region_allocate ( ARMD_MemoryRegion memory_region,
ARMD_Size  size 
)

Allocates memory area with ARMD_MemoryRegion.

Parameters
allocatorThe memory region
sizeAllocation size in bytes. It can be zero but not recommended.
Returns
The pointer to allocated memory area. NULL if failed.

◆ armd_memory_region_create()

ARMD_EXTERN_C ARMD_MemoryRegion* armd_memory_region_create ( const ARMD_MemoryAllocator memory_allocator)

Create ARMD_MemoryRegion.

Parameters
memory_allocatorThe memory allocator to use
Returns
The pointer to the new ARMD_MemoryRegion. NULL if failed.

◆ armd_memory_region_destroy()

ARMD_EXTERN_C ARMD_Size armd_memory_region_destroy ( ARMD_MemoryRegion memory_region)

Destroy ARMD_MemoryRegion.

Parameters
memory_regionThe memory region to destroy
Returns
the count of freed memory areas

◆ armd_memory_region_free()

ARMD_EXTERN_C void armd_memory_region_free ( ARMD_MemoryRegion memory_region,
void *  buf 
)

Free memory area allocated with ARMD_MemoryRegion.

Parameters
allocatorThe memory region. It must be the same region used on allocation.
bufThe pointer to free. It must be the same pointer returned by armd_memory_region_allocate.

◆ armd_procedure_builder_build_and_destroy()

ARMD_EXTERN_C ARMD_Procedure* armd_procedure_builder_build_and_destroy ( ARMD_ProcedureBuilder procedure_builder)

Build ARMD_Procedure and destroy ARMD_ProcedureBuilder.

Parameters
procedure_builderThe procedure builder to build and destroy
Returns
The pointer to the new ARMD_Procedure. NULL if failed.

◆ armd_procedure_builder_create()

ARMD_EXTERN_C ARMD_ProcedureBuilder* armd_procedure_builder_create ( const ARMD_MemoryAllocator memory_allocator,
ARMD_Size  constant_size,
ARMD_Size  frame_size 
)

Create ARMD_ProcedureBuilder.

Parameters
memory_allocatorThe memory allocator to use
constant_sizeThe size of constant table
frame_sizeThe size of frame
Returns
The pointer to the new ARMD_ProcedureBuilder. NULL if failed.

◆ armd_procedure_builder_destroy()

ARMD_EXTERN_C int armd_procedure_builder_destroy ( ARMD_ProcedureBuilder procedure_builder)

Destroy ARMD_ProcedureBuilder without building ARMD_Procedure.

Parameters
procedure_builderThe procedure builder to destroy
Returns
Status code, 0 if succeeded, non-zero if otherwise

◆ armd_procedure_builder_get_constants()

ARMD_EXTERN_C void* armd_procedure_builder_get_constants ( ARMD_ProcedureBuilder procedure_builder)

Get the pointer to constant table.

Parameters
procedure_builderThe procedure builder
Returns
The pointer to constant table. Always non-NULL.

◆ armd_procedure_builder_get_memory_allocator()

ARMD_EXTERN_C ARMD_MemoryAllocator armd_procedure_builder_get_memory_allocator ( ARMD_ProcedureBuilder procedure_builder)

Get the memory allocator used in ARMD_ProcedureBuilder.

Parameters
procedure_builderThe procedure builder
Returns
The memory allocator used in ARMD_ProcedureBuilder. Always non-NULL.

◆ armd_procedure_destroy()

ARMD_EXTERN_C int armd_procedure_destroy ( ARMD_Procedure procedure)

Destroy ARMD_Procedure.

Parameters
memory_regionThe procedure to destroy
Returns
Status code, 0 if succeeded, non-zero if otherwise

◆ armd_procedure_get_constants()

ARMD_EXTERN_C void* armd_procedure_get_constants ( ARMD_Procedure procedure)

Get the pointer to constant table.

Parameters
procedureThe procedure
Returns
The pointer to constant table. Always non-NULL.

◆ armd_setup()

int armd_setup ( ARMD_ProcedureBuilder builder,
ARMD_SetupFunc  setup_func 
)

Add unwind callback to the procedure.

Adds the unwind callback to the procedure. The unwind callback is called when procedures exit independent of the execution status.

◆ armd_then()

ARMD_EXTERN_C int armd_then ( ARMD_ProcedureBuilder procedure_builder,
ARMD_ContinuationFunc  continuation_func,
void *  continuation_constants,
ARMD_ContinuationConstantsDestroyer  continuation_constants_destroyer,
ARMD_ErrorTrapFunc  error_trap_func,
ARMD_ContinuationFrameCreator  continuation_frame_creator,
ARMD_ContinuationFrameDestroyer  continuation_frame_destroyer 
)

Appends a versatile continuation to the procedure.

The versatile API to add the new continuation at last of the continuation sequence in ARMD_ProcedureBuilder. You should not use this function unless you are implementing scheduling function. armd_then_single and armd_then_sequential_for is much simpler and enough.

◆ armd_then_sequential_for()

ARMD_EXTERN_C int armd_then_sequential_for ( ARMD_ProcedureBuilder procedure_builder,
ARMD_SequentialForCountFunc  sequential_for_count_func,
ARMD_SequentialForContinuationFunc  sequential_for_continuation_func 
)

Appends a sequential-for continuation to the procedure.

Adds a sequential-for continuation at last of the continuation sequence in ARMD_ProcedureBuilder. A sequential-for continuation sequential_for_continuation_func is called repeatedly several times specified by sequential_for_count_func.

◆ armd_then_single()

ARMD_EXTERN_C int armd_then_single ( ARMD_ProcedureBuilder procedure_builder,
ARMD_SingleContinuationFunc  single_continuation_func 
)

Appends a single continuation to the procedure.

Adds a single continuation at last of the continuation sequence in ARMD_ProcedureBuilder. A single continuation is simply called once per invocation.

◆ armd_unwind()

ARMD_EXTERN_C int armd_unwind ( ARMD_ProcedureBuilder procedure_builder,
ARMD_UnwindFunc  unwind_func 
)

Add unwind callback to the procedure.

Adds the unwind callback to the procedure. The unwind callback is called when procedures exit independent of the execution status.