Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaner namespace #189

Merged
merged 12 commits into from
Apr 12, 2023
1 change: 1 addition & 0 deletions core/federated/RTI/message_record/message_record.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***************/

#include "message_record.h"
#include "platform.h"
#include <stdlib.h>

/**
Expand Down
1 change: 1 addition & 0 deletions core/federated/RTI/message_record/rti_pqueue_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "tag.h"
#include "utils/pqueue.h"
#include "utils/util.h"
#include "platform.h"

// ********** Priority Queue Support Start
/**
Expand Down
4 changes: 3 additions & 1 deletion core/federated/RTI/rti_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "rti_lib.h"
#include "string.h"

/**
* The state of this RTI instance.
*/
Expand Down Expand Up @@ -2032,4 +2034,4 @@ int process_args(int argc, const char* argv[]) {
return 0;
}
return 1;
}
}
1 change: 1 addition & 0 deletions core/federated/clock-sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sys/socket.h>
#include <netinet/in.h>

#include "platform.h"
#include "clock-sync.h"
#include "net_common.h"
#include "net_util.h"
Expand Down
3 changes: 2 additions & 1 deletion core/federated/federate.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> // Defines read(), write(), and close()
#include <string.h>

#include "clock-sync.h"
#include "federate.h"
Expand Down Expand Up @@ -2940,4 +2941,4 @@ parse_rti_code_t parse_rti_addr(const char* rti_addr) {
void set_federation_id(const char* fid) {
federation_metadata.federation_id = fid;
}
#endif
#endif
1 change: 1 addition & 0 deletions core/modal_models/modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <string.h>

#include "platform.h"
#include "lf_types.h"
#include "modes.h"
#include "reactor_common.h"
Expand Down
1 change: 1 addition & 0 deletions core/platform/lf_unix_clock_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <time.h>
#include <errno.h>

#include "platform.h"
#include "lf_unix_clock_support.h"

/**
Expand Down
11 changes: 5 additions & 6 deletions core/platform/lf_windows_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @see https://gist.github.com/Soroosh129/127d1893fa4c1da6d3e1db33381bb273
*/

#include <windows.h>
#include <windows.h> // Order in which windows.h is included does matter!
#include <errno.h>
#include <process.h>
#include <sysinfoapi.h>
#include <errno.h>
#include <time.h>

#include "lf_windows_support.h"
#include "platform.h"
#include "util.h"
#include "tag.h"
#include <time.h>
#include "util.h"

/**
* Indicate whether or not the underlying hardware
Expand All @@ -59,8 +60,6 @@ double _lf_frequency_to_ns = 1.0;

#define LF_MIN_SLEEP_NS USEC(10)

#define BILLION 1000000000

#if defined LF_THREADED || defined _LF_TRACE

/**
Expand Down
1 change: 1 addition & 0 deletions core/reactor_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

#include "platform.h"
#include "lf_types.h"
Expand Down
2 changes: 2 additions & 0 deletions core/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "tag.h"
#include "util.h"
#include "platform.h"
#include "util.h"

// Global variables :(

Expand Down
2 changes: 1 addition & 1 deletion core/threaded/reactor_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,4 +1192,4 @@ int lf_critical_section_enter() {
int lf_critical_section_exit() {
return lf_mutex_unlock(&mutex);
}
#endif
#endif
1 change: 1 addition & 0 deletions core/utils/pqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <assert.h>
#include <stdbool.h>

#include "platform.h"
#include "pqueue.h"
#include "util.h"
#include "lf_types.h"
Expand Down
1 change: 1 addition & 0 deletions include/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef API_H
#define API_H

#include <stdio.h> // Included for backwards compatibility so that users do not need to explicitly include this
#include "lf_types.h"
#include "tag.h"

Expand Down
4 changes: 3 additions & 1 deletion include/core/federated/federate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef FEDERATE_H
#define FEDERATE_H

#include <stdbool.h>

#include "tag.h"
#include "lf_types.h"
#include <stdbool.h>
#include "platform.h"

#ifndef ADVANCE_MESSAGE_INTERVAL
#define ADVANCE_MESSAGE_INTERVAL MSEC(10)
Expand Down
1 change: 0 additions & 1 deletion include/core/lf_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

#include "modal_models/modes.h" // Modal model support
#include "utils/pqueue.h"
#include "platform.h"
#include "tag.h"
#include "lf_token.h"

Expand Down
2 changes: 1 addition & 1 deletion include/core/modal_models/modes.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stddef.h>
#include <stdbool.h>

#include "platform.h"
#include "lf_types.h"
#include "tag.h"

typedef struct event_t event_t;
typedef struct reaction_t reaction_t;
Expand Down
25 changes: 2 additions & 23 deletions include/core/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* This file detects the platform on which the C compiler is being run
* (e.g. Windows, Linux, Mac) and conditionally includes platform-specific
* files that define core datatypes and function signatures for Lingua Franca.
* For example, the type instant_t represents a time value (long long on
* most of the platforms). The conditionally included files define a type
* _instant_t, and this file defines the type instant_t to be whatever
* the included defines _instant_t to be. All platform-independent code
* in Lingua Franca, therefore, should use the type instant_t for time
* values.
*
* @author{Soroush Bateni <[email protected]>}
*/

#ifndef PLATFORM_H
#define PLATFORM_H

#include "lf_types.h"

#if defined(LF_THREADED) && defined(LF_UNTHREADED)
#error LF_UNTHREADED and LF_THREADED runtime requested
#endif
Expand Down Expand Up @@ -85,23 +81,6 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#define LF_TIMEOUT _LF_TIMEOUT


/**
* Time instant. Both physical and logical times are represented
* using this typedef.
*/
typedef _instant_t instant_t;

/**
* Interval of time.
*/
typedef _interval_t interval_t;

/**
* Microstep instant.
*/
typedef _microstep_t microstep_t;

/**
* Enter a critical section where logical time and the event queue are guaranteed
* to not change unless they are changed within the critical section.
Expand Down
16 changes: 0 additions & 16 deletions include/core/platform/lf_arduino_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,4 @@ extern lf_cond_t event_q_changed;
// Arduinos are embedded platforms with no tty
#define NO_TTY

/**
* Time instant. Both physical and logical times are represented
* using this typedef.
*/
typedef int64_t _instant_t;

/**
* Interval of time.
*/
typedef int64_t _interval_t;

/**
* Microstep instant.
*/
typedef uint32_t _microstep_t;

#endif // LF_ARDUINO_SUPPORT_H
12 changes: 0 additions & 12 deletions include/core/platform/lf_nrf52_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define PRINTF_MICROSTEP "%" PRIu32
#define PRINTF_TAG "(%" PRId64 ", %" PRIu32 ")"

typedef int64_t _instant_t;

/**
* Interval of time.
*/
typedef int64_t _interval_t;

/**
* Microstep instant.
*/
typedef uint32_t _microstep_t;

/**
* No mutex or condition variable needed for single threaded NRF platforms
*/
Expand Down
20 changes: 1 addition & 19 deletions include/core/platform/lf_tag_64_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// If you are targeting a platform that uses some other type
// for time and microsteps, you can simply define
// PRINTF_TIME and PRINTF_MICROSTEP directly in the same file that
// defines the types _instant_t, _interval_t, and _microstep_t.
// defines the types instant_t, interval_t, and microstep_t.
#include <inttypes.h>
#define PRINTF_TIME "%" PRId64
#define PRINTF_MICROSTEP "%" PRIu32
Expand All @@ -48,24 +48,6 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// printf("Tag is " PRINTF_TAG "\n", time_value, microstep);
#define PRINTF_TAG "(" PRINTF_TIME ", " PRINTF_MICROSTEP ")"

/**
* Time instant. Both physical and logical times are represented
* using this typedef.
* WARNING: If this code is used after about the year 2262,
* then representing time as a 64-bit long long will be insufficient.
*/
typedef int64_t _instant_t;

/**
* Interval of time.
*/
typedef int64_t _interval_t;

/**
* Microstep instant.
*/
typedef uint32_t _microstep_t;

/**
* For user-friendly reporting of time values, the buffer length required.
* This is calculated as follows, based on 64-bit time in nanoseconds:
Expand Down
9 changes: 5 additions & 4 deletions include/core/platform/lf_windows_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define _LF_TIMEOUT ETIMEDOUT
// Use 64-bit times and 32-bit unsigned microsteps
#include "lf_tag_64_32.h"
#include "tag.h"

// Forward declare lf_clock_gettime which is needed by lf_cond_timedwait
extern int lf_clock_gettime(_instant_t* t);
extern int lf_clock_gettime(instant_t* t);

#if defined LF_THREADED || defined _LF_TRACE
#if __STDC_VERSION__ < 201112L || defined (__STDC_NO_THREADS__) // (Not C++11 or later) or no threads support
Expand Down Expand Up @@ -218,11 +219,11 @@ static int lf_cond_wait(lf_cond_t* cond) {
*
* @return 0 on success and LF_TIMEOUT on timeout, 1 otherwise.
*/
static int lf_cond_timedwait(lf_cond_t* cond, _instant_t absolute_time_ns) {
static int lf_cond_timedwait(lf_cond_t* cond, instant_t absolute_time_ns) {
// Convert the absolute time to a relative time
_instant_t current_time_ns;
instant_t current_time_ns;
lf_clock_gettime(&current_time_ns);
_interval_t relative_time_ns = (absolute_time_ns - current_time_ns);
interval_t relative_time_ns = (absolute_time_ns - current_time_ns);
if (relative_time_ns <= 0) {
// physical time has already caught up sufficiently and we do not need to wait anymore
return 0;
Expand Down
16 changes: 0 additions & 16 deletions include/core/platform/lf_zephyr_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,6 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define PRINTF_TAG "(" PRINTF_TIME ", " PRINTF_MICROSTEP ")"
#define _LF_TIMEOUT 1

/**
* Time instant. Both physical and logical times are represented
* using this typedef.
*/
typedef int64_t _instant_t;

/**
* Interval of time.
*/
typedef int64_t _interval_t;

/**
* Microstep instant.
*/
typedef uint32_t _microstep_t;

#ifdef LF_THREADED

typedef struct k_mutex lf_mutex_t;
Expand Down
1 change: 0 additions & 1 deletion include/core/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
#include <stdlib.h>
#include <stdbool.h>
#include "lf_token.h" // Defines token types and lf_port_base_t, lf_sparse_io_record
#include "utils/vector.h"

/** Threshold for width of multiport s.t. sparse reading is supported. */
#define LF_SPARSE_WIDTH_THRESHOLD 10
Expand Down
10 changes: 0 additions & 10 deletions include/core/reactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,9 @@
#ifndef REACTOR_H
#define REACTOR_H

#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "lf_types.h"
#include "lf_token.h"
#include "modes.h" // Modal model support
#include "platform.h" // Platform-specific times and APIs
#include "port.h"
#include "pqueue.h"
#include "tag.h" // Time-related functions.
#include "trace.h"
#include "util.h"
Expand Down
Loading