Skip to content
Snippets Groups Projects

input_file.c: Use HAVE_PHTREADS compile definitions to support building without pthread

Merged Mathieu Westphal requested to merge b383306/libcdi:have_pthread_input_file into develop
1 file
+ 14
1
Compare changes
  • Side-by-side
  • Inline
+ 14
1
@@ -18,10 +18,13 @@
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>
#if HAVE_PTHREAD
#include <pthread.h>
#endif
static void cdiInputFile_destruct(CdiInputFile *me);
// For an explanation of the condestruct() pattern, see the comment in iterator_grib.c
@@ -64,7 +67,9 @@ success:
static CdiInputFile **openFileList = NULL;
static size_t openFileCount = 0, openFileListSize = 0;
#if HAVE_PTHREAD
static pthread_mutex_t openFileListLock = PTHREAD_MUTEX_INITIALIZER;
#endif
// This either returns a new object, or retains and returns a preexisting open file.
CdiInputFile *
@@ -72,8 +77,10 @@ cdiInputFile_make(const char *path)
{
CdiInputFile *result = NULL;
xassert(path);
#if HAVE_PTHREAD
int error = pthread_mutex_lock(&openFileListLock);
xassert(!error);
#endif
{
// Check the list of open files for the given path.
for (size_t i = openFileCount; i-- && !result;)
@@ -108,8 +115,10 @@ cdiInputFile_make(const char *path)
}
}
}
#if HAVE_PTHREAD
error = pthread_mutex_unlock(&openFileListLock);
xassert(!error);
#endif
return result;
}
@@ -142,8 +151,10 @@ cdiInputFile_getPath(const CdiInputFile *me)
void
cdiInputFile_destruct(CdiInputFile *me)
{
#if HAVE_PTHREAD
int error = pthread_mutex_lock(&openFileListLock);
xassert(!error);
#endif
{
// Find the position of me in the list of open files.
ssize_t position = (ssize_t) openFileCount;
@@ -152,8 +163,10 @@ cdiInputFile_destruct(CdiInputFile *me)
// Remove me from the list
openFileList[position] = openFileList[--openFileCount];
}
#if HAVE_PTHREAD
error = pthread_mutex_unlock(&openFileListLock);
xassert(!error);
#endif
cdiInputFile_condestruct(me, NULL);
}
Loading