nvidia-texture-tools/src/nvtt/TaskDispatcher.h

56 lines
1.2 KiB
C
Raw Normal View History

2010-11-22 07:34:05 +00:00
#include "nvtt.h"
// OpenMP
#if defined(HAVE_OPENMP)
#include <omp.h>
#endif
2010-11-26 07:20:23 +00:00
#if NV_OS_DARWIN && defined(HAVE_DISPATCH_H)
2010-11-22 07:34:05 +00:00
#include <dispatch/dispatch.h>
#endif
namespace nvtt {
struct SequentialTaskDispatcher : public TaskDispatcher
{
virtual void dispatch(Task * task, void * context, size_t count) {
for (size_t i = 0; i < count; i++) {
task(context, i);
}
}
};
2010-11-26 07:20:23 +00:00
#if NV_OS_DARWIN && defined(HAVE_DISPATCH_H)
2010-11-22 07:34:05 +00:00
// Task dispatcher using Apple's Grand Central Dispatch.
struct AppleTaskDispatcher : public TaskDispatcher
{
virtual void dispatch(Task * task, void * context, size_t count) {
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
dispatch_apply_f(count, q, context, task);
}
};
#endif
#if defined(HAVE_OPENMP)
struct OpenMPTaskDispatcher : public TaskDispatcher
{
virtual void dispatch(Task * task, void * context, size_t count) {
#pragma omp parallel
{
#pragma omp for
for (size_t i = 0; i < count; i++) {
task(context, i);
}
}
}
};
#endif
} // namespace nvtt