Add rig_lock and rig_unlock to support serial I/O locking for a transaction

https://github.com/Hamlib/Hamlib/issues/695
pull/875/head
Mike Black W9MDB 2021-11-15 07:16:31 -06:00
rodzic 3502852d42
commit 3de368f6a2
4 zmienionych plików z 30 dodań i 10 usunięć

Wyświetl plik

@ -3181,6 +3181,10 @@ extern HAMLIB_EXPORT(int) hl_usleep(rig_useconds_t msec);
extern HAMLIB_EXPORT(int) rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie, int cookie_len);
// two functions globally accessible so rig backends can lock for an I/O transaction
void rig_lock();
void rig_unlock();
//! @endcond
__END_DECLS

Wyświetl plik

@ -621,6 +621,7 @@ static int netrigctl_open(RIG *rig)
rs->mode_list |= rs->tx_range_list[i].modes;
rs->vfo_list |= rs->tx_range_list[i].vfo;
}
if (rs->vfo_list == 0) rs->vfo_list = RIG_VFO_A|RIG_VFO_B;
if (prot_ver == 0) { return RIG_OK; }

Wyświetl plik

@ -445,15 +445,11 @@ void *multicast_server(void *arg)
if (rig->caps->get_freq)
{
sync_callback(1);
retval = rig_get_freq(rig, RIG_VFO_A, &freqMain);
sync_callback(0);
if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s(%d): rig_get_freqA error %s\n", __FILE__, __LINE__, rigerror(retval)); }
sync_callback(1);
retval = rig_get_freq(rig, RIG_VFO_B, &freqSub);
sync_callback(0);
if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s(%d): rig_get_freqB error %s\n", __FILE__, __LINE__, rigerror(retval)); }
@ -470,15 +466,11 @@ void *multicast_server(void *arg)
if (rig->caps->get_mode)
{
sync_callback(1);
retval = rig_get_mode(rig, RIG_VFO_A, &modeMain, &widthMain);
sync_callback(0);
if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s(%d): rig_get_modeA error %s\n", __FILE__, __LINE__, rigerror(retval)); }
sync_callback(1);
retval = rig_get_mode(rig, RIG_VFO_B, &modeSub, &widthSub);
sync_callback(0);
if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s(%d): rig_get_modeB error %s\n", __FILE__, __LINE__, rigerror(retval)); }
@ -506,9 +498,7 @@ void *multicast_server(void *arg)
if (rig->caps->get_split_vfo)
{
vfo_t tx_vfo;
sync_callback(1);
retval = rig_get_split_vfo(rig, RIG_VFO_A, &split, &tx_vfo);
sync_callback(0);
if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s(%d): rig_get_modeA error %s\n", __FILE__, __LINE__, rigerror(retval)); }

Wyświetl plik

@ -202,6 +202,31 @@ static const char *const rigerror_table[] =
#define ERROR_TBL_SZ (sizeof(rigerror_table)/sizeof(char *))
#ifdef HAVE_PTHREAD
// Any call to rig_set or rig_get functions will lock the rig
// for non-targetable rigs this will still be problematic for rigctld
// in non-vfo mode as a transaction may be set_vfo/set_x/set_vfo
// this would require the client to request a lock
static pthread_mutex_t rig_lock_mutex = PTHREAD_MUTEX_INITIALIZER;
void rig_lock()
{
#ifdef HAVE_PTHREAD
pthread_mutex_lock(&rig_lock_mutex);
rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__);
#endif
}
void rig_unlock()
{
#ifdef HAVE_PTHREAD
pthread_mutex_unlock(&rig_lock_mutex);
rig_debug(RIG_DEBUG_TRACE, "%s\n", __func__);
#endif
}
#else
void rig_lock() {};
void rig_unlock() {};
#endif
/*
* track which rig is opened (with rig_open)
* needed at least for transceive mode