Skip to content
Snippets Groups Projects
Commit b6f554d9 authored by Mathieu Westphal's avatar Mathieu Westphal
Browse files

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

parent dc1b53ce
No related branches found
No related tags found
1 merge request!133input_file.c: Use HAVE_PHTREADS compile definitions to support building without pthread
Pipeline #98477 passed
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment