Skip to content

Commit

Permalink
A clean version of #673: Allow the use of Pthreads with WIN32/64 buil…
Browse files Browse the repository at this point in the history
…ds under MinGW

Signed-off-by: Cary Phillips <cary@ilm.com>
  • Loading branch information
cary-ilm committed May 3, 2020
1 parent ac4fb15 commit 3ab677b
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion IlmBase/IlmThread/IlmThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Thread::start ()
}

#else
# if !defined (_WIN32) &&!(_WIN64) && !(HAVE_PTHREAD)
# if !defined (_WIN32) && !defined (_WIN64) && ! defined(HAVE_PTHREAD)
//-----------------------------------------------------------------------------
// OPENEXR_FORCE_CXX03 with no windows / pthread support
//-----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions IlmBase/IlmThread/IlmThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
#include "IlmThreadNamespace.h"

#ifdef ILMBASE_FORCE_CXX03
# if defined _WIN32 || defined _WIN64
# if (defined (_WIN32) || defined (_WIN64)) && !defined(HAVE_PTHREAD)
# ifdef NOMINMAX
# undef NOMINMAX
# endif
Expand Down Expand Up @@ -132,7 +132,7 @@ class Thread
private:

#ifdef ILMBASE_FORCE_CXX03
# if defined _WIN32 || defined _WIN64
# if (defined (_WIN32) || defined (_WIN64)) && !defined (HAVE_PTHREAD)
HANDLE _thread;
# elif HAVE_PTHREAD
pthread_t _thread;
Expand Down
2 changes: 1 addition & 1 deletion IlmBase/IlmThread/IlmThreadMutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include "IlmBaseConfig.h"

#ifdef ILMBASE_FORCE_CXX03
# if !defined (_WIN32) && !(_WIN64) && !(HAVE_PTHREAD)
# if !defined (_WIN32) && !defined (_WIN64) && !defined (HAVE_PTHREAD)
# include "IlmThreadMutex.h"

ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER
Expand Down
8 changes: 4 additions & 4 deletions IlmBase/IlmThread/IlmThreadMutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@
#include "IlmThreadNamespace.h"

#ifdef ILMBASE_FORCE_CXX03
# if defined _WIN32 || defined _WIN64
# if defined (_WIN32) || defined (_WIN64)
# ifdef NOMINMAX
# undef NOMINMAX
# endif
# define NOMINMAX
# include <windows.h>
# elif HAVE_PTHREAD
# elif defined (HAVE_PTHREAD)
# include <pthread.h>
# endif
#else
Expand Down Expand Up @@ -116,9 +116,9 @@ class ILMTHREAD_EXPORT Mutex
void lock () const;
void unlock () const;

#if defined _WIN32 || defined _WIN64
#if (defined (_WIN32) || defined (_WIN64)) && !defined (HAVE_PTHREADS)
mutable CRITICAL_SECTION _mutex;
#elif HAVE_PTHREAD
#elif defined (HAVE_PTHREAD)
mutable pthread_mutex_t _mutex;
#endif

Expand Down
5 changes: 2 additions & 3 deletions IlmBase/IlmThread/IlmThreadMutexPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@
//-----------------------------------------------------------------------------

#include "IlmBaseConfig.h"
#include "IlmThreadMutex.h"

#ifdef ILMBASE_FORCE_CXX03
# if HAVE_PTHREAD

# include "IlmThreadMutex.h"
# ifdef HAVE_PTHREAD
# include "Iex.h"
# include <assert.h>

Expand Down
4 changes: 2 additions & 2 deletions IlmBase/IlmThread/IlmThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ TaskGroup::Data::addTask ()
// extra lock but for c++98, to add the ability for custom thread
// pool we add the lock here
//
#if ILMBASE_FORCE_CXX03
#ifdef ILMBASE_FORCE_CXX03
Lock lock (dtorMutex);
#endif
if (numPending++ == 0)
Expand Down Expand Up @@ -862,7 +862,7 @@ unsigned
ThreadPool::estimateThreadCountForFileIO ()
{
#ifdef ILMBASE_FORCE_CXX03
# if defined(_WIN32)
# if defined (_WIN32) || defined (_WIN64)
SYSTEM_INFO sysinfo;
GetSystemInfo (&sysinfo);
return static_cast<unsigned> (sysinfo.dwNumberOfProcessors);
Expand Down
2 changes: 1 addition & 1 deletion IlmBase/IlmThread/IlmThreadPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

#include "IlmBaseConfig.h"

#if HAVE_PTHREAD
#ifdef HAVE_PTHREAD
#ifdef ILMBASE_FORCE_CXX03

#include "IlmThread.h"
Expand Down
4 changes: 2 additions & 2 deletions IlmBase/IlmThread/IlmThreadSemaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
# include <dispatch/dispatch.h>
#else
# ifdef ILMBASE_FORCE_CXX03
# if HAVE_PTHREAD
# ifdef HAVE_PTHREAD
# include <pthread.h>
# endif
# else
Expand All @@ -84,7 +84,7 @@ class ILMTHREAD_EXPORT Semaphore

private:

#if defined _WIN32 || defined _WIN64
#if (defined (_WIN32) || defined (_WIN64)) && !defined (HAVE_POSIX_SEMAPHORES)

mutable HANDLE _semaphore;

Expand Down
2 changes: 1 addition & 1 deletion IlmBase/IlmThread/IlmThreadSemaphorePosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

#include "IlmBaseConfig.h"

#if HAVE_PTHREAD && HAVE_POSIX_SEMAPHORES
#if defined (HAVE_PTHREAD) && defined(HAVE_POSIX_SEMAPHORES)

#include "IlmThreadSemaphore.h"
#include "Iex.h"
Expand Down
9 changes: 6 additions & 3 deletions IlmBase/IlmThread/IlmThreadSemaphorePosixCompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@
//-----------------------------------------------------------------------------

#include "IlmBaseConfig.h"
#include "IlmThreadSemaphore.h"

#if (!HAVE_POSIX_SEMAPHORES) && !defined (_WIN32) && ! defined (_WIN64) && ! defined (__APPLE__)
#if !defined (HAVE_POSIX_SEMAPHORES) && !defined (APPLE)
#if (!defined (_WIN32) && !defined (_WIN64)) || defined (__MINGW64_VERSION_MAJOR)

#include "IlmThreadSemaphore.h"
#include "Iex.h"
#include <assert.h>

ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER

#if ILMBASE_FORCE_CXX03 && HAVE_PTHREAD
#if defined (ILMBASE_FORCE_CXX03) && defined(HAVE_PTHREAD)
Semaphore::Semaphore (unsigned int value)
{
if (int error = ::pthread_mutex_init (&_semaphore.mutex, 0))
Expand Down Expand Up @@ -224,3 +225,5 @@ Semaphore::value () const
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT

#endif
#endif

4 changes: 2 additions & 2 deletions IlmBase/IlmThread/IlmThreadWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@


#include "IlmBaseConfig.h"
#include "IlmThread.h"

#ifdef ILMBASE_FORCE_CXX03
#ifdef _WIN32
#if (defined (_WIN32) || defined (_WIN64)) && !defined(HAVE_POSIX_SEMAPHORES)

#include "IlmThread.h"
#include "Iex.h"
#include <iostream>
#include <assert.h>
Expand Down

0 comments on commit 3ab677b

Please sign in to comment.