Skip to content

Commit

Permalink
[This commit contains highly-experimental and possibly unstable alter…
Browse files Browse the repository at this point in the history
…ations to core archeitcture on dvmhost] deprecate ThreadFunc (using C++ lambda's was a bad idea to begin with); refactor some startup messages; refactor use of ThreadFunc in FNE; refactor how threads were created in the FNE; [EXPERIMENTAL] refactor the host architecture to use threading for modem clocking and protocol readers;
  • Loading branch information
gatekeep committed Jul 16, 2024
1 parent 4ba65c5 commit 355db0c
Show file tree
Hide file tree
Showing 22 changed files with 1,903 additions and 1,292 deletions.
4 changes: 2 additions & 2 deletions src/common/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ typedef unsigned long long ulong64_t;
#define __EXE_NAME__ ""

#define VERSION_MAJOR "04"
#define VERSION_MINOR "01"
#define VERSION_REV "B"
#define VERSION_MINOR "02"
#define VERSION_REV "C"

#define __NETVER__ "DVM_R" VERSION_MAJOR VERSION_REV VERSION_MINOR
#define __VER__ VERSION_MAJOR "." VERSION_MINOR VERSION_REV " (R" VERSION_MAJOR VERSION_REV VERSION_MINOR " " __GIT_VER__ ")"
Expand Down
22 changes: 20 additions & 2 deletions src/common/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2015,2016 Jonathan Naylor, G4KLX
* Copyright (C) 2023 Bryan Biedenkapp, N2PLL
* Copyright (C) 2023,2024 Bryan Biedenkapp, N2PLL
*
*/
#include "Thread.h"
Expand Down Expand Up @@ -82,7 +82,25 @@ void Thread::detach()
::pthread_detach(m_thread);
}

/* Helper to sleep the current thread. */
/* Executes the specified start routine to run as a thread. */

bool Thread::runAsThread(void* obj, void *(*startRoutine)(void *), thread_t* thread)
{
if (thread == nullptr)
thread = new thread_t();

thread->obj = obj;

if (::pthread_create(&thread->thread, NULL, startRoutine, thread) != 0) {
LogError(LOG_NET, "Error returned from pthread_create, err: %d", errno);
delete thread;
return false;
}

return true;
}

/* Suspends the current thread for the specified amount of time. */

void Thread::sleep(uint32_t ms, uint32_t us)
{
Expand Down
26 changes: 24 additions & 2 deletions src/common/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2015,2016 Jonathan Naylor, G4KLX
* Copyright (C) 2023 Bryan Biedenkapp, N2PLL
* Copyright (C) 2023,2024 Bryan Biedenkapp, N2PLL
*
*/
/**
Expand All @@ -27,6 +27,19 @@

#include <pthread.h>

// ---------------------------------------------------------------------------
// Structure Declaration
// ---------------------------------------------------------------------------

/**
* @brief Represents the data passed to a thread runner.
* @ingroup common
*/
struct thread_t {
void* obj; //! Object that created this thread.
pthread_t thread; //! Thread Handle.
};

// ---------------------------------------------------------------------------
// Class Declaration
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -75,7 +88,16 @@ class HOST_SW_API Thread {
virtual void detach();

/**
* @brief Helper to sleep the current thread.
* @brief Executes the specified start routine to run as a thread.
* @param obj Instance of a object to pass to the threaded function.
* @param startRoutine Represents the function that executes on a thread.
* @param[out] thread Instance of the thread data.
* @returns bool True, if successful, otherwise error occurred.
*/
static bool runAsThread(void* obj, void *(*startRoutine)(void *), thread_t* thread = nullptr);

/**
* @brief Suspends the current thread for the specified amount of time.
* @param ms Time in milliseconds to sleep.
* @param us Time in microseconds to sleep.
*/
Expand Down
55 changes: 0 additions & 55 deletions src/common/ThreadFunc.h

This file was deleted.

13 changes: 10 additions & 3 deletions src/dfsi/Dfsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace lookups;
#include <functional>
#include <random>

#include <sys/utsname.h>
#include <unistd.h>
#include <pwd.h>

Expand Down Expand Up @@ -152,8 +153,6 @@ int Dfsi::run()
if (!ret)
return EXIT_FAILURE;

::LogInfoEx(LOG_HOST, "DFSI peer network is up and running");

std::string dfsiModeStr = "Unknown";

switch (dfsiMode) {
Expand Down Expand Up @@ -195,7 +194,15 @@ int Dfsi::run()
StopWatch stopWatch;
stopWatch.start();

// main execution loop
/*
** Main execution loop
*/

struct utsname utsinfo;
::memset(&utsinfo, 0, sizeof(utsinfo));
::uname(&utsinfo);

::LogInfoEx(LOG_HOST, "[ OK ] DFSI is up and running on %s %s %s", utsinfo.sysname, utsinfo.release, utsinfo.machine);
while (!g_killed) {
uint32_t ms = stopWatch.elapsed();

Expand Down
6 changes: 3 additions & 3 deletions src/dfsi/DfsiMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ int main(int argc, char** argv)
delete dfsi;

if (g_signal == 2)
::LogInfoEx(LOG_HOST, "Exited on receipt of SIGINT");
::LogInfoEx(LOG_HOST, "[STOP] dvmdfsi:main SIGINT");

if (g_signal == 15)
::LogInfoEx(LOG_HOST, "Exited on receipt of SIGTERM");
::LogInfoEx(LOG_HOST, "[STOP] dvmdfsi:main SIGTERM");

if (g_signal == 1)
::LogInfoEx(LOG_HOST, "Restarting on receipt of SIGHUP");
::LogInfoEx(LOG_HOST, "[RSTR] dvmdfsi:main SIGHUP");
} while (g_signal == 1);

::LogFinalise();
Expand Down
6 changes: 3 additions & 3 deletions src/fne/FNEMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ int main(int argc, char** argv)
delete fne;

if (g_signal == 2)
::LogInfoEx(LOG_HOST, "Exited on receipt of SIGINT");
::LogInfoEx(LOG_HOST, "[STOP] dvmfne:main SIGINT");

if (g_signal == 15)
::LogInfoEx(LOG_HOST, "Exited on receipt of SIGTERM");
::LogInfoEx(LOG_HOST, "[STOP] dvmfne:main SIGTERM");

if (g_signal == 1)
::LogInfoEx(LOG_HOST, "Restarting on receipt of SIGHUP");
::LogInfoEx(LOG_HOST, "[RSTR] dvmfne:main SIGHUP");
} while (g_signal == 1);

::LogFinalise();
Expand Down
Loading

0 comments on commit 355db0c

Please sign in to comment.