Make set_transaction functions use intra process mutex -- Phase 1

Phase 2 will be inter-process named mutexes
https://github.com/Hamlib/Hamlib/issues/942
pull/948/head
Mike Black W9MDB 2022-01-23 09:01:06 -06:00
rodzic 388738b78b
commit 1beebfc835
3 zmienionych plików z 16 dodań i 4 usunięć

Wyświetl plik

@ -33,6 +33,10 @@
#include <inttypes.h>
#include <time.h>
#include <sys/time.h>
#include "config.h"
#ifdef HAVE_PTHREAD
#include <pthread.h>
#endif
/* Rig list is in a separate file so as not to mess up w/ this one */
#include <hamlib/riglist.h>
@ -2447,6 +2451,9 @@ struct rig_state {
void *async_data_handler_priv_data;
volatile int poll_routine_thread_run;
void *poll_routine_priv_data;
#ifdef HAVE_PTHREAD
pthread_mutex_t mutex_set_transaction;
#endif
};
//! @cond Doxygen_Suppress

Wyświetl plik

@ -26,13 +26,15 @@
/*
* Careful!! These macros are NOT reentrant!
* ie. they may not be executed atomically,
* thus not ensure mutual exclusion.
* Fix it when making Hamlib reentrant! --SF
*/
#ifdef HAVE_PTHREAD
#include <pthread.h>
#define set_transaction_active(rig) {pthread_mutex_lock(&rig->state.mutex_set_transaction);(rig)->state.transaction_active = 1;}
#define set_transaction_inactive(rig) {(rig)->state.transaction_active = 0;pthread_mutex_unlock(&rig->state.mutex_set_transaction);}
#else
#define set_transaction_active(rig) {(rig)->state.transaction_active = 1;}
#define set_transaction_inactive(rig) {(rig)->state.transaction_active = 0;}
#endif
__BEGIN_DECLS

Wyświetl plik

@ -451,6 +451,9 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model)
* TODO: read the Preferences here!
*/
rs = &rig->state;
#ifdef HAVE_PTHREAD
pthread_mutex_init(&rs->mutex_set_transaction, NULL);
#endif
rs->async_data_enabled = 0;
rs->rigport.fd = -1;