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)   __string1 __string2 __string3
 
#define LF_LEVEL(index)   (index & 0xffffLL)
 
#define LF_MAX(X, Y)   (((X) > (Y)) ? (X) : (Y))
 
#define LF_MIN(X, Y)   (((X) < (Y)) ? (X) : (Y))
 
#define LF_MUTEX_INIT(mutex)   LF_ASSERTN(lf_mutex_init(mutex), "Mutex init failed.")
 
#define LF_MUTEX_LOCK(mutex)   LF_ASSERTN(lf_mutex_lock(mutex), "Mutex lock failed.")
 
#define LF_MUTEX_UNLOCK(mutex)   LF_ASSERTN(lf_mutex_unlock(mutex), "Mutex unlock failed.")
 
#define LF_COND_INIT(cond, mutex)   LF_ASSERTN(lf_cond_init(cond, mutex), "Condition variable init failed.")
 
#define LF_COND_SIGNAL(cond)   LF_ASSERTN(lf_cond_signal(cond), "Condition variable signal failed.")
 
#define LF_COND_BROADCAST(cond)   LF_ASSERTN(lf_cond_broadcast(cond), "Condition variable broadcast failed.")
 
#define LF_COND_WAIT(cond)   LF_ASSERTN(lf_cond_wait(cond), "Condition variable wait failed.")
 
#define LF_CRITICAL_SECTION_ENTER(env)   LF_ASSERT(!lf_critical_section_enter(env), "Could not enter critical section")
 
#define LF_CRITICAL_SECTION_EXIT(env)   LF_ASSERT(!lf_critical_section_exit(env), "Could not exit critical section")
 

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.

Functions intitializing and freeing memory for environments.

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

Macro Definition Documentation

◆ CONCATENATE_THREE_STRINGS

#define CONCATENATE_THREE_STRINGS ( __string1,
__string2,
__string3 )   __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)    LF_ASSERTN(lf_cond_broadcast(cond), "Condition variable broadcast failed.")

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 )   LF_ASSERTN(lf_cond_init(cond, mutex), "Condition variable init failed.")

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)    LF_ASSERTN(lf_cond_signal(cond), "Condition variable signal failed.")

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)    LF_ASSERTN(lf_cond_wait(cond), "Condition variable wait failed.")

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)    LF_ASSERT(!lf_critical_section_enter(env), "Could not enter critical section")

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)    LF_ASSERT(!lf_critical_section_exit(env), "Could not exit critical section")

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)    (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 )   (((X) > (Y)) ? (X) : (Y))

Utility for finding the maximum of two values.

◆ LF_MIN

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

Utility for finding the minimum of two values.

◆ LF_MUTEX_INIT

#define LF_MUTEX_INIT ( mutex)    LF_ASSERTN(lf_mutex_init(mutex), "Mutex init failed.")

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)    LF_ASSERTN(lf_mutex_lock(mutex), "Mutex lock failed.")

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)    LF_ASSERTN(lf_mutex_unlock(mutex), "Mutex unlock failed.")

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.