Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs
Reentrant

Data Structures

struct  sol_reentrant
 Structure containing the flags for safely freeing a larger structure. More...
 

Macros

#define SOL_REENTRANT_CALL(handle)
 Wraps a function call to an external callback. More...
 
#define SOL_REENTRANT_FREE(reentrant)   if (({ (reentrant).delete_me = true; !(reentrant).in_use; }))
 Conditionally free a reentrant structure. More...
 

Typedefs

typedef struct sol_reentrant sol_reentrant
 Structure containing the flags for safely freeing a larger structure. More...
 

Detailed Description

Macro Definition Documentation

#define SOL_REENTRANT_CALL (   handle)
Value:
for (bool reentrant_run = true; reentrant_run; reentrant_run = false) \
for (bool reentrant_was_used = (handle).in_use; reentrant_run; \
(handle).in_use = reentrant_was_used, reentrant_run = false) \
for ((handle).in_use = true; reentrant_run; reentrant_run = false)

Wraps a function call to an external callback.

Parameters
handleThe reentrant tracking the structure affected by the function call

Wraps the statement or statement block following it by marking the handle passed in as the parameter as being in use. Thus, if you call an external callback from within the block which attempts to free the structure, the structure will be protected from deletion by the flags set in the preamble. For example:

SO_REENTRANT_CALL(context->reentrant) {
context->cb(context->data);
context->cb_was_called = true;
}

will ensure that the context will not be freed as part of the call to context->cb() and will be available after context->cb() returns as long as all calls to free the context are made via SOL_REENTRANT_FREE().

Examples:
/src/samples/design_patterns/stream_sample.c.

Referenced by _inform_user().

#define SOL_REENTRANT_FREE (   reentrant)    if (({ (reentrant).delete_me = true; !(reentrant).in_use; }))

Conditionally free a reentrant structure.

Parameters
reentrantThe reentrant to free

Provides a condition statement for calling the function that frees the structure associated with the reentrant passed in as the parameter. As a side effect it also marks the structure as needing deletion.

Examples:
/src/samples/design_patterns/stream_sample.c.

Referenced by _inform_user(), and my_stream_api_close().

Typedef Documentation

typedef struct sol_reentrant sol_reentrant

Structure containing the flags for safely freeing a larger structure.

This structure is meant to be used inside larger structures which are affected by calls to external callbacks that in turn end up calling library APIs. The possibility of a double free is particularly likely in such cases.