-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd58236
commit 3d78a71
Showing
2,399 changed files
with
343,719 additions
and
385,282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/ThirdParty/OpenEXR/IlmThreadQt/IlmThread/IlmThread.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "IlmThread.h" | ||
|
||
#include <QString> | ||
|
||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER | ||
|
||
bool supportsThreads() | ||
{ | ||
return true; | ||
} | ||
|
||
Thread::Thread() | ||
{ | ||
setObjectName(QString::fromLatin1("IlmThreadQt")); | ||
} | ||
|
||
Thread::~Thread() | ||
{ | ||
if(isRunning()) | ||
wait(); | ||
} | ||
|
||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#if !defined(ILM_QT_THREAD_H_INCLUDED) | ||
#define ILM_QT_THREAD_H_INCLUDED | ||
|
||
#include <QThread> | ||
|
||
#include "IlmBaseConfig.h" | ||
#include "IlmThreadNamespace.h" | ||
|
||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER | ||
|
||
bool supportsThreads(); | ||
|
||
class Thread : public QThread | ||
{ | ||
Q_DISABLE_COPY(Thread) | ||
|
||
public: | ||
Thread(); | ||
~Thread(); | ||
}; | ||
|
||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT | ||
|
||
#endif // ILM_QT_THREAD_H_INCLUDED |
18 changes: 18 additions & 0 deletions
18
src/ThirdParty/OpenEXR/IlmThreadQt/IlmThread/IlmThreadForward.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#if !defined(ILM_QT_THREAD_FORWARD_H_INCLUDED) | ||
#define ILM_QT_THREAD_FORWARD_H_INCLUDED | ||
|
||
#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 // ILM_QT_THREAD_FORWARD_H_INCLUDED |
42 changes: 42 additions & 0 deletions
42
src/ThirdParty/OpenEXR/IlmThreadQt/IlmThread/IlmThreadMutex.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "IlmThreadMutex.h" | ||
|
||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER | ||
|
||
Mutex::Mutex() | ||
{} | ||
|
||
Mutex::~Mutex() | ||
{} | ||
|
||
Lock::Lock(const Mutex &m, bool autoLock) | ||
: m_mutex(const_cast<Mutex&>(m)) | ||
, m_locked(false) | ||
{ | ||
if(autoLock) | ||
acquire(); | ||
} | ||
|
||
Lock::~Lock() | ||
{ | ||
if(m_locked) | ||
m_mutex.unlock(); | ||
} | ||
|
||
void Lock::acquire() | ||
{ | ||
m_mutex.lock(); | ||
m_locked = true; | ||
} | ||
|
||
void Lock::release() | ||
{ | ||
m_mutex.unlock(); | ||
m_locked = false; | ||
} | ||
|
||
bool Lock::locked() const | ||
{ | ||
return m_locked; | ||
} | ||
|
||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT |
39 changes: 39 additions & 0 deletions
39
src/ThirdParty/OpenEXR/IlmThreadQt/IlmThread/IlmThreadMutex.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#if !defined(ILM_QT_THREAD_MUTEX_H_INCLUDED) | ||
#define ILM_QT_THREAD_MUTEX_H_INCLUDED | ||
|
||
#include <QMutex> | ||
|
||
#include "IlmBaseConfig.h" | ||
#include "IlmThreadNamespace.h" | ||
|
||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_ENTER | ||
|
||
class Mutex : public QMutex | ||
{ | ||
Q_DISABLE_COPY(Mutex) | ||
|
||
public: | ||
Mutex(); | ||
~Mutex(); | ||
}; | ||
|
||
class Lock | ||
{ | ||
Q_DISABLE_COPY(Lock) | ||
|
||
public: | ||
Lock(const Mutex &m, bool autoLock = true); | ||
~Lock(); | ||
|
||
void acquire(); | ||
void release(); | ||
bool locked() const; | ||
|
||
private: | ||
Mutex &m_mutex; | ||
bool m_locked; | ||
}; | ||
|
||
ILMTHREAD_INTERNAL_NAMESPACE_HEADER_EXIT | ||
|
||
#endif // ILM_QT_THREAD_MUTEX_H_INCLUDED |
25 changes: 25 additions & 0 deletions
25
src/ThirdParty/OpenEXR/IlmThreadQt/IlmThread/IlmThreadNamespace.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#if !defined(ILM_QT_THREAD_NAMESPACE_H_INCLUDED) | ||
#define ILM_QT_THREAD_NAMESPACE_H_INCLUDED | ||
|
||
#include "IlmBaseConfig.h" | ||
|
||
#ifndef ILMTHREAD_NAMESPACE | ||
#define ILMTHREAD_NAMESPACE IlmThread | ||
#endif | ||
|
||
#ifndef ILMTHREAD_INTERNAL_NAMESPACE | ||
#define ILMTHREAD_INTERNAL_NAMESPACE ILMTHREAD_NAMESPACE | ||
#endif | ||
|
||
namespace ILMTHREAD_INTERNAL_NAMESPACE {} | ||
namespace ILMTHREAD_NAMESPACE { | ||
using namespace ILMTHREAD_INTERNAL_NAMESPACE; | ||
} | ||
|
||
#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 // ILM_QT_THREAD_NAMESPACE_H_INCLUDED |
119 changes: 119 additions & 0 deletions
119
src/ThirdParty/OpenEXR/IlmThreadQt/IlmThread/IlmThreadPool.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#include "IlmThreadPool.h" | ||
|
||
#include <QDebug> | ||
|
||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_ENTER | ||
|
||
TaskGroup::TaskGroup() | ||
: m_counter(0) | ||
{} | ||
|
||
TaskGroup::~TaskGroup() | ||
{ | ||
m_mutex.lock(); | ||
while(m_counter > 0) | ||
m_cond.wait(&m_mutex); | ||
m_mutex.unlock(); | ||
} | ||
|
||
void TaskGroup::incrementCounter() | ||
{ | ||
m_mutex.lock(); | ||
m_counter++; | ||
m_mutex.unlock(); | ||
} | ||
|
||
void TaskGroup::decrementCounter() | ||
{ | ||
m_mutex.lock(); | ||
m_counter--; | ||
m_mutex.unlock(); | ||
m_cond.wakeAll(); | ||
} | ||
|
||
Task::Task(TaskGroup *g) | ||
: m_runnable(new TaskImpl(this)) | ||
, m_group(g) | ||
{ | ||
m_group->incrementCounter(); | ||
} | ||
|
||
Task::~Task() | ||
{ | ||
m_group->decrementCounter(); | ||
} | ||
|
||
TaskGroup *Task::group() | ||
{ | ||
return m_group; | ||
} | ||
|
||
QRunnable *Task::runnable() | ||
{ | ||
return m_runnable; | ||
} | ||
|
||
Task::TaskImpl::TaskImpl(Task *task) | ||
: m_task(task) | ||
{} | ||
|
||
Task::TaskImpl::~TaskImpl() | ||
{ | ||
delete m_task; | ||
} | ||
|
||
void Task::TaskImpl::run() | ||
{ | ||
m_task->execute(); | ||
} | ||
|
||
ThreadPool::ThreadPool(unsigned numThreads) | ||
: m_threadPool(new QThreadPool) | ||
, m_isExternal(false) | ||
{ | ||
setNumThreads(static_cast<int>(numThreads)); | ||
} | ||
|
||
ThreadPool::ThreadPool(QThreadPool *pool) | ||
: m_threadPool(pool) | ||
, m_isExternal(true) | ||
{} | ||
|
||
ThreadPool::~ThreadPool() | ||
{ | ||
if(m_isExternal) | ||
return; | ||
m_threadPool->waitForDone(); | ||
m_threadPool->deleteLater(); | ||
} | ||
|
||
int ThreadPool::numThreads() const | ||
{ | ||
return m_threadPool->maxThreadCount(); | ||
} | ||
|
||
void ThreadPool::setNumThreads(int count) | ||
{ | ||
if(m_threadPool != QThreadPool::globalInstance()) | ||
m_threadPool->setMaxThreadCount(count); | ||
else | ||
qWarning() << "ThreadPool::setNumThreads() is not allowed for global thread pool"; | ||
} | ||
|
||
void ThreadPool::addTask(Task *task) | ||
{ | ||
m_threadPool->start(task->runnable()); | ||
} | ||
|
||
ThreadPool &ThreadPool::globalThreadPool() | ||
{ | ||
static ThreadPool globalPool(QThreadPool::globalInstance()); | ||
return globalPool; | ||
} | ||
|
||
void ThreadPool::addGlobalTask(Task *task) | ||
{ | ||
globalThreadPool().addTask(task); | ||
} | ||
|
||
ILMTHREAD_INTERNAL_NAMESPACE_SOURCE_EXIT |
Oops, something went wrong.