MEL
Microthread & Execution library
synchronization_macros.h File Reference

Some useful macros for function synchronization. More...

Go to the source code of this file.

Macros

#define SYNCHRONIZED_STATIC(function_name, TRet, args, qualifiers, runnable)
 Declare a static function synchronized with a given runnable. More...
 
#define SYNCHRONIZED_METHOD(function_name, TRet, args, qualifiers, runnable)
 Declare a method synchronized with a given runnable. More...
 

Detailed Description

Some useful macros for function synchronization.

Macro Definition Documentation

◆ SYNCHRONIZED_METHOD

#define SYNCHRONIZED_METHOD (   function_name,
  TRet,
  args,
  qualifiers,
  runnable 
)
Value:
TRet function_name##_sync args qualifiers; \
Future<TRet> function_name( MAKE_PARAMS args ) qualifiers \
{ \
return runnable->execute<TRet>( \
[this, CALL_PARAMS args]() qualifiers \
{ return function_name##_sync( CALL_PARAMS args ); } ); \
}

Declare a method synchronized with a given runnable.

The code need to implement that no sync funcion (so, a normal funcion) which its call is managed by this macro. For example, if we declare a synchronized function as

SYNCHRONIZED_METHOD(
f1,string,(int,float),,sRunnable ) 

, we have to implement the neccesary code for f1_sync, as:

static string f1_sync(int a,float b )
{
return std::to_string(a) + std::to:string(b);
}
Parameters
[in]function_name.funtion to create
[in]TRet.Return type
[in]argsparameter types (without parameter names), in the form (T1,T2,...) [0..10] number of parameters
[in]qualifiersextra function qualifiers. Can be left empty
[in]runnableRunnable (pointer) in which function is executed
Returns
mel::core::Future<TRet>

◆ SYNCHRONIZED_STATIC

#define SYNCHRONIZED_STATIC (   function_name,
  TRet,
  args,
  qualifiers,
  runnable 
)
Value:
static TRet function_name##_sync args qualifiers; \
static Future<TRet> function_name( MAKE_PARAMS args ) qualifiers \
{ \
return runnable->execute<TRet>( \
[CALL_PARAMS args]() qualifiers \
{ return function_name##_sync( CALL_PARAMS args ); } ); \
}

Declare a static function synchronized with a given runnable.

The code need to implement that no sync funcion (so, a normal funcion) which its call is managed by this macro. For example, if we declare a synchronized function as

SYNCHRONIZED_STATIC(
f1,string,(int),noexcept,sRunnable ) 

, we have to implement the neccesary code for f1_sync, as:

static string f1_sync(int v) noexcept
{
return std::to_string(v);
}
Parameters
[in]TRet.Return type
[in]function_name.funtion to create
[in]argsparameter types (without parameter names), in the form (T1,T2,...) [0..10] number of parameters
[in]qualifiersextra function qualifiers. Can be left empty
[in]runnableRunnable (pointer) in which function is executed
Returns
mel::core::Future<TRet>