Porting parallel stuff to unix.
This commit is contained in:
@ -25,6 +25,12 @@ namespace nv
|
||||
inline uint32 asUnsigned(int32 x) { return (uint32) x; }
|
||||
inline uint64 asUnsigned(int64 x) { return (uint64) x; }
|
||||
|
||||
template <typename T> inline uint32 toU32(T x) {
|
||||
nvDebugCheck(x <= UINT32_MAX);
|
||||
nvDebugCheck(x >= 0);
|
||||
return (uint32) x;
|
||||
}
|
||||
|
||||
/*
|
||||
template <typename T> inline int8 toI8(T x) {
|
||||
nvDebugCheck(x <= INT8_MAX);
|
||||
|
@ -61,7 +61,7 @@ namespace nv {
|
||||
*ptr = value; // on x86, stores are Release
|
||||
nvCompilerWriteBarrier();
|
||||
#else
|
||||
#error "Not implemented"
|
||||
#error "Atomics not implemented."
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -84,6 +84,25 @@ namespace nv {
|
||||
|
||||
return (uint32)_InterlockedDecrement((long *)value);
|
||||
}
|
||||
#elif NV_CC_GNUC
|
||||
// Many alternative implementations at:
|
||||
// http://www.memoryhole.net/kyle/2007/05/atomic_incrementing.html
|
||||
|
||||
inline uint32 atomicIncrement(uint32 * value)
|
||||
{
|
||||
nvDebugCheck((intptr_t(value) & 3) == 0);
|
||||
|
||||
return __sync_fetch_and_add(value, 1);
|
||||
}
|
||||
|
||||
inline uint32 atomicDecrement(uint32 * value)
|
||||
{
|
||||
nvDebugCheck((intptr_t(value) & 3) == 0);
|
||||
|
||||
return __sync_fetch_and_sub(value, 1);
|
||||
}
|
||||
#else
|
||||
#error "Atomics not implemented."
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
PROJECT(nvthreads)
|
||||
|
||||
SET(THREADS_SRCS
|
||||
nvthreads.h
|
||||
nvthread.h nvthread.cpp
|
||||
Atomic.h
|
||||
Event.h Event.cpp
|
||||
Mutex.h Mutex.cpp
|
||||
SpinWaiter.h SpinWaiter.cpp
|
||||
ParallelFor.h ParallelFor.cpp
|
||||
Thread.h Thread.cpp
|
||||
ThreadLocalStorage.h ThreadLocalStorage.cpp)
|
||||
ThreadPool.h ThreadPool.cpp)
|
||||
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
|
@ -48,5 +48,6 @@ void Event::wait() {
|
||||
}
|
||||
|
||||
#elif NV_OS_UNIX
|
||||
// @@
|
||||
// @@ TODO
|
||||
#pragma NV_MESSAGE("Implement event using pthreads!")
|
||||
#endif
|
||||
|
@ -86,4 +86,4 @@ void Mutex::unlock()
|
||||
nvDebugCheck(result == 0);
|
||||
}
|
||||
|
||||
#endif // NV_OS
|
||||
#endif // NV_OS_UNIX
|
||||
|
@ -25,7 +25,7 @@ namespace nv
|
||||
private:
|
||||
struct Private;
|
||||
AutoPtr<Private> m;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// Templated lock that can be used with any mutex.
|
||||
|
@ -23,6 +23,7 @@ struct Thread::Private
|
||||
void * arg;
|
||||
};
|
||||
|
||||
|
||||
#if NV_OS_WIN32
|
||||
|
||||
unsigned long __stdcall threadFunc(void * arg) {
|
||||
@ -32,11 +33,13 @@ unsigned long __stdcall threadFunc(void * arg) {
|
||||
}
|
||||
|
||||
#elif NV_OS_UNIX
|
||||
|
||||
extern "C" void * threadFunc(void * arg) {
|
||||
Thread * thread = (Thread *)arg;
|
||||
thread->func(thread->arg);
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -134,3 +137,4 @@ bool Thread::isRunning () const
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ namespace nv
|
||||
struct Private;
|
||||
AutoPtr<Private> p;
|
||||
|
||||
public:
|
||||
public: // @@ Why public? Also in private?!
|
||||
ThreadFunc * func;
|
||||
void * arg;
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "Mutex.h"
|
||||
#include "Thread.h"
|
||||
|
||||
#include "nvcore/Utils.h"
|
||||
|
||||
// Most of the time it's not necessary to protect the thread pool, but if it doesn't add a significant overhead, then it'd be safer to do it.
|
||||
#define PROTECT_THREAD_POOL 1
|
||||
|
||||
@ -47,7 +49,7 @@ AutoPtr<ThreadPool> s_pool;
|
||||
|
||||
|
||||
/*static*/ void ThreadPool::workerFunc(void * arg) {
|
||||
uint i = (uint)arg;
|
||||
uint i = toU32((uintptr_t)arg); // This is OK, because workerCount should always be <<< 2^32
|
||||
|
||||
while(true)
|
||||
{
|
||||
|
@ -1,11 +1,16 @@
|
||||
// This code is in the public domain -- Ignacio Casta<74>o <castano@gmail.com>
|
||||
|
||||
#include "nvthread.h"
|
||||
|
||||
#include "Thread.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define VC_EXTRALEAN
|
||||
#include <windows.h>
|
||||
#if NV_OS_WIN32
|
||||
#include "Win32.h"
|
||||
#elif NV_OS_UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
|
||||
using namespace nv;
|
||||
|
||||
|
@ -269,6 +269,10 @@ struct MyOutputHandler : public nvtt::OutputHandler
|
||||
m_ptr = m_data;
|
||||
}
|
||||
|
||||
virtual void endImage()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool writeData(const void * data, int size)
|
||||
{
|
||||
memcpy(m_ptr, data, size);
|
||||
|
Reference in New Issue
Block a user