Disabled external gits
This commit is contained in:
16
cs440-acg/ext/openexr/IlmBase/IlmThread/.cvsignore
Normal file
16
cs440-acg/ext/openexr/IlmBase/IlmThread/.cvsignore
Normal file
@@ -0,0 +1,16 @@
|
||||
Makefile
|
||||
Makefile.in
|
||||
config.h.in
|
||||
config.h
|
||||
config.log
|
||||
config.status
|
||||
configure
|
||||
libtool
|
||||
stamp-h
|
||||
aclocal.m4
|
||||
OpenEXR.pc
|
||||
autom4te.cache
|
||||
ltmain.sh
|
||||
stamp-h.in
|
||||
depcomp
|
||||
.deps
|
47
cs440-acg/ext/openexr/IlmBase/IlmThread/CMakeLists.txt
Normal file
47
cs440-acg/ext/openexr/IlmBase/IlmThread/CMakeLists.txt
Normal file
@@ -0,0 +1,47 @@
|
||||
# yue.nicholas@gmail.com
|
||||
|
||||
SET( ILMTHREAD_LIBRARY_SOURCES
|
||||
IlmThread.cpp
|
||||
IlmThreadMutex.cpp
|
||||
IlmThreadMutexPosix.cpp
|
||||
IlmThreadPool.cpp
|
||||
IlmThreadPosix.cpp
|
||||
IlmThreadSemaphore.cpp
|
||||
IlmThreadSemaphorePosixCompat.cpp
|
||||
IlmThreadSemaphorePosix.cpp
|
||||
)
|
||||
IF (WIN32)
|
||||
SET( ILMTHREAD_LIBRARY_SOURCES ${ILMTHREAD_LIBRARY_SOURCES}
|
||||
IlmThreadMutexWin32.cpp
|
||||
IlmThreadSemaphoreWin32.cpp
|
||||
IlmThreadWin32.cpp
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
|
||||
IF(ILMBASE_BUILD_SHARED_LIBS)
|
||||
ADD_DEFINITIONS(-DILMTHREAD_EXPORTS)
|
||||
ENDIF()
|
||||
|
||||
ADD_LIBRARY ( IlmThread ${LIB_TYPE}
|
||||
${ILMTHREAD_LIBRARY_SOURCES}
|
||||
)
|
||||
TARGET_LINK_LIBRARIES(IlmThread Iex)
|
||||
|
||||
INSTALL ( TARGETS
|
||||
IlmThread
|
||||
DESTINATION
|
||||
${OPENEXR_INSTALL_LIB_DEST}
|
||||
)
|
||||
|
||||
INSTALL ( FILES
|
||||
IlmThreadPool.h
|
||||
IlmThread.h
|
||||
IlmThreadSemaphore.h
|
||||
IlmThreadMutex.h
|
||||
IlmThreadNamespace.h
|
||||
IlmThreadExport.h
|
||||
IlmThreadForward.h
|
||||
DESTINATION
|
||||
${OPENEXR_INSTALL_HEADER_DEST}
|
||||
)
|
80
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThread.cpp
Normal file
80
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThread.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Thread -- dummy implementation for
|
||||
// platforms that do not support threading
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmBaseConfig.h"
|
||||
|
||||
#if !defined (_WIN32) &&!(_WIN64) && !(HAVE_PTHREAD)
|
||||
|
||||
#include "IlmThread.h"
|
||||
#include "Iex.h"
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER
|
||||
|
||||
|
||||
bool
|
||||
supportsThreads ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Thread::Thread ()
|
||||
{
|
||||
throw IEX_NAMESPACE::NoImplExc ("Threads not supported on this platform.");
|
||||
}
|
||||
|
||||
|
||||
Thread::~Thread ()
|
||||
{
|
||||
throw IEX_NAMESPACE::NoImplExc ("Threads not supported on this platform.");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Thread::start ()
|
||||
{
|
||||
throw IEX_NAMESPACE::NoImplExc ("Threads not supported on this platform.");
|
||||
}
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT
|
||||
|
||||
#endif
|
143
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThread.h
Normal file
143
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThread.h
Normal file
@@ -0,0 +1,143 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDED_ILM_THREAD_H
|
||||
#define INCLUDED_ILM_THREAD_H
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Thread
|
||||
//
|
||||
// Class Thread is a portable interface to a system-dependent thread
|
||||
// primitive. In order to make a thread actually do something useful,
|
||||
// you must derive a subclass from class Thread and implement the
|
||||
// run() function. If the operating system supports threading then
|
||||
// the run() function will be executed int a new thread.
|
||||
//
|
||||
// The actual creation of the thread is done by the start() routine
|
||||
// which then calls the run() function. In general the start()
|
||||
// routine should be called from the constructor of the derived class.
|
||||
//
|
||||
// The base-class thread destructor will join/destroy the thread.
|
||||
//
|
||||
// IMPORTANT: Due to the mechanisms that encapsulate the low-level
|
||||
// threading primitives in a C++ class there is a race condition
|
||||
// with code resembling the following:
|
||||
//
|
||||
// {
|
||||
// WorkerThread myThread;
|
||||
// } // myThread goes out of scope, is destroyed
|
||||
// // and the thread is joined
|
||||
//
|
||||
// The race is between the parent thread joining the child thread
|
||||
// in the destructor of myThread, and the run() function in the
|
||||
// child thread. If the destructor gets executed first then run()
|
||||
// will be called with an invalid "this" pointer.
|
||||
//
|
||||
// This issue can be fixed by using a Semaphore to keep track of
|
||||
// whether the run() function has already been called. You can
|
||||
// include a Semaphore member variable within your derived class
|
||||
// which you post() on in the run() function, and wait() on in the
|
||||
// destructor before the thread is joined. Alternatively you could
|
||||
// do something like this:
|
||||
//
|
||||
// Semaphore runStarted;
|
||||
//
|
||||
// void WorkerThread::run ()
|
||||
// {
|
||||
// runStarted.post()
|
||||
// // do some work
|
||||
// ...
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// WorkerThread myThread;
|
||||
// runStarted.wait (); // ensure that we have started
|
||||
// // the run function
|
||||
// } // myThread goes out of scope, is destroyed
|
||||
// // and the thread is joined
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmBaseConfig.h"
|
||||
#include "IlmThreadExport.h"
|
||||
#include "IlmThreadNamespace.h"
|
||||
|
||||
#if defined _WIN32 || defined _WIN64
|
||||
#ifdef NOMINMAX
|
||||
#undef NOMINMAX
|
||||
#endif
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
#elif HAVE_PTHREAD
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER
|
||||
|
||||
//
|
||||
// Query function to determine if the current platform supports
|
||||
// threads AND this library was compiled with threading enabled.
|
||||
//
|
||||
|
||||
ILMTHREAD_EXPORT bool supportsThreads ();
|
||||
|
||||
|
||||
class ILMTHREAD_EXPORT Thread
|
||||
{
|
||||
public:
|
||||
|
||||
Thread ();
|
||||
virtual ~Thread ();
|
||||
|
||||
void start ();
|
||||
virtual void run () = 0;
|
||||
|
||||
private:
|
||||
|
||||
#if defined _WIN32 || defined _WIN64
|
||||
HANDLE _thread;
|
||||
#elif HAVE_PTHREAD
|
||||
pthread_t _thread;
|
||||
#endif
|
||||
|
||||
void operator = (const Thread& t); // not implemented
|
||||
Thread (const Thread& t); // not implemented
|
||||
};
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT
|
||||
|
||||
#endif // INCLUDED_ILM_THREAD_H
|
46
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadExport.h
Normal file
46
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadExport.h
Normal file
@@ -0,0 +1,46 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(OPENEXR_DLL)
|
||||
#if defined(ILMTHREAD_EXPORTS)
|
||||
#define ILMTHREAD_EXPORT __declspec(dllexport)
|
||||
#define ILMTHREAD_EXPORT_CONST extern __declspec(dllexport)
|
||||
#else
|
||||
#define ILMTHREAD_EXPORT __declspec(dllimport)
|
||||
#define ILMTHREAD_EXPORT_CONST extern __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define ILMTHREAD_EXPORT
|
||||
#define ILMTHREAD_EXPORT_CONST extern const
|
||||
#endif
|
52
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadForward.h
Normal file
52
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadForward.h
Normal file
@@ -0,0 +1,52 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDED_ILMTHREADFORWARD_H
|
||||
#define INCLUDED_ILMTHREADFORWARD_H
|
||||
|
||||
#include "IlmThreadNamespace.h"
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER
|
||||
|
||||
class Thread;
|
||||
class Mutex;
|
||||
class Lock;
|
||||
class ThreadPool;
|
||||
class Task;
|
||||
class TaskGroup;
|
||||
class Semaphore;
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT
|
||||
|
||||
#endif // INCLUDED_ILMTHREADFORWARD_H
|
59
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadMutex.cpp
Normal file
59
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadMutex.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Mutex, class Lock -- dummy implementation
|
||||
// for platforms that do not support threading
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmBaseConfig.h"
|
||||
|
||||
#if !defined (_WIN32) && !(_WIN64) && !(HAVE_PTHREAD)
|
||||
|
||||
#include "IlmThreadMutex.h"
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER
|
||||
|
||||
|
||||
Mutex::Mutex () {}
|
||||
Mutex::~Mutex () {}
|
||||
void Mutex::lock () const {}
|
||||
void Mutex::unlock () const {}
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT
|
||||
|
||||
#endif
|
160
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadMutex.h
Normal file
160
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadMutex.h
Normal file
@@ -0,0 +1,160 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDED_ILM_THREAD_MUTEX_H
|
||||
#define INCLUDED_ILM_THREAD_MUTEX_H
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Mutex, class Lock
|
||||
//
|
||||
// Class Mutex is a wrapper for a system-dependent mutual exclusion
|
||||
// mechanism. Actual locking and unlocking of a Mutex object must
|
||||
// be performed using an instance of a Lock (defined below).
|
||||
//
|
||||
// Class lock provides safe locking and unlocking of mutexes even in
|
||||
// the presence of C++ exceptions. Constructing a Lock object locks
|
||||
// the mutex; destroying the Lock unlocks the mutex.
|
||||
//
|
||||
// Lock objects are not themselves thread-safe. You should never
|
||||
// share a Lock object among multiple threads.
|
||||
//
|
||||
// Typical usage:
|
||||
//
|
||||
// Mutex mtx; // Create a Mutex object that is visible
|
||||
// //to multiple threads
|
||||
//
|
||||
// ... // create some threads
|
||||
//
|
||||
// // Then, within each thread, construct a critical section like so:
|
||||
//
|
||||
// {
|
||||
// Lock lock (mtx); // Lock constructor locks the mutex
|
||||
// ... // do some computation on shared data
|
||||
// } // leaving the block unlocks the mutex
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmThreadExport.h"
|
||||
#include "IlmBaseConfig.h"
|
||||
#include "IlmThreadNamespace.h"
|
||||
|
||||
#if defined _WIN32 || defined _WIN64
|
||||
#ifdef NOMINMAX
|
||||
#undef NOMINMAX
|
||||
#endif
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#elif HAVE_PTHREAD
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER
|
||||
|
||||
class Lock;
|
||||
|
||||
|
||||
class ILMTHREAD_EXPORT Mutex
|
||||
{
|
||||
public:
|
||||
|
||||
Mutex ();
|
||||
virtual ~Mutex ();
|
||||
|
||||
private:
|
||||
|
||||
void lock () const;
|
||||
void unlock () const;
|
||||
|
||||
#if defined _WIN32 || defined _WIN64
|
||||
mutable CRITICAL_SECTION _mutex;
|
||||
#elif HAVE_PTHREAD
|
||||
mutable pthread_mutex_t _mutex;
|
||||
#endif
|
||||
|
||||
void operator = (const Mutex& M); // not implemented
|
||||
Mutex (const Mutex& M); // not implemented
|
||||
|
||||
friend class Lock;
|
||||
};
|
||||
|
||||
|
||||
class ILMTHREAD_EXPORT Lock
|
||||
{
|
||||
public:
|
||||
|
||||
Lock (const Mutex& m, bool autoLock = true):
|
||||
_mutex (m),
|
||||
_locked (false)
|
||||
{
|
||||
if (autoLock)
|
||||
{
|
||||
_mutex.lock();
|
||||
_locked = true;
|
||||
}
|
||||
}
|
||||
|
||||
~Lock ()
|
||||
{
|
||||
if (_locked)
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
void acquire ()
|
||||
{
|
||||
_mutex.lock();
|
||||
_locked = true;
|
||||
}
|
||||
|
||||
void release ()
|
||||
{
|
||||
_mutex.unlock();
|
||||
_locked = false;
|
||||
}
|
||||
|
||||
bool locked ()
|
||||
{
|
||||
return _locked;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
const Mutex & _mutex;
|
||||
bool _locked;
|
||||
};
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT
|
||||
|
||||
#endif // INCLUDED_ILM_THREAD_MUTEX_H
|
@@ -0,0 +1,85 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Mutex -- implementation for
|
||||
// platforms that support Posix threads
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmBaseConfig.h"
|
||||
|
||||
#if HAVE_PTHREAD
|
||||
|
||||
#include "IlmThreadMutex.h"
|
||||
#include "Iex.h"
|
||||
#include <assert.h>
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER
|
||||
|
||||
|
||||
Mutex::Mutex ()
|
||||
{
|
||||
if (int error = ::pthread_mutex_init (&_mutex, 0))
|
||||
IEX_INTERNAL_NAMESPACE::throwErrnoExc ("Cannot initialize mutex (%T).", error);
|
||||
}
|
||||
|
||||
|
||||
Mutex::~Mutex ()
|
||||
{
|
||||
int error = ::pthread_mutex_destroy (&_mutex);
|
||||
assert (error == 0);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Mutex::lock () const
|
||||
{
|
||||
if (int error = ::pthread_mutex_lock (&_mutex))
|
||||
IEX_INTERNAL_NAMESPACE::throwErrnoExc ("Cannot lock mutex (%T).", error);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Mutex::unlock () const
|
||||
{
|
||||
if (int error = ::pthread_mutex_unlock (&_mutex))
|
||||
IEX_INTERNAL_NAMESPACE::throwErrnoExc ("Cannot unlock mutex (%T).", error);
|
||||
}
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT
|
||||
|
||||
#endif
|
@@ -0,0 +1,73 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Mutex -- implementation for Windows
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmThreadMutex.h"
|
||||
#include "Iex.h"
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER
|
||||
|
||||
|
||||
Mutex::Mutex ()
|
||||
{
|
||||
::InitializeCriticalSection (&_mutex);
|
||||
}
|
||||
|
||||
|
||||
Mutex::~Mutex ()
|
||||
{
|
||||
::DeleteCriticalSection (&_mutex);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Mutex::lock () const
|
||||
{
|
||||
::EnterCriticalSection (&_mutex);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Mutex::unlock () const
|
||||
{
|
||||
::LeaveCriticalSection (&_mutex);
|
||||
}
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT
|
114
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadNamespace.h
Normal file
114
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadNamespace.h
Normal file
@@ -0,0 +1,114 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDED_ILMTHREADNAMESPACE_H
|
||||
#define INCLUDED_ILMTHREADNAMESPACE_H
|
||||
|
||||
//
|
||||
// The purpose of this file is to make it possible to specify an
|
||||
// ILMTHREAD_INTERNAL_NAMESPACE as a preprocessor definition and have all of
|
||||
// the IlmThread symbols defined within that namespace rather than the
|
||||
// standard IlmThread namespace. Those symbols are made available to client
|
||||
// code through the ILMTHREAD_NAMESPACE in addition to the
|
||||
// ILMTHREAD_INTERNAL_NAMESPACE.
|
||||
//
|
||||
// To ensure source code compatibility, the ILMTHREAD_NAMESPACE defaults to
|
||||
// IlmThread and then "using namespace ILMTHREAD_INTERNAL_NAMESPACE;" brings
|
||||
// all of the declarations from the ILMTHREAD_INTERNAL_NAMESPACE into the
|
||||
// ILMTHREAD_NAMESPACE. This means that client code can continue to use
|
||||
// syntax like IlmThread::Thread, but at link time it will resolve to a
|
||||
// mangled symbol based on the ILMTHREAD_INTERNAL_NAMESPACE.
|
||||
//
|
||||
// As an example, if one needed to build against a newer version of IlmThread
|
||||
// and have it run alongside an older version in the same application, it is
|
||||
// now possible to use an internal namespace to prevent collisions between
|
||||
// the older versions of IlmThread symbols and the newer ones. To do this,
|
||||
// the following could be defined at build time:
|
||||
//
|
||||
// ILMTHREAD_INTERNAL_NAMESPACE = IlmThread_v2
|
||||
//
|
||||
// This means that declarations inside IlmThread headers look like this
|
||||
// (after the preprocessor has done its work):
|
||||
//
|
||||
// namespace IlmThread_v2 {
|
||||
// ...
|
||||
// class declarations
|
||||
// ...
|
||||
// }
|
||||
//
|
||||
// namespace IlmThread {
|
||||
// using namespace IlmThread_v2;
|
||||
// }
|
||||
//
|
||||
|
||||
//
|
||||
// Open Source version of this file pulls in the IlmBaseConfig.h file
|
||||
// for the configure time options.
|
||||
//
|
||||
#include "IlmBaseConfig.h"
|
||||
|
||||
#ifndef ILMTHREAD_NAMESPACE
|
||||
#define ILMTHREAD_NAMESPACE IlmThread
|
||||
#endif
|
||||
|
||||
#ifndef ILMTHREAD_INTERNAL_NAMESPACE
|
||||
#define ILMTHREAD_INTERNAL_NAMESPACE ILMTHREAD_NAMESPACE
|
||||
#endif
|
||||
|
||||
//
|
||||
// We need to be sure that we import the internal namespace into the public one.
|
||||
// To do this, we use the small bit of code below which initially defines
|
||||
// ILMTHREAD_INTERNAL_NAMESPACE (so it can be referenced) and then defines
|
||||
// ILMTHREAD_NAMESPACE and pulls the internal symbols into the public
|
||||
// namespace.
|
||||
//
|
||||
|
||||
namespace ILMTHREAD_INTERNAL_NAMESPACE {}
|
||||
namespace ILMTHREAD_NAMESPACE {
|
||||
using namespace ILMTHREAD_INTERNAL_NAMESPACE;
|
||||
}
|
||||
|
||||
//
|
||||
// There are identical pairs of HEADER/SOURCE ENTER/EXIT macros so that
|
||||
// future extension to the namespace mechanism is possible without changing
|
||||
// project source code.
|
||||
//
|
||||
|
||||
#define ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER namespace ILMTHREAD_INTERNAL_NAMESPACE {
|
||||
#define ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT }
|
||||
|
||||
#define ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER namespace ILMTHREAD_INTERNAL_NAMESPACE {
|
||||
#define ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT }
|
||||
|
||||
#endif // INCLUDED_ILMTHREADNAMESPACE_H
|
483
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadPool.cpp
Normal file
483
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadPool.cpp
Normal file
@@ -0,0 +1,483 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Task, class ThreadPool, class TaskGroup
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmThread.h"
|
||||
#include "IlmThreadMutex.h"
|
||||
#include "IlmThreadSemaphore.h"
|
||||
#include "IlmThreadPool.h"
|
||||
#include "Iex.h"
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER
|
||||
namespace {
|
||||
|
||||
class WorkerThread: public Thread
|
||||
{
|
||||
public:
|
||||
|
||||
WorkerThread (ThreadPool::Data* data);
|
||||
|
||||
virtual void run ();
|
||||
|
||||
private:
|
||||
|
||||
ThreadPool::Data * _data;
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
||||
|
||||
struct TaskGroup::Data
|
||||
{
|
||||
Data ();
|
||||
~Data ();
|
||||
|
||||
void addTask () ;
|
||||
void removeTask ();
|
||||
|
||||
Semaphore isEmpty; // used to signal that the taskgroup is empty
|
||||
int numPending; // number of pending tasks to still execute
|
||||
Mutex dtorMutex; // used to work around the glibc bug:
|
||||
// http://sources.redhat.com/bugzilla/show_bug.cgi?id=12674
|
||||
};
|
||||
|
||||
|
||||
struct ThreadPool::Data
|
||||
{
|
||||
Data ();
|
||||
~Data();
|
||||
|
||||
void finish ();
|
||||
bool stopped () const;
|
||||
void stop ();
|
||||
|
||||
Semaphore taskSemaphore; // threads wait on this for ready tasks
|
||||
Mutex taskMutex; // mutual exclusion for the tasks list
|
||||
list<Task*> tasks; // the list of tasks to execute
|
||||
size_t numTasks; // fast access to list size
|
||||
// (list::size() can be O(n))
|
||||
|
||||
Semaphore threadSemaphore; // signaled when a thread starts executing
|
||||
Mutex threadMutex; // mutual exclusion for threads list
|
||||
list<WorkerThread*> threads; // the list of all threads
|
||||
size_t numThreads; // fast access to list size
|
||||
|
||||
bool stopping; // flag indicating whether to stop threads
|
||||
Mutex stopMutex; // mutual exclusion for stopping flag
|
||||
};
|
||||
|
||||
|
||||
|
||||
//
|
||||
// class WorkerThread
|
||||
//
|
||||
|
||||
WorkerThread::WorkerThread (ThreadPool::Data* data):
|
||||
_data (data)
|
||||
{
|
||||
start();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WorkerThread::run ()
|
||||
{
|
||||
//
|
||||
// Signal that the thread has started executing
|
||||
//
|
||||
|
||||
_data->threadSemaphore.post();
|
||||
|
||||
while (true)
|
||||
{
|
||||
//
|
||||
// Wait for a task to become available
|
||||
//
|
||||
|
||||
_data->taskSemaphore.wait();
|
||||
|
||||
{
|
||||
Lock taskLock (_data->taskMutex);
|
||||
|
||||
//
|
||||
// If there is a task pending, pop off the next task in the FIFO
|
||||
//
|
||||
|
||||
if (_data->numTasks > 0)
|
||||
{
|
||||
Task* task = _data->tasks.front();
|
||||
TaskGroup* taskGroup = task->group();
|
||||
_data->tasks.pop_front();
|
||||
_data->numTasks--;
|
||||
|
||||
taskLock.release();
|
||||
task->execute();
|
||||
taskLock.acquire();
|
||||
|
||||
delete task;
|
||||
taskGroup->_data->removeTask();
|
||||
}
|
||||
else if (_data->stopped())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// struct TaskGroup::Data
|
||||
//
|
||||
|
||||
TaskGroup::Data::Data (): isEmpty (1), numPending (0)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
TaskGroup::Data::~Data ()
|
||||
{
|
||||
//
|
||||
// A TaskGroup acts like an "inverted" semaphore: if the count
|
||||
// is above 0 then waiting on the taskgroup will block. This
|
||||
// destructor waits until the taskgroup is empty before returning.
|
||||
//
|
||||
|
||||
isEmpty.wait ();
|
||||
|
||||
// Alas, given the current bug in glibc we need a secondary
|
||||
// syncronisation primitive here to account for the fact that
|
||||
// destructing the isEmpty Semaphore in this thread can cause
|
||||
// an error for a separate thread that is issuing the post() call.
|
||||
// We are entitled to destruct the semaphore at this point, however,
|
||||
// that post() call attempts to access data out of the associated
|
||||
// memory *after* it has woken the waiting threads, including this one,
|
||||
// potentially leading to invalid memory reads.
|
||||
// http://sources.redhat.com/bugzilla/show_bug.cgi?id=12674
|
||||
|
||||
Lock lock (dtorMutex);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TaskGroup::Data::addTask ()
|
||||
{
|
||||
//
|
||||
// Any access to the taskgroup is protected by a mutex that is
|
||||
// held by the threadpool. Therefore it is safe to access
|
||||
// numPending before we wait on the semaphore.
|
||||
//
|
||||
|
||||
if (numPending++ == 0)
|
||||
isEmpty.wait ();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TaskGroup::Data::removeTask ()
|
||||
{
|
||||
// Alas, given the current bug in glibc we need a secondary
|
||||
// syncronisation primitive here to account for the fact that
|
||||
// destructing the isEmpty Semaphore in a separate thread can
|
||||
// cause an error. Issuing the post call here the current libc
|
||||
// implementation attempts to access memory *after* it has woken
|
||||
// waiting threads.
|
||||
// Since other threads are entitled to delete the semaphore the
|
||||
// access to the memory location can be invalid.
|
||||
// http://sources.redhat.com/bugzilla/show_bug.cgi?id=12674
|
||||
|
||||
if (--numPending == 0)
|
||||
{
|
||||
Lock lock (dtorMutex);
|
||||
isEmpty.post ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// struct ThreadPool::Data
|
||||
//
|
||||
|
||||
ThreadPool::Data::Data (): numTasks (0), numThreads (0), stopping (false)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
ThreadPool::Data::~Data()
|
||||
{
|
||||
Lock lock (threadMutex);
|
||||
finish ();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ThreadPool::Data::finish ()
|
||||
{
|
||||
stop();
|
||||
|
||||
//
|
||||
// Signal enough times to allow all threads to stop.
|
||||
//
|
||||
// Wait until all threads have started their run functions.
|
||||
// If we do not wait before we destroy the threads then it's
|
||||
// possible that the threads have not yet called their run
|
||||
// functions.
|
||||
// If this happens then the run function will be called off
|
||||
// of an invalid object and we will crash, most likely with
|
||||
// an error like: "pure virtual method called"
|
||||
//
|
||||
|
||||
for (size_t i = 0; i < numThreads; i++)
|
||||
{
|
||||
taskSemaphore.post();
|
||||
threadSemaphore.wait();
|
||||
}
|
||||
|
||||
//
|
||||
// Join all the threads
|
||||
//
|
||||
|
||||
for (list<WorkerThread*>::iterator i = threads.begin();
|
||||
i != threads.end();
|
||||
++i)
|
||||
{
|
||||
delete (*i);
|
||||
}
|
||||
|
||||
Lock lock1 (taskMutex);
|
||||
Lock lock2 (stopMutex);
|
||||
threads.clear();
|
||||
tasks.clear();
|
||||
numThreads = 0;
|
||||
numTasks = 0;
|
||||
stopping = false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
ThreadPool::Data::stopped () const
|
||||
{
|
||||
Lock lock (stopMutex);
|
||||
return stopping;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ThreadPool::Data::stop ()
|
||||
{
|
||||
Lock lock (stopMutex);
|
||||
stopping = true;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// class Task
|
||||
//
|
||||
|
||||
Task::Task (TaskGroup* g): _group(g)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
Task::~Task()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
TaskGroup*
|
||||
Task::group ()
|
||||
{
|
||||
return _group;
|
||||
}
|
||||
|
||||
|
||||
TaskGroup::TaskGroup ():
|
||||
_data (new Data())
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
TaskGroup::~TaskGroup ()
|
||||
{
|
||||
delete _data;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// class ThreadPool
|
||||
//
|
||||
|
||||
ThreadPool::ThreadPool (unsigned nthreads):
|
||||
_data (new Data())
|
||||
{
|
||||
setNumThreads (nthreads);
|
||||
}
|
||||
|
||||
|
||||
ThreadPool::~ThreadPool ()
|
||||
{
|
||||
delete _data;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ThreadPool::numThreads () const
|
||||
{
|
||||
Lock lock (_data->threadMutex);
|
||||
return _data->numThreads;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ThreadPool::setNumThreads (int count)
|
||||
{
|
||||
if (count < 0)
|
||||
throw IEX_INTERNAL_NAMESPACE::ArgExc ("Attempt to set the number of threads "
|
||||
"in a thread pool to a negative value.");
|
||||
|
||||
//
|
||||
// Lock access to thread list and size
|
||||
//
|
||||
|
||||
Lock lock (_data->threadMutex);
|
||||
|
||||
if ((size_t)count > _data->numThreads)
|
||||
{
|
||||
//
|
||||
// Add more threads
|
||||
//
|
||||
|
||||
while (_data->numThreads < (size_t)count)
|
||||
{
|
||||
_data->threads.push_back (new WorkerThread (_data));
|
||||
_data->numThreads++;
|
||||
}
|
||||
}
|
||||
else if ((size_t)count < _data->numThreads)
|
||||
{
|
||||
//
|
||||
// Wait until all existing threads are finished processing,
|
||||
// then delete all threads.
|
||||
//
|
||||
|
||||
_data->finish ();
|
||||
|
||||
//
|
||||
// Add in new threads
|
||||
//
|
||||
|
||||
while (_data->numThreads < (size_t)count)
|
||||
{
|
||||
_data->threads.push_back (new WorkerThread (_data));
|
||||
_data->numThreads++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ThreadPool::addTask (Task* task)
|
||||
{
|
||||
//
|
||||
// Lock the threads, needed to access numThreads
|
||||
//
|
||||
|
||||
Lock lock (_data->threadMutex);
|
||||
|
||||
if (_data->numThreads == 0)
|
||||
{
|
||||
task->execute ();
|
||||
delete task;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Get exclusive access to the tasks queue
|
||||
//
|
||||
|
||||
{
|
||||
Lock taskLock (_data->taskMutex);
|
||||
|
||||
//
|
||||
// Push the new task into the FIFO
|
||||
//
|
||||
|
||||
_data->tasks.push_back (task);
|
||||
_data->numTasks++;
|
||||
task->group()->_data->addTask();
|
||||
}
|
||||
|
||||
//
|
||||
// Signal that we have a new task to process
|
||||
//
|
||||
|
||||
_data->taskSemaphore.post ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ThreadPool&
|
||||
ThreadPool::globalThreadPool ()
|
||||
{
|
||||
//
|
||||
// The global thread pool
|
||||
//
|
||||
|
||||
static ThreadPool gThreadPool (0);
|
||||
|
||||
return gThreadPool;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ThreadPool::addGlobalTask (Task* task)
|
||||
{
|
||||
globalThreadPool().addTask (task);
|
||||
}
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT
|
160
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadPool.h
Normal file
160
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadPool.h
Normal file
@@ -0,0 +1,160 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDED_ILM_THREAD_POOL_H
|
||||
#define INCLUDED_ILM_THREAD_POOL_H
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Task, class ThreadPool, class TaskGroup
|
||||
//
|
||||
// Class ThreadPool manages a set of worker threads and accepts
|
||||
// tasks for processing. Tasks added to the thread pool are
|
||||
// executed concurrently by the worker threads.
|
||||
//
|
||||
// Class Task provides an abstract interface for a task which
|
||||
// a ThreadPool works on. Derived classes need to implement the
|
||||
// execute() function which performs the actual task.
|
||||
//
|
||||
// Class TaskGroup allows synchronization on the completion of a set
|
||||
// of tasks. Every task that is added to a ThreadPool belongs to a
|
||||
// single TaskGroup. The destructor of the TaskGroup waits for all
|
||||
// tasks in the group to finish.
|
||||
//
|
||||
// Note: if you plan to use the ThreadPool interface in your own
|
||||
// applications note that the implementation of the ThreadPool calls
|
||||
// operator delete on tasks as they complete. If you define a custom
|
||||
// operator new for your tasks, for instance to use a custom heap,
|
||||
// then you must also write an appropriate operator delete.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmThreadNamespace.h"
|
||||
#include "IlmThreadExport.h"
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER
|
||||
|
||||
class TaskGroup;
|
||||
class Task;
|
||||
|
||||
|
||||
class ILMTHREAD_EXPORT ThreadPool
|
||||
{
|
||||
public:
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Constructor -- creates numThreads worker threads which
|
||||
// wait until a task is available.
|
||||
//-------------------------------------------------------
|
||||
|
||||
ThreadPool (unsigned numThreads = 0);
|
||||
|
||||
|
||||
//-----------------------------------------------------------
|
||||
// Destructor -- waits for all tasks to complete, joins all
|
||||
// the threads to the calling thread, and then destroys them.
|
||||
//-----------------------------------------------------------
|
||||
|
||||
virtual ~ThreadPool ();
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
// Query and set the number of worker threads in the pool.
|
||||
//
|
||||
// Warning: never call setNumThreads from within a worker
|
||||
// thread as this will almost certainly cause a deadlock
|
||||
// or crash.
|
||||
//--------------------------------------------------------
|
||||
|
||||
int numThreads () const;
|
||||
void setNumThreads (int count);
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Add a task for processing. The ThreadPool can handle any
|
||||
// number of tasks regardless of the number of worker threads.
|
||||
// The tasks are first added onto a queue, and are executed
|
||||
// by threads as they become available, in FIFO order.
|
||||
//------------------------------------------------------------
|
||||
|
||||
void addTask (Task* task);
|
||||
|
||||
|
||||
//-------------------------------------------
|
||||
// Access functions for the global threadpool
|
||||
//-------------------------------------------
|
||||
|
||||
static ThreadPool& globalThreadPool ();
|
||||
static void addGlobalTask (Task* task);
|
||||
|
||||
struct Data;
|
||||
|
||||
protected:
|
||||
|
||||
Data * _data;
|
||||
};
|
||||
|
||||
|
||||
class ILMTHREAD_EXPORT Task
|
||||
{
|
||||
public:
|
||||
|
||||
Task (TaskGroup* g);
|
||||
virtual ~Task ();
|
||||
|
||||
virtual void execute () = 0;
|
||||
TaskGroup * group();
|
||||
|
||||
protected:
|
||||
|
||||
TaskGroup * _group;
|
||||
};
|
||||
|
||||
|
||||
class ILMTHREAD_EXPORT TaskGroup
|
||||
{
|
||||
public:
|
||||
|
||||
TaskGroup();
|
||||
~TaskGroup();
|
||||
|
||||
struct Data;
|
||||
Data* const _data;
|
||||
};
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT
|
||||
|
||||
#endif // INCLUDED_ILM_THREAD_POOL_H
|
98
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadPosix.cpp
Normal file
98
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadPosix.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Thread -- implementation for
|
||||
// platforms that support Posix threads
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmBaseConfig.h"
|
||||
|
||||
#if HAVE_PTHREAD
|
||||
|
||||
#include "IlmThread.h"
|
||||
#include "Iex.h"
|
||||
#include <assert.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
typedef void * (* Start) (void *);
|
||||
}
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER
|
||||
|
||||
|
||||
bool
|
||||
supportsThreads ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void
|
||||
threadLoop (void * t)
|
||||
{
|
||||
return (reinterpret_cast<Thread*>(t))->run();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
Thread::Thread ()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
Thread::~Thread ()
|
||||
{
|
||||
int error = ::pthread_join (_thread, 0);
|
||||
assert (error == 0);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Thread::start ()
|
||||
{
|
||||
if (int error = ::pthread_create (&_thread, 0, Start (threadLoop), this))
|
||||
IEX_NAMESPACE::throwErrnoExc ("Cannot create new thread (%T).", error);
|
||||
}
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT
|
||||
|
||||
#endif
|
@@ -0,0 +1,60 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Semaphore -- dummy implementation for
|
||||
// for platforms that do not support threading
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmBaseConfig.h"
|
||||
|
||||
#if !defined (_WIN32) && !(_WIN64) && !(HAVE_PTHREAD)
|
||||
#include "IlmThreadSemaphore.h"
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER
|
||||
|
||||
|
||||
Semaphore::Semaphore (unsigned int value) {}
|
||||
Semaphore::~Semaphore () {}
|
||||
void Semaphore::wait () {}
|
||||
bool Semaphore::tryWait () {return true;}
|
||||
void Semaphore::post () {}
|
||||
int Semaphore::value () const {return 0;}
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT
|
||||
|
||||
#endif
|
112
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadSemaphore.h
Normal file
112
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadSemaphore.h
Normal file
@@ -0,0 +1,112 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef INCLUDED_ILM_THREAD_SEMAPHORE_H
|
||||
#define INCLUDED_ILM_THREAD_SEMAPHORE_H
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Semaphore -- a wrapper class for
|
||||
// system-dependent counting semaphores
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmBaseConfig.h"
|
||||
#include "IlmThreadExport.h"
|
||||
#include "IlmThreadNamespace.h"
|
||||
|
||||
#if defined _WIN32 || defined _WIN64
|
||||
#ifdef NOMINMAX
|
||||
#undef NOMINMAX
|
||||
#endif
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#elif HAVE_PTHREAD && !HAVE_POSIX_SEMAPHORES
|
||||
#include <pthread.h>
|
||||
#elif HAVE_PTHREAD && HAVE_POSIX_SEMAPHORES
|
||||
#include <semaphore.h>
|
||||
#endif
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER
|
||||
|
||||
|
||||
class ILMTHREAD_EXPORT Semaphore
|
||||
{
|
||||
public:
|
||||
|
||||
Semaphore (unsigned int value = 0);
|
||||
virtual ~Semaphore();
|
||||
|
||||
void wait();
|
||||
bool tryWait();
|
||||
void post();
|
||||
int value() const;
|
||||
|
||||
private:
|
||||
|
||||
#if defined _WIN32 || defined _WIN64
|
||||
|
||||
mutable HANDLE _semaphore;
|
||||
|
||||
#elif HAVE_PTHREAD && !HAVE_POSIX_SEMAPHORES
|
||||
|
||||
//
|
||||
// If the platform has Posix threads but no semapohores,
|
||||
// then we implement them ourselves using condition variables
|
||||
//
|
||||
|
||||
struct sema_t
|
||||
{
|
||||
unsigned int count;
|
||||
unsigned long numWaiting;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t nonZero;
|
||||
};
|
||||
|
||||
mutable sema_t _semaphore;
|
||||
|
||||
#elif HAVE_PTHREAD && HAVE_POSIX_SEMAPHORES
|
||||
|
||||
mutable sem_t _semaphore;
|
||||
|
||||
#endif
|
||||
|
||||
void operator = (const Semaphore& s); // not implemented
|
||||
Semaphore (const Semaphore& s); // not implemented
|
||||
};
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT
|
||||
|
||||
#endif // INCLUDED_ILM_THREAD_SEMAPHORE_H
|
@@ -0,0 +1,106 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Semaphore -- implementation for platforms
|
||||
// that support Posix threads and Posix semaphores
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmBaseConfig.h"
|
||||
|
||||
#if HAVE_PTHREAD && HAVE_POSIX_SEMAPHORES
|
||||
|
||||
#include "IlmThreadSemaphore.h"
|
||||
#include "Iex.h"
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER
|
||||
|
||||
|
||||
Semaphore::Semaphore (unsigned int value)
|
||||
{
|
||||
if (::sem_init (&_semaphore, 0, value))
|
||||
IEX_NAMESPACE::throwErrnoExc ("Cannot initialize semaphore (%T).");
|
||||
}
|
||||
|
||||
|
||||
Semaphore::~Semaphore ()
|
||||
{
|
||||
int error = ::sem_destroy (&_semaphore);
|
||||
assert (error == 0);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Semaphore::wait ()
|
||||
{
|
||||
while( ::sem_wait( &_semaphore ) == -1 && errno == EINTR )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Semaphore::tryWait ()
|
||||
{
|
||||
return sem_trywait (&_semaphore) == 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Semaphore::post ()
|
||||
{
|
||||
if (::sem_post (&_semaphore))
|
||||
IEX_NAMESPACE::throwErrnoExc ("Post operation on semaphore failed (%T).");
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
Semaphore::value () const
|
||||
{
|
||||
int value;
|
||||
|
||||
if (::sem_getvalue (&_semaphore, &value))
|
||||
IEX_NAMESPACE::throwErrnoExc ("Cannot read semaphore value (%T).");
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT
|
||||
|
||||
#endif
|
@@ -0,0 +1,155 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Semaphore -- implementation for for platforms that do
|
||||
// support Posix threads but do not support Posix semaphores,
|
||||
// for example, OS X
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmBaseConfig.h"
|
||||
|
||||
#if HAVE_PTHREAD && !HAVE_POSIX_SEMAPHORES
|
||||
|
||||
#include "IlmThreadSemaphore.h"
|
||||
#include "Iex.h"
|
||||
#include <assert.h>
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER
|
||||
|
||||
|
||||
Semaphore::Semaphore (unsigned int value)
|
||||
{
|
||||
if (int error = ::pthread_mutex_init (&_semaphore.mutex, 0))
|
||||
IEX_NAMESPACE::throwErrnoExc ("Cannot initialize mutex (%T).", error);
|
||||
|
||||
if (int error = ::pthread_cond_init (&_semaphore.nonZero, 0))
|
||||
IEX_NAMESPACE::throwErrnoExc ("Cannot initialize condition variable (%T).",
|
||||
error);
|
||||
|
||||
_semaphore.count = value;
|
||||
_semaphore.numWaiting = 0;
|
||||
}
|
||||
|
||||
|
||||
Semaphore::~Semaphore ()
|
||||
{
|
||||
int error = ::pthread_cond_destroy (&_semaphore.nonZero);
|
||||
assert (error == 0);
|
||||
error = ::pthread_mutex_destroy (&_semaphore.mutex);
|
||||
assert (error == 0);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Semaphore::wait ()
|
||||
{
|
||||
::pthread_mutex_lock (&_semaphore.mutex);
|
||||
|
||||
_semaphore.numWaiting++;
|
||||
|
||||
while (_semaphore.count == 0)
|
||||
{
|
||||
if (int error = ::pthread_cond_wait (&_semaphore.nonZero,
|
||||
&_semaphore.mutex))
|
||||
{
|
||||
::pthread_mutex_unlock (&_semaphore.mutex);
|
||||
|
||||
IEX_NAMESPACE::throwErrnoExc ("Cannot wait on condition variable (%T).",
|
||||
error);
|
||||
}
|
||||
}
|
||||
|
||||
_semaphore.numWaiting--;
|
||||
_semaphore.count--;
|
||||
|
||||
::pthread_mutex_unlock (&_semaphore.mutex);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Semaphore::tryWait ()
|
||||
{
|
||||
::pthread_mutex_lock (&_semaphore.mutex);
|
||||
|
||||
if (_semaphore.count == 0)
|
||||
{
|
||||
::pthread_mutex_unlock (&_semaphore.mutex);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_semaphore.count--;
|
||||
::pthread_mutex_unlock (&_semaphore.mutex);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Semaphore::post ()
|
||||
{
|
||||
::pthread_mutex_lock (&_semaphore.mutex);
|
||||
|
||||
if (_semaphore.numWaiting > 0)
|
||||
{
|
||||
if (int error = ::pthread_cond_signal (&_semaphore.nonZero))
|
||||
{
|
||||
::pthread_mutex_unlock (&_semaphore.mutex);
|
||||
|
||||
IEX_NAMESPACE::throwErrnoExc ("Cannot signal condition variable (%T).",
|
||||
error);
|
||||
}
|
||||
}
|
||||
|
||||
_semaphore.count++;
|
||||
::pthread_mutex_unlock (&_semaphore.mutex);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
Semaphore::value () const
|
||||
{
|
||||
::pthread_mutex_lock (&_semaphore.mutex);
|
||||
int value = _semaphore.count;
|
||||
::pthread_mutex_unlock (&_semaphore.mutex);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT
|
||||
|
||||
#endif
|
@@ -0,0 +1,147 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Semaphore -- implementation for Windows
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "IlmThreadSemaphore.h"
|
||||
#include "Iex.h"
|
||||
#include <string>
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER
|
||||
|
||||
using namespace IEX_NAMESPACE;
|
||||
|
||||
namespace {
|
||||
|
||||
std::string
|
||||
errorString ()
|
||||
{
|
||||
LPSTR messageBuffer;
|
||||
DWORD bufferLength;
|
||||
std::string message;
|
||||
|
||||
//
|
||||
// Call FormatMessage() to allow for message
|
||||
// text to be acquired from the system.
|
||||
//
|
||||
|
||||
if (bufferLength = FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
0,
|
||||
GetLastError (),
|
||||
MAKELANGID (LANG_NEUTRAL,
|
||||
SUBLANG_DEFAULT),
|
||||
(LPSTR) &messageBuffer,
|
||||
0,
|
||||
NULL))
|
||||
{
|
||||
message = messageBuffer;
|
||||
LocalFree (messageBuffer);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
Semaphore::Semaphore (unsigned int value)
|
||||
{
|
||||
if ((_semaphore = ::CreateSemaphore (0, value, 0x7fffffff, 0)) == 0)
|
||||
{
|
||||
THROW (LogicExc, "Could not create semaphore "
|
||||
"(" << errorString() << ").");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Semaphore::~Semaphore()
|
||||
{
|
||||
bool ok = ::CloseHandle (_semaphore) != FALSE;
|
||||
assert (ok);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Semaphore::wait()
|
||||
{
|
||||
if (::WaitForSingleObject (_semaphore, INFINITE) != WAIT_OBJECT_0)
|
||||
{
|
||||
THROW (LogicExc, "Could not wait on semaphore "
|
||||
"(" << errorString() << ").");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Semaphore::tryWait()
|
||||
{
|
||||
return ::WaitForSingleObject (_semaphore, 0) == WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Semaphore::post()
|
||||
{
|
||||
if (!::ReleaseSemaphore (_semaphore, 1, 0))
|
||||
{
|
||||
THROW (LogicExc, "Could not post on semaphore "
|
||||
"(" << errorString() << ").");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
Semaphore::value() const
|
||||
{
|
||||
LONG v = -1;
|
||||
|
||||
if (!::ReleaseSemaphore (_semaphore, 0, &v) || v < 0)
|
||||
{
|
||||
THROW (LogicExc, "Could not get value of semaphore "
|
||||
"(" << errorString () << ").");
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT
|
95
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadWin32.cpp
Normal file
95
cs440-acg/ext/openexr/IlmBase/IlmThread/IlmThreadWin32.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005-2012, Industrial Light & Magic, a division of Lucas
|
||||
// Digital Ltd. LLC
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Industrial Light & Magic nor the names of
|
||||
// its contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// class Thread -- implementation for Windows
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include "IlmThread.h"
|
||||
#include "Iex.h"
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER
|
||||
|
||||
|
||||
bool
|
||||
supportsThreads ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
unsigned __stdcall
|
||||
threadLoop (void * t)
|
||||
{
|
||||
reinterpret_cast<Thread*>(t)->run();
|
||||
_endthreadex (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
Thread::Thread ()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
|
||||
Thread::~Thread ()
|
||||
{
|
||||
DWORD status = ::WaitForSingleObject (_thread, INFINITE);
|
||||
assert (status == WAIT_OBJECT_0);
|
||||
bool ok = ::CloseHandle (_thread) != FALSE;
|
||||
assert (ok);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Thread::start ()
|
||||
{
|
||||
unsigned id;
|
||||
_thread = (HANDLE)::_beginthreadex (0, 0, &threadLoop, this, 0, &id);
|
||||
|
||||
if (_thread == 0)
|
||||
IEX_NAMESPACE::throwErrnoExc ("Cannot create new thread (%T).");
|
||||
}
|
||||
|
||||
|
||||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT
|
31
cs440-acg/ext/openexr/IlmBase/IlmThread/Makefile.am
Normal file
31
cs440-acg/ext/openexr/IlmBase/IlmThread/Makefile.am
Normal file
@@ -0,0 +1,31 @@
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
lib_LTLIBRARIES = libIlmThread.la
|
||||
|
||||
libIlmThread_la_SOURCES = IlmThreadPool.h IlmThread.h \
|
||||
IlmThreadSemaphore.h IlmThreadMutex.h \
|
||||
IlmThreadPool.cpp IlmThread.cpp \
|
||||
IlmThreadSemaphore.cpp IlmThreadMutex.cpp \
|
||||
IlmThreadPosix.cpp IlmThreadSemaphorePosix.cpp \
|
||||
IlmThreadSemaphorePosixCompat.cpp \
|
||||
IlmThreadMutexPosix.cpp
|
||||
|
||||
libIlmThread_la_LDFLAGS = -version-info @LIBTOOL_VERSION@ -no-undefined
|
||||
if LIB_SUFFIX_EXISTS
|
||||
libIlmThread_la_LDFLAGS += -release @LIB_SUFFIX@
|
||||
endif
|
||||
libIlmThread_la_LIBADD = ../Iex/libIex.la
|
||||
|
||||
libIlmThreadincludedir = $(includedir)/OpenEXR
|
||||
|
||||
libIlmThreadinclude_HEADERS = IlmThreadPool.h IlmThread.h \
|
||||
IlmThreadSemaphore.h IlmThreadMutex.h \
|
||||
IlmThreadNamespace.h IlmThreadForward.h \
|
||||
IlmThreadExport.h
|
||||
|
||||
noinst_HEADERS =
|
||||
|
||||
EXTRA_DIST = $(noinst_HEADERS) IlmThreadMutexWin32.cpp IlmThreadSemaphoreWin32.cpp \
|
||||
IlmThreadWin32.cpp CMakeLists.txt
|
||||
|
||||
INCLUDES = -I$(top_builddir) -I$(top_srcdir)/Iex -I$(top_srcdir)/config
|
Reference in New Issue
Block a user