From df65ceee67bc11d6f6daba9bce3142ef55a082c5 Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Wed, 20 Aug 2025 18:11:15 -0400 Subject: [PATCH] Start removing conditional pthreads use. We can treat HAVE_PTHREAD and HAVE_PTHREAD_H as equivalent. But using _PTHREAD_H is a real kludge. --- include/hamlib/rig.h | 4 ---- include/hamlib/rig_state.h | 4 +++- rigs/anytone/anytone.c | 2 -- rigs/dummy/rot_pstrotator.c | 3 --- rigs/dummy/rot_pstrotator.h | 3 --- rigs/flexradio/smartsdr.c | 2 -- rigs/icom/icom.c | 9 --------- rigs/tentec/orion.h | 12 ------------ src/fifo.c | 14 -------------- 9 files changed, 3 insertions(+), 50 deletions(-) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 902bb683c..0502e97ca 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -178,11 +178,7 @@ typedef struct int head; int tail; int flush; // flush flag for stop_morse -#ifdef _PTHREAD_H pthread_mutex_t mutex; -#else - int mutex; -#endif } FIFO_RIG; diff --git a/include/hamlib/rig_state.h b/include/hamlib/rig_state.h index bd1c727c1..5d32089d7 100644 --- a/include/hamlib/rig_state.h +++ b/include/hamlib/rig_state.h @@ -24,8 +24,10 @@ #ifndef _RIG_STATE_H #define _RIG_STATE_H 1 -__BEGIN_DECLS +//#include +//#include +__BEGIN_DECLS /** * \addtogroup rig diff --git a/rigs/anytone/anytone.c b/rigs/anytone/anytone.c index 3945d08f6..426332deb 100644 --- a/rigs/anytone/anytone.c +++ b/rigs/anytone/anytone.c @@ -223,9 +223,7 @@ int anytone_init(RIG *rig) { STATE(rig)->priv = p; p->vfo_curr = RIG_VFO_NONE; -#ifdef HAVE_PTHREAD pthread_mutex_init(&p->mutex, NULL); -#endif } } diff --git a/rigs/dummy/rot_pstrotator.c b/rigs/dummy/rot_pstrotator.c index 69d7c4da1..a4b31d675 100644 --- a/rigs/dummy/rot_pstrotator.c +++ b/rigs/dummy/rot_pstrotator.c @@ -178,7 +178,6 @@ static void readPacket(int sockfd, char *buf, int buf_len, int expected) //if (n > 0) { rig_debug(RIG_DEBUG_VERBOSE, "%s: buf=%s\n", __func__, buf); } } -#if defined(HAVE_PTHREAD) #if 0 typedef struct pstrotator_handler_args_sw { @@ -245,8 +244,6 @@ static void *pstrotator_handler_start(void *arg) return NULL; } -#endif - static int pstrotator_rot_init(ROT *rot) { struct pstrotator_rot_priv_data *priv; diff --git a/rigs/dummy/rot_pstrotator.h b/rigs/dummy/rot_pstrotator.h index 5f85c46b7..509f31382 100644 --- a/rigs/dummy/rot_pstrotator.h +++ b/rigs/dummy/rot_pstrotator.h @@ -40,7 +40,6 @@ extern struct rot_caps pstrotator_caps; extern struct rot_caps netrotctl_caps; -#if defined(HAVE_PTHREAD) typedef struct pstrotator_handler_args_sw { ROT *rot; @@ -55,8 +54,6 @@ typedef struct pstrotator_handler_priv_data_s int sockfd2; } pstrotator_handler_priv_data; -#endif - #endif /* _ROT_PSTROTATOR_H */ diff --git a/rigs/flexradio/smartsdr.c b/rigs/flexradio/smartsdr.c index c24718905..1bbc1da8d 100644 --- a/rigs/flexradio/smartsdr.c +++ b/rigs/flexradio/smartsdr.c @@ -301,7 +301,6 @@ int smartsdr_cleanup(RIG *rig) } #if 0 -#if defined(HAVE_PTHREAD) typedef struct smartsdr_data_handler_args_s { RIG *rig; @@ -370,7 +369,6 @@ static int smartsdr_data_handler_start(RIG *rig) } #endif -#endif /* Example response to "sub slice 0" 511+511+35 diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index 77d3ac80e..85686a68b 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -9049,7 +9049,6 @@ int icom_mW2power(RIG *rig, float *power, unsigned int mwpower, freq_t freq, RETURNFUNC(RIG_OK); } -#if defined(HAVE_PTHREAD) static int icom_parse_spectrum_frame(RIG *rig, size_t length, const unsigned char *frame_data) { @@ -9209,7 +9208,6 @@ static int icom_parse_spectrum_frame(RIG *rig, size_t length, RETURNFUNC(RIG_OK); } -#endif int icom_is_async_frame(RIG *rig, size_t frame_length, const unsigned char *frame) @@ -9262,9 +9260,7 @@ int icom_process_async_frame(RIG *rig, size_t frame_length, // TODO: Disable cache timeout for frequency after first transceive packet once we figure out how to get active VFO reliably with transceive updates // TODO: rig_set_cache_timeout_ms(rig, HAMLIB_CACHE_FREQ, HAMLIB_CACHE_ALWAYS); freq_t freq = (freq_t) from_bcd(frame + 5, (priv->civ_731_mode ? 4 : 5) * 2); -#if defined(HAVE_PTHREAD) rig_fire_freq_event(rig, RIG_VFO_CURR, freq); -#endif #if 0 @@ -9284,9 +9280,7 @@ int icom_process_async_frame(RIG *rig, size_t frame_length, // TODO: Disable cache timeout for frequency after first transceive packet once we figure out how to get active VFO reliably with transceive updates // TODO: rig_set_cache_timeout_ms(rig, HAMLIB_CACHE_MODE, HAMLIB_CACHE_ALWAYS); icom2rig_mode(rig, frame[5], frame[6], &mode, &width); -#if defined(HAVE_PTHREAD) rig_fire_mode_event(rig, RIG_VFO_CURR, mode, width); -#endif if (rs->use_cached_mode != 1) { @@ -9297,8 +9291,6 @@ int icom_process_async_frame(RIG *rig, size_t frame_length, break; -#if defined(HAVE_PTHREAD) - case C_CTL_SCP: if (frame[5] == S_SCP_DAT) { @@ -9306,7 +9298,6 @@ int icom_process_async_frame(RIG *rig, size_t frame_length, } break; -#endif default: rig_debug(RIG_DEBUG_VERBOSE, "%s: transceive cmd unsupported %#2.2x\n", diff --git a/rigs/tentec/orion.h b/rigs/tentec/orion.h index 76772a4c2..cf6c89040 100644 --- a/rigs/tentec/orion.h +++ b/rigs/tentec/orion.h @@ -354,25 +354,13 @@ RIG_MODEL(RIG_MODEL_TT565), .rig_close = tt565_close, .set_freq = tt565_set_freq, -#if defined(HAVE_PTHREAD) .get_freq = tt565_get_freq_cache, -#else -.get_freq = tt565_get_freq, -#endif .set_vfo = tt565_set_vfo, .get_vfo = tt565_get_vfo, .set_mode = tt565_set_mode, -#if defined(HAVE_PTHREAD) .get_mode = tt565_get_mode_cache, -#else -.get_mode = tt565_get_mode, -#endif .set_split_vfo = tt565_set_split_vfo, -#if defined(HAVE_PTHREAD) .get_split_vfo = tt565_get_split_vfo_cache, -#else -.get_split_vfo = tt565_get_split_vfo, -#endif .set_level = tt565_set_level, .get_level = tt565_get_level, .set_mem = tt565_set_mem, diff --git a/src/fifo.c b/src/fifo.c index cd112a9d7..b145bcbd0 100644 --- a/src/fifo.c +++ b/src/fifo.c @@ -8,10 +8,8 @@ void initFIFO(FIFO_RIG *fifo) { fifo->head = 0; fifo->tail = 0; -#ifdef _PTHREAD_H static pthread_mutex_t t = PTHREAD_MUTEX_INITIALIZER; fifo->mutex = t; -#endif } void resetFIFO(FIFO_RIG *fifo) @@ -25,9 +23,7 @@ void resetFIFO(FIFO_RIG *fifo) // return -RIG error if overflow int push(FIFO_RIG *fifo, const char *msg) { -#ifdef _PTHREAD_H pthread_mutex_lock(&fifo->mutex); -#endif int len = strlen(msg); for (int i = 0; i < len; ++i) @@ -57,9 +53,7 @@ int push(FIFO_RIG *fifo, const char *msg) fifo->tail = (fifo->tail + 1) % HAMLIB_FIFO_SIZE; } -#ifdef _PTHREAD_H pthread_mutex_unlock(&fifo->mutex); -#endif return RIG_OK; } @@ -73,9 +67,7 @@ int peek(FIFO_RIG *fifo) if (fifo->tail == fifo->head) { return -1; } -#ifdef _PTHREAD_H pthread_mutex_lock(&fifo->mutex); -#endif char c = fifo->data[fifo->head]; #if 0 @@ -89,9 +81,7 @@ int peek(FIFO_RIG *fifo) fifo->tail); #endif -#ifdef _PTHREAD_H pthread_mutex_unlock(&fifo->mutex); -#endif return c; } @@ -99,9 +89,7 @@ int pop(FIFO_RIG *fifo) { if (fifo->tail == fifo->head) { return -1; } -#ifdef _PTHREAD_H pthread_mutex_lock(&fifo->mutex); -#endif char c = fifo->data[fifo->head]; #if 0 @@ -115,9 +103,7 @@ int pop(FIFO_RIG *fifo) #endif fifo->head = (fifo->head + 1) % HAMLIB_FIFO_SIZE; -#ifdef _PTHREAD_H pthread_mutex_unlock(&fifo->mutex); -#endif return c; }