From e7846b374d25716d35eb49e7235ddd36e22299a7 Mon Sep 17 00:00:00 2001 From: Ed Gonzalez Date: Thu, 15 Jan 2015 09:52:29 -0600 Subject: [PATCH] Add shutdown semaphore for termination instead of endless loop --- DSP_API/main.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/DSP_API/main.c b/DSP_API/main.c index 7313eef..74120c7 100644 --- a/DSP_API/main.c +++ b/DSP_API/main.c @@ -61,6 +61,8 @@ const char* APP_NAME = "FreeDV"; // Name of Application const char* CFG_FILE = "/home/root/FreeDV.cfg"; // Name of associated configuration file +static sem_t shutdown_sem; + /* This structure mirrors the one found in /usr/include/asm/ucontext.h */ typedef struct _sig_ucontext { unsigned long uc_flags; @@ -124,16 +126,20 @@ void setup_segfault_handler(void) // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // main() -int main(void) { +int main(void) +{ + + /* Semaphore will be used to signal end of execution */ + sem_init(&shutdown_sem, 0, 0); setup_segfault_handler(); + SmartSDR_API_Init(); - while(1) { - usleep(100000); - } + /* Wait to be notified of shutdown */ + sem_wait(&shutdown_sem); - return 1; + return 0; }