exceptions4c-pthreads 0.1
Multithreading exception handling for C
Loading...
Searching...
No Matches
exceptions4c-pthreads.c File Reference

Implementation of the thread-safe extension for exceptions4c. More...

#include <stdio.h>
#include <errno.h>
#include <pthread.h>
#include <exceptions4c-pthreads.h>

Macros

#define ASSERT_PTHREAD(message, function, ...)
 Invokes a function and terminates the program on error.
 
#define ASSERT_THAT(cause, message, assertion)
 Causes abnormal program termination depending on assertion.
 

Functions

struct e4c_context * e4c_pthreads_context_supplier (void)
 Supplies a thread-safe exception context.
 

Detailed Description

Implementation of the thread-safe extension for exceptions4c.

Version
0.1.0
Author
Guillermo Calvo
See also
For more information, visit the project on GitHub

Macro Definition Documentation

◆ ASSERT_PTHREAD

#define ASSERT_PTHREAD ( message,
function,
... )
Value:
do { \
const int error_code = function(__VA_ARGS__); \
if (error_code != 0) { \
print_error(message); \
errno = error_code; \
perror(#function); \
abort(); \
} \
} while (false)

Invokes a function and terminates the program on error.

Parameters
messageThe message to print to standard error output.
functionThe function to call.
...The arguments to pass to the function.

◆ ASSERT_THAT

#define ASSERT_THAT ( cause,
message,
assertion )
Value:
do { \
if (!(assertion)) { \
print_error(message); \
if (errno != 0) { \
perror(cause); \
} \
abort(); \
} \
} while (false)

Causes abnormal program termination depending on assertion.

Parameters
assertionThe condition that must be true to avoid termination.
causeThe cause of the problem.
messageThe message to print to standard error output.

Function Documentation

◆ e4c_pthreads_context_supplier()

struct e4c_context * e4c_pthreads_context_supplier ( void )

Supplies a thread-safe exception context.

Note
This function MUST be passed to e4c_set_context_supplier so each thread will get its own exception context.
Returns
The thread-safe exception context.