diff --git a/core/federated/clock-sync.c b/core/federated/clock-sync.c index fdbf0642b..d21c06859 100644 --- a/core/federated/clock-sync.c +++ b/core/federated/clock-sync.c @@ -31,12 +31,15 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef FEDERATED +#ifdef PLATFORM_ZEPHYR +#else +#include +#include +#endif #include #include #include #include -#include -#include #include "platform.h" #include "clock-sync.h" diff --git a/core/federated/federate.c b/core/federated/federate.c index 5f6119582..f55626e7a 100644 --- a/core/federated/federate.c +++ b/core/federated/federate.c @@ -33,6 +33,8 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifdef FEDERATED #ifdef PLATFORM_ARDUINO #error To be implemented. No support for federation on Arduino yet. +#elif PLATFORM_ZEPHYR +#warning Federated support on Zephyr is still experimental. #else #include // inet_ntop & inet_pton #include // Defines getaddrinfo(), freeaddrinfo() and struct addrinfo. @@ -2439,6 +2441,7 @@ void terminate_execution(environment_t* env) { // possibility of deadlock. To ensure this, this // function should NEVER be called while holding any mutex lock. lf_mutex_lock(&outbound_socket_mutex); + // FIXME: Should this be _fed.number_of_outbound_p2p_connections instead? for (int i=0; i < NUMBER_OF_FEDERATES; i++) { // Close outbound connections, in case they have not closed themselves. // This will result in EOF being sent to the remote federate, I think. diff --git a/core/platform/lf_zephyr_support.c b/core/platform/lf_zephyr_support.c index de8e51c23..0b61ee7aa 100644 --- a/core/platform/lf_zephyr_support.c +++ b/core/platform/lf_zephyr_support.c @@ -300,7 +300,7 @@ int _lf_unthreaded_notify_of_event() { #warning "Threaded support on Zephyr is still experimental." // FIXME: What is an appropriate stack size? -#define _LF_STACK_SIZE 1024 +#define _LF_STACK_SIZE 4096 // FIXME: What is an appropriate thread prio? #define _LF_THREAD_PRIORITY 5 @@ -315,7 +315,38 @@ int _lf_unthreaded_notify_of_event() { #define USER_THREADS 0 #endif +#if defined(FEDERATED) && defined(FEDERATED_DECENTRALIZED) +#define RTI_SOCKET_LISTENER_THREAD 1 +#define FEDERATE_SOCKET_LISTENER_THREADS NUMBER_OF_FEDERATES +#define P2P_HANDLER_THREAD 1 + +#elif defined(FEDERATED) && defined(FEDERATED_CENTRALIZED) +#define RTI_SOCKET_LISTENER_THREAD 1 +#define FEDERATE_SOCKET_LISTENER_THREADS 0 +#define P2P_HANDLER_THREAD 0 + +#else +#define RTI_SOCKET_LISTENER_THREAD 0 +#define FEDERATE_SOCKET_LISTENER_THREADS 0 +#define P2P_HANDLER_THREAD 0 +#endif + +#if defined(FEDERATED) && defined(_LF_CLOCK_SYNC_ON) +#define CLOCK_SYNC_THREAD 1 +#else +#define CLOCK_SYNC_THREAD 0 +#endif + +#ifndef WORKERS_NEEDED_FOR_FEDERATE +#define WORKERS_NEEDED_FOR_FEDERATE 0 +#endif + #define NUMBER_OF_THREADS (NUMBER_OF_WORKERS \ + + WORKERS_NEEDED_FOR_FEDERATE \ + + RTI_SOCKET_LISTENER_THREAD \ + + FEDERATE_SOCKET_LISTENER_THREADS \ + + P2P_HANDLER_THREAD \ + + CLOCK_SYNC_THREAD \ + USER_THREADS) K_MUTEX_DEFINE(thread_mutex); diff --git a/include/core/federated/net_util.h b/include/core/federated/net_util.h index fc5c85248..9f6e90d38 100644 --- a/include/core/federated/net_util.h +++ b/include/core/federated/net_util.h @@ -40,12 +40,14 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifdef PLATFORM_ARDUINO #error To be implemented. No support for federation on Arduino yet. +#elif PLATFORM_ZEPHYR +#warning Federated support on Zephyr is still experimental. #else #include -#include #endif #include +#include #include #include "../platform.h" @@ -364,12 +366,14 @@ bool validate_user(const char* user); bool extract_match_group(const char* rti_addr, char* dest, regmatch_t group, int max_len, int min_len, const char* err_msg); + /** * Extract match groups from the rti_addr regex. * @return true if success, else false. */ bool extract_match_groups(const char* rti_addr, char** rti_addr_strs, bool** rti_addr_flags, regmatch_t* group_array, int* gids, int* max_lens, int* min_lens, const char** err_msgs); + /** * Extract the host, port and user from rti_addr. */ diff --git a/include/core/platform/lf_zephyr_support.h b/include/core/platform/lf_zephyr_support.h index d1f132323..225f16ab4 100644 --- a/include/core/platform/lf_zephyr_support.h +++ b/include/core/platform/lf_zephyr_support.h @@ -39,6 +39,8 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include //malloc, calloc, free, realloc #include +#include +#include #define NO_TTY #ifdef LF_THREADED