Commit e18ec024 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Replaced pthread mutex by std::mutex.

parent fd1c4b15
......@@ -88,10 +88,8 @@ streamInqVlistLocked(int p_fileID)
{
if (Threading::cdoLockIO) PTHREAD_MUTEX_LOCK(&streamMutex);
int vlistID = streamInqVlist(p_fileID);
if (Threading::cdoLockIO) PTHREAD_MUTEX_UNLOCK(&streamMutex);
#ifdef HAVE_LIBPTHREAD
if (Threading::cdoLockIO) pthread_mutex_unlock(&streamMutex);
#endif
return vlistID;
}
......
......@@ -25,46 +25,23 @@
#ifdef HAVE_UDUNITS2
static void udunitsInitialize(void);
#ifdef HAVE_LIBPTHREAD
#include <pthread.h>
static pthread_once_t udunitsInitThread = PTHREAD_ONCE_INIT;
static pthread_mutex_t udunitsMutex = PTHREAD_MUTEX_INITIALIZER;
#define UDUNITS_LOCK() pthread_mutex_lock(&udunitsMutex)
#define UDUNITS_UNLOCK() pthread_mutex_unlock(&udunitsMutex)
#define UDUNITS_INIT() pthread_once(&udunitsInitThread, udunitsInitialize)
#include <mutex>
static std::mutex udunitsMutex;
#define UDUNITS_LOCK() std::unique_lock<std::mutex> locked_mutex(udunitsMutex);
#else
static bool udunitsInit = false;
#define UDUNITS_LOCK()
#define UDUNITS_UNLOCK()
#define UDUNITS_INIT() \
if (!udunitsInit) udunitsInitialize();
#endif
static ut_system *ut_read = nullptr;
static void
udunitsInitialize(void)
{
#ifdef HAVE_LIBPTHREAD
/* initialize global API mutex lock */
pthread_mutex_init(&udunitsMutex, nullptr);
#else
udunitsInit = true;
#endif
}
static void *
get_converter(char *src_unit_str, char *tgt_unit_str, int *rstatus)
{
ut_unit *src_unit, *tgt_unit;
cv_converter *ut_units_converter = nullptr;
int status;
......@@ -94,7 +71,7 @@ get_converter(char *src_unit_str, char *tgt_unit_str, int *rstatus)
}
ut_trim(src_unit_str, UT_ASCII);
src_unit = ut_parse(ut_read, src_unit_str, UT_ASCII);
ut_unit *src_unit = ut_parse(ut_read, src_unit_str, UT_ASCII);
if (ut_get_status() != UT_SUCCESS)
{
if (Options::cdoVerbose) cdoWarning("Udunits: Error parsing units: [%s]", src_unit_str);
......@@ -102,7 +79,7 @@ get_converter(char *src_unit_str, char *tgt_unit_str, int *rstatus)
}
ut_trim(tgt_unit_str, UT_ASCII);
tgt_unit = ut_parse(ut_read, tgt_unit_str, UT_ASCII);
ut_unit *tgt_unit = ut_parse(ut_read, tgt_unit_str, UT_ASCII);
if (ut_get_status() != UT_SUCCESS)
{
if (Options::cdoVerbose) cdoWarning("Udunits: Error parsing units: [%s]", tgt_unit_str);
......@@ -151,7 +128,6 @@ cdoConvertFree(void *ut_converter)
{
UDUNITS_LOCK();
cv_free((cv_converter *) ut_converter);
UDUNITS_UNLOCK();
}
void
......@@ -162,7 +138,6 @@ cdoConvertDestroy()
UDUNITS_LOCK();
ut_free_system(ut_read);
ut_read = nullptr;
UDUNITS_UNLOCK();
}
}
#endif
......@@ -174,10 +149,10 @@ cdoConvertUnits(void **ut_converter, bool *changeunits, char *units, char *units
{
#ifdef HAVE_UDUNITS2
int status;
UDUNITS_INIT();
UDUNITS_LOCK();
*ut_converter = get_converter(units_old, units, &status);
UDUNITS_UNLOCK();
{
UDUNITS_LOCK();
*ut_converter = get_converter(units_old, units, &status);
}
if (*ut_converter == nullptr)
{
if (status == -2)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment