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