kopia lustrzana https://github.com/Hamlib/Hamlib
New mutex macros to be resued across all rig functions to support async multicast actions
rodzic
8399b4b4dc
commit
43251254c5
34
src/rig.c
34
src/rig.c
|
@ -160,6 +160,8 @@ const char hamlib_copyright[231] = /* hamlib 1.2 ABI specifies 231 bytes */
|
||||||
#define ELAPSED1 clock_t __begin = clock()
|
#define ELAPSED1 clock_t __begin = clock()
|
||||||
#define ELAPSED2 rig_debug(RIG_DEBUG_TRACE, "%s: elapsed=%.0lfms\n", __func__, ((double)clock() - __begin) / CLOCKS_PER_SEC * 1000)
|
#define ELAPSED2 rig_debug(RIG_DEBUG_TRACE, "%s: elapsed=%.0lfms\n", __func__, ((double)clock() - __begin) / CLOCKS_PER_SEC * 1000)
|
||||||
|
|
||||||
|
#define LOCK \
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Data structure to track the opened rig (by rig_open)
|
* Data structure to track the opened rig (by rig_open)
|
||||||
*/
|
*/
|
||||||
|
@ -2266,6 +2268,7 @@ int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
||||||
{
|
{
|
||||||
RETURNFUNC(-RIG_EINVAL);
|
RETURNFUNC(-RIG_EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ELAPSED1;
|
ELAPSED1;
|
||||||
|
|
||||||
// do not mess with mode while PTT is on
|
// do not mess with mode while PTT is on
|
||||||
|
@ -6788,6 +6791,24 @@ const char *HAMLIB_API rig_copyright()
|
||||||
return hamlib_copyright2;
|
return hamlib_copyright2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PTHREAD
|
||||||
|
#define MUTEX(var) static pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER
|
||||||
|
#else
|
||||||
|
#define MUTEX(var)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PTHREAD
|
||||||
|
#define MUTEX_LOCK(var) pthread_mutex_lock(var)
|
||||||
|
#else
|
||||||
|
#define MUTEX_LOCK1(var)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PTHREAD
|
||||||
|
#define MUTEX_UNLOCK(var) pthread_mutex_unlock(var)
|
||||||
|
#else
|
||||||
|
#define MUTEX_UNLOCK2(var)
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief get a cookie to grab rig control
|
* \brief get a cookie to grab rig control
|
||||||
* \param rig Not used
|
* \param rig Not used
|
||||||
|
@ -6823,9 +6844,7 @@ int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie,
|
||||||
static double time_last_used;
|
static double time_last_used;
|
||||||
struct timespec tp;
|
struct timespec tp;
|
||||||
int ret;
|
int ret;
|
||||||
#ifdef HAVE_PTHREAD
|
MUTEX(mutex_rig_cookie);
|
||||||
static pthread_mutex_t cookie_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* This is not needed for RIG_COOKIE_RELEASE but keep it simple. */
|
/* This is not needed for RIG_COOKIE_RELEASE but keep it simple. */
|
||||||
if (cookie_len < HAMLIB_COOKIE_SIZE)
|
if (cookie_len < HAMLIB_COOKIE_SIZE)
|
||||||
|
@ -6844,9 +6863,7 @@ int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie,
|
||||||
|
|
||||||
/* Accesing cookie_save and time_last_used must be done with lock held.
|
/* Accesing cookie_save and time_last_used must be done with lock held.
|
||||||
* So keep code simple and lock it during the whole operation. */
|
* So keep code simple and lock it during the whole operation. */
|
||||||
#ifdef HAVE_PTHREAD
|
MUTEX_LOCK(mutex_rig_cookie);
|
||||||
pthread_mutex_lock(&cookie_lock);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (cookie_cmd)
|
switch (cookie_cmd)
|
||||||
{
|
{
|
||||||
|
@ -6937,11 +6954,8 @@ int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_PTHREAD
|
MUTEX_UNLOCK(mutex_rig_cookie);
|
||||||
pthread_mutex_unlock(&cookie_lock);
|
|
||||||
#endif
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HAMLIB_EXPORT(void) sync_callback(int lock)
|
HAMLIB_EXPORT(void) sync_callback(int lock)
|
||||||
|
|
Ładowanie…
Reference in New Issue