reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
util.h File Reference
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include "logging_macros.h"

Go to the source code of this file.

Data Structures

struct  lf_stat_ll
 

Macros

#define CONCATENATE_THREE_STRINGS(__string1, __string2, __string3)
 
#define LF_LEVEL(index)
 
#define LF_MAX(X, Y)
 
#define LF_MIN(X, Y)
 
#define LF_MUTEX_INIT(mutex)
 
#define LF_MUTEX_LOCK(mutex)
 
#define LF_MUTEX_UNLOCK(mutex)
 
#define LF_COND_INIT(cond, mutex)
 
#define LF_COND_SIGNAL(cond)
 
#define LF_COND_BROADCAST(cond)
 
#define LF_COND_WAIT(cond)
 
#define LF_CRITICAL_SECTION_ENTER(env)
 
#define LF_CRITICAL_SECTION_EXIT(env)
 

Typedefs

typedef struct lf_stat_ll lf_stat_ll
 

Functions

int lf_fed_id (void)
 
void lf_vprint (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 
void void lf_vprint_log (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 
void void void lf_vprint_debug (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 
void void void void error (const char *msg)
 
void lf_vprint_error (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 
void void lf_vprint_warning (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 
void void void lf_vprint_error_and_exit (const char *format, va_list args) ATTRIBUTE_FORMAT_PRINTF(1
 

Variables

int _lf_my_fed_id
 

Detailed Description

Author
Edward A. Lee
Soroush Bateni

LICENSE

Copyright (c) 2020, The University of California at Berkeley.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

DESCRIPTION

Header file for utility types and functions for Lingua Franca programs.

Macro Definition Documentation

◆ CONCATENATE_THREE_STRINGS

#define CONCATENATE_THREE_STRINGS ( __string1,
__string2,
__string3 )
Value:
__string1 __string2 __string3

A handy macro that can concatenate three strings. Useful in the LF_PRINT_DEBUG macro and lf_print_error functions that want to concatenate a "DEBUG: " or "ERROR: " to the beginning of the message and a new line format
at the end.

◆ LF_COND_BROADCAST

#define LF_COND_BROADCAST ( cond)
Value:
LF_ASSERTN(lf_cond_broadcast(cond), "Condition variable broadcast failed.")
#define LF_ASSERTN(condition, format,...)
Definition logging_macros.h:95
int lf_cond_broadcast(lf_cond_t *cond)
Definition lf_POSIX_threads_support.c:53

Broadcast a condition variable with error checking. This is optimized away if the NDEBUG flag is defined.

Parameters
condPointer to the condition variable.

◆ LF_COND_INIT

#define LF_COND_INIT ( cond,
mutex )
Value:
LF_ASSERTN(lf_cond_init(cond, mutex), "Condition variable init failed.")
int lf_cond_init(lf_cond_t *cond, lf_mutex_t *mutex)
Definition lf_POSIX_threads_support.c:44

Initialize condition variable with error checking. This is optimized away if the NDEBUG flag is defined.

Parameters
condPointer to the condition variable to initialize.
mutexPointer to the mutex to associate with the condition variable.

◆ LF_COND_SIGNAL

#define LF_COND_SIGNAL ( cond)
Value:
LF_ASSERTN(lf_cond_signal(cond), "Condition variable signal failed.")
int lf_cond_signal(lf_cond_t *cond)
Definition lf_POSIX_threads_support.c:55

Signal a condition variable with error checking. This is optimized away if the NDEBUG flag is defined.

Parameters
condPointer to the condition variable.

◆ LF_COND_WAIT

#define LF_COND_WAIT ( cond)
Value:
LF_ASSERTN(lf_cond_wait(cond), "Condition variable wait failed.")
int lf_cond_wait(lf_cond_t *cond)
Definition lf_POSIX_threads_support.c:57

Wait on a condition variable with error checking. This is optimized away if the NDEBUG flag is defined.

Parameters
condPointer to the condition variable.

◆ LF_CRITICAL_SECTION_ENTER

#define LF_CRITICAL_SECTION_ENTER ( env)
Value:
LF_ASSERT(!lf_critical_section_enter(env), "Could not enter critical section")
#define LF_ASSERT(condition, format,...)
Definition logging_macros.h:88
int lf_critical_section_enter(environment_t *env)
Enter critical section by locking the global mutex.
Definition reactor_threaded.c:1153

Enter critical section with error checking. This is optimized away if the NDEBUG flag is defined.

Parameters
envPointer to the environment.

◆ LF_CRITICAL_SECTION_EXIT

#define LF_CRITICAL_SECTION_EXIT ( env)
Value:
LF_ASSERT(!lf_critical_section_exit(env), "Could not exit critical section")
int lf_critical_section_exit(environment_t *env)
Leave a critical section by unlocking the global mutex.
Definition reactor_threaded.c:1165

Exit critical section with error checking. This is optimized away if the NDEBUG flag is defined.

Parameters
envPointer to the environment.

◆ LF_LEVEL

#define LF_LEVEL ( index)
Value:
(index & 0xffffLL)

Macro for extracting the level from the index of a reaction. A reaction that has no upstream reactions has level 0. Other reactions have a level that is the length of the longest upstream chain to a reaction with level 0 (inclusive). This is used, along with the deadline, to sort reactions in the reaction queue. It ensures that reactions that are upstream in the dependence graph execute before reactions that are downstream.

◆ LF_MAX

#define LF_MAX ( X,
Y )
Value:
(((X) > (Y)) ? (X) : (Y))

Utility for finding the maximum of two values.

◆ LF_MIN

#define LF_MIN ( X,
Y )
Value:
(((X) < (Y)) ? (X) : (Y))

Utility for finding the minimum of two values.

◆ LF_MUTEX_INIT

#define LF_MUTEX_INIT ( mutex)
Value:
LF_ASSERTN(lf_mutex_init(mutex), "Mutex init failed.")
int lf_mutex_init(lf_mutex_t *mutex)
Definition lf_POSIX_threads_support.c:21

Initialize mutex with error checking. This is optimized away if the NDEBUG flag is defined.

Parameters
mutexPointer to the mutex to initialize.

◆ LF_MUTEX_LOCK

#define LF_MUTEX_LOCK ( mutex)
Value:
LF_ASSERTN(lf_mutex_lock(mutex), "Mutex lock failed.")
int lf_mutex_lock(lf_mutex_t *mutex)
Definition lf_POSIX_threads_support.c:40

Lock mutex with error checking. This is optimized away if the NDEBUG flag is defined.

Parameters
mutexPointer to the mutex to lock.

◆ LF_MUTEX_UNLOCK

#define LF_MUTEX_UNLOCK ( mutex)
Value:
LF_ASSERTN(lf_mutex_unlock(mutex), "Mutex unlock failed.")
int lf_mutex_unlock(lf_mutex_t *mutex)
Definition lf_POSIX_threads_support.c:42

Unlock mutex with error checking. This is optimized away if the NDEBUG flag is defined.

Parameters
mutexPointer to the mutex to unlock.

Typedef Documentation

◆ lf_stat_ll

typedef struct lf_stat_ll lf_stat_ll

Holds generic statistical data

Function Documentation

◆ error()

void void void void error ( const char * msg)

Print the error defined by the errno variable with the specified message as a prefix, then exit with error code 1.

Parameters
msgThe prefix to the message.

◆ lf_fed_id()

int lf_fed_id ( void )

Return the federate ID or -1 if this program is not part of a federation.

◆ lf_vprint()

void lf_vprint ( const char * format,
va_list args )

varargs alternative of "lf_print"

◆ lf_vprint_debug()

void void void lf_vprint_debug ( const char * format,
va_list args )

varargs alternative of "lf_print_debug"

◆ lf_vprint_error()

void lf_vprint_error ( const char * format,
va_list args )

varargs alternative of "lf_print_error"

◆ lf_vprint_error_and_exit()

void void void lf_vprint_error_and_exit ( const char * format,
va_list args )

varargs alternative of "lf_print_error_and_exit"

◆ lf_vprint_log()

void void lf_vprint_log ( const char * format,
va_list args )

varargs alternative of "lf_print_log"

◆ lf_vprint_warning()

void void lf_vprint_warning ( const char * format,
va_list args )

varargs alternative of "lf_print_warning"

Variable Documentation

◆ _lf_my_fed_id

int _lf_my_fed_id
extern

The ID of this federate. For a non-federated execution, this will be -1. For a federated execution, it will be assigned when the generated function _lf_initialize_trigger_objects() is called.

See also
xtext/org.icyphy.linguafranca/src/org/icyphy/generator/CGenerator.xtend.

The ID of this federate. For a non-federated execution, this will be -1. For a federated execution, it will be assigned in the generated code.