aboutsummaryrefslogtreecommitdiff
path: root/PxShared
diff options
context:
space:
mode:
authorMarijn Tamis <[email protected]>2017-07-31 13:52:20 +0200
committerMarijn Tamis <[email protected]>2017-07-31 13:52:20 +0200
commit223aff8b3f73bb786dce5c67b83ff55208d43969 (patch)
tree2e3e2760cb49afbf8d9379e23e27d175bbba27aa /PxShared
parentRemove unused copy of PxShared. (diff)
downloadnvcloth-223aff8b3f73bb786dce5c67b83ff55208d43969.tar.xz
nvcloth-223aff8b3f73bb786dce5c67b83ff55208d43969.zip
NvCloth 1.1.2 Release. (22576033)v1.1.2
Diffstat (limited to 'PxShared')
-rw-r--r--PxShared/src/foundation/include/nx/PsNXAbort.h26
-rw-r--r--PxShared/src/foundation/include/nx/PsNXIntrinsics.h135
-rw-r--r--PxShared/src/foundation/src/nx/PsNXAtomic.cpp84
-rw-r--r--PxShared/src/foundation/src/nx/PsNXCpu.cpp26
-rw-r--r--PxShared/src/foundation/src/nx/PsNXFPU.cpp45
-rw-r--r--PxShared/src/foundation/src/nx/PsNXMutex.cpp137
-rw-r--r--PxShared/src/foundation/src/nx/PsNXPrintString.cpp32
-rw-r--r--PxShared/src/foundation/src/nx/PsNXSList.cpp105
-rw-r--r--PxShared/src/foundation/src/nx/PsNXSocket.cpp417
-rw-r--r--PxShared/src/foundation/src/nx/PsNXSync.cpp132
-rw-r--r--PxShared/src/foundation/src/nx/PsNXThread.cpp404
-rw-r--r--PxShared/src/foundation/src/nx/PsNXTime.cpp70
12 files changed, 0 insertions, 1613 deletions
diff --git a/PxShared/src/foundation/include/nx/PsNXAbort.h b/PxShared/src/foundation/include/nx/PsNXAbort.h
deleted file mode 100644
index 3b0413e..0000000
--- a/PxShared/src/foundation/include/nx/PsNXAbort.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
- *
- * NVIDIA CORPORATION and its licensors retain all intellectual property
- * and proprietary rights in and to this software, related documentation
- * and any modifications thereto. Any use, reproduction, disclosure or
- * distribution of this software and related documentation without an express
- * license agreement from NVIDIA CORPORATION is strictly prohibited.
- */
-// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
-// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
-
-#ifndef PX_FOUNDATION_PX_NX_ABORT_H
-#define PX_FOUNDATION_PX_NX_ABORT_H
-
-#include "foundation/PxPreprocessor.h"
-#include "nn/nn_Assert.h"
-#include "nn/nn_Log.h"
-
-void abort(const char* message)
-{
- NN_LOG(message);
- NN_ASSERT(message == NULL);
-}
-
-#endif // PX_FOUNDATION_PX_NX_ABORT_H
diff --git a/PxShared/src/foundation/include/nx/PsNXIntrinsics.h b/PxShared/src/foundation/include/nx/PsNXIntrinsics.h
deleted file mode 100644
index 789e39c..0000000
--- a/PxShared/src/foundation/include/nx/PsNXIntrinsics.h
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
- *
- * NVIDIA CORPORATION and its licensors retain all intellectual property
- * and proprietary rights in and to this software, related documentation
- * and any modifications thereto. Any use, reproduction, disclosure or
- * distribution of this software and related documentation without an express
- * license agreement from NVIDIA CORPORATION is strictly prohibited.
- */
-// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
-// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
-
-
-#ifndef PX_FOUNDATION_PS_NX_INTRINSICS_H
-#define PX_FOUNDATION_PS_NX_INTRINSICS_H
-
-#include "Ps.h"
-#include "foundation/PxAssert.h"
-
-// this file is for internal intrinsics - that is, intrinsics that are used in
-// cross platform code but do not appear in the API
-
-#if !PX_NX
- #error "This file should only be included by NX builds!!"
-#endif
-
-#include <math.h>
-
-namespace physx
-{
-namespace shdfnd
-{
- /*
- * Implements a memory barrier
- */
- PX_FORCE_INLINE void memoryBarrier()
- {
- __sync_synchronize();
- }
-
- /*!
- Returns the index of the highest set bit. Not valid for zero arg.
- */
- PX_FORCE_INLINE PxU32 highestSetBitUnsafe(PxU32 v)
- {
- // http://graphics.stanford.edu/~seander/bithacks.html
- static const PxU32 MultiplyDeBruijnBitPosition[32] =
- {
- 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
- 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
- };
-
- v |= v >> 1; // first round up to one less than a power of 2
- v |= v >> 2;
- v |= v >> 4;
- v |= v >> 8;
- v |= v >> 16;
-
- return MultiplyDeBruijnBitPosition[(PxU32)(v * 0x07C4ACDDU) >> 27];
- }
-
- /*!
- Returns the index of the highest set bit. Undefined for zero arg.
- */
- PX_FORCE_INLINE PxU32 lowestSetBitUnsafe(PxU32 v)
- {
- // http://graphics.stanford.edu/~seander/bithacks.html
- static const PxU32 MultiplyDeBruijnBitPosition[32] =
- {
- 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
- 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
- };
- PxI32 w = v;
- return MultiplyDeBruijnBitPosition[(PxU32)((w & -w) * 0x077CB531U) >> 27];
- }
-
- /*!
- Returns the number of leading zeros in v. Returns 32 for v=0.
- */
- PX_FORCE_INLINE PxU32 countLeadingZeros(PxU32 v)
- {
- PxI32 result = 0;
- PxU32 testBit = (1<<31);
- while ((v & testBit) == 0 && testBit != 0)
- result ++, testBit >>= 1;
- return result;
- }
-
- /*!
- Prefetch aligned cache size around \c ptr+offset.
- */
- PX_FORCE_INLINE void prefetchLine(const void* ptr, PxU32 offset = 0)
- {
- __builtin_prefetch((char* PX_RESTRICT)(ptr) + offset, 0, 3);
- }
-
- /*!
- Prefetch \c count bytes starting at \c ptr.
- */
- PX_FORCE_INLINE void prefetch(const void* ptr, PxU32 count = 1)
- {
- const char* cp = (char*)ptr;
- PxU64 p = size_t(ptr);
- PxU64 startLine = p>>6, endLine = (p+count-1)>>6;
- PxU64 lines = endLine - startLine + 1;
- do
- {
- prefetchLine(cp);
- cp+=64;
- } while(--lines);
- }
-
- //! \brief platform-specific reciprocal
- PX_CUDA_CALLABLE PX_FORCE_INLINE float recipFast(float a) { return 1.0f/a; }
-
- //! \brief platform-specific fast reciprocal square root
- PX_CUDA_CALLABLE PX_FORCE_INLINE float recipSqrtFast(float a) { return 1.0f/::sqrtf(a); }
-
- //! \brief platform-specific floor
- PX_CUDA_CALLABLE PX_FORCE_INLINE float floatFloor(float x)
- {
- return ::floorf(x);
- }
-
- #define PX_PRINTF printf
- #define PX_EXPECT_TRUE(x) x
- #define PX_EXPECT_FALSE(x) x
-
-} // namespace shdfnd
-} // namespace physx
-
-#define PX_EXPECT_TRUE(x) x
-#define PX_EXPECT_FALSE(x) x
-
-#endif
diff --git a/PxShared/src/foundation/src/nx/PsNXAtomic.cpp b/PxShared/src/foundation/src/nx/PsNXAtomic.cpp
deleted file mode 100644
index 1ab5e6b..0000000
--- a/PxShared/src/foundation/src/nx/PsNXAtomic.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
- *
- * NVIDIA CORPORATION and its licensors retain all intellectual property
- * and proprietary rights in and to this software, related documentation
- * and any modifications thereto. Any use, reproduction, disclosure or
- * distribution of this software and related documentation without an express
- * license agreement from NVIDIA CORPORATION is strictly prohibited.
- */
-// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
-// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
-
-
-#define PAUSE() asm ("nop")
-
-#include "PsAtomic.h"
-
-namespace physx
-{
-namespace shdfnd
-{
-
-PxI32 atomicExchange(volatile PxI32* val,PxI32 val2)
-{
- PxI32 newVal, oldVal;
-
- do
- {
- PAUSE();
- oldVal = *val;
- newVal = val2;
- }
- while (atomicCompareExchange(val, newVal, oldVal) != oldVal);
-
- return oldVal;
-}
-
-PxI32 atomicCompareExchange(volatile PxI32* dest, PxI32 exch, PxI32 comp)
-{
- return __sync_val_compare_and_swap(dest, comp, exch);
-}
-
-void* atomicCompareExchangePointer(volatile void** dest, void* exch, void* comp)
-{
- return __sync_val_compare_and_swap((void**)dest, comp, exch);
-}
-
-PxI32 atomicIncrement(volatile PxI32* val)
-{
- return __sync_add_and_fetch(val, 1);
-}
-
-PxI32 atomicDecrement(volatile PxI32* val)
-{
- return __sync_sub_and_fetch(val, 1);
-}
-
-PxI32 atomicAdd(volatile PxI32* val, PxI32 delta)
-{
- return __sync_add_and_fetch(val, delta);
-}
-
-PxI32 atomicMax(volatile PxI32* val, PxI32 val2)
-{
- PxI32 oldVal, newVal;
-
- do
- {
- PAUSE();
- oldVal = *val;
-
- if (val2 > oldVal)
- newVal = val2;
- else
- newVal = oldVal;
-
- }
- while (atomicCompareExchange(val, newVal, oldVal) != oldVal);
-
- return *val;
-}
-
-} // namespace shdfnd
-} // namespace physx
diff --git a/PxShared/src/foundation/src/nx/PsNXCpu.cpp b/PxShared/src/foundation/src/nx/PsNXCpu.cpp
deleted file mode 100644
index 47c1354..0000000
--- a/PxShared/src/foundation/src/nx/PsNXCpu.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
- *
- * NVIDIA CORPORATION and its licensors retain all intellectual property
- * and proprietary rights in and to this software, related documentation
- * and any modifications thereto. Any use, reproduction, disclosure or
- * distribution of this software and related documentation without an express
- * license agreement from NVIDIA CORPORATION is strictly prohibited.
- */
-// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
-// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
-
-
-#include "PsCpu.h"
-
-#define cpuid(op, reg) reg[0]=reg[1]=reg[2]=reg[3]=0;
-
-namespace physx { namespace shdfnd {
-
- physx::PxU8 Cpu::getCpuId()
- {
- PxU32 cpuInfo[4];
- cpuid(1, cpuInfo);
- return static_cast<physx::PxU8>( cpuInfo[1] >> 24 ); // APIC Physical ID
- }
-}}
diff --git a/PxShared/src/foundation/src/nx/PsNXFPU.cpp b/PxShared/src/foundation/src/nx/PsNXFPU.cpp
deleted file mode 100644
index a94354f..0000000
--- a/PxShared/src/foundation/src/nx/PsNXFPU.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
- *
- * NVIDIA CORPORATION and its licensors retain all intellectual property
- * and proprietary rights in and to this software, related documentation
- * and any modifications thereto. Any use, reproduction, disclosure or
- * distribution of this software and related documentation without an express
- * license agreement from NVIDIA CORPORATION is strictly prohibited.
- */
-// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
-// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
-#include "PsFPU.h"
-
-#include <cfenv>
-
-physx::shdfnd::FPUGuard::FPUGuard()
-{
- PX_COMPILE_TIME_ASSERT(sizeof(fenv_t) <= sizeof(mControlWords));
-
- fegetenv(reinterpret_cast<fenv_t*>(mControlWords));
- fesetenv(FE_DFL_ENV);
-
- // NX does not seem to support fedisableexcept
- //fedisableexcept(FE_ALL_EXCEPT);
-
- fesetround(FE_TONEAREST); // since this does not seem to be the default mode
-}
-
-physx::shdfnd::FPUGuard::~FPUGuard()
-{
- fesetenv(reinterpret_cast<fenv_t*>(mControlWords));
-}
-
-PX_FOUNDATION_API void physx::shdfnd::enableFPExceptions()
-{
- // NX does not seem to support feenableexcept
- //feclearexcept(FE_ALL_EXCEPT);
- //feenableexcept(FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW);
-}
-
-PX_FOUNDATION_API void physx::shdfnd::disableFPExceptions()
-{
- // NX does not seem to support fedisableexcept
- //fedisableexcept(FE_ALL_EXCEPT);
-}
diff --git a/PxShared/src/foundation/src/nx/PsNXMutex.cpp b/PxShared/src/foundation/src/nx/PsNXMutex.cpp
deleted file mode 100644
index 6d3334a..0000000
--- a/PxShared/src/foundation/src/nx/PsNXMutex.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
- *
- * NVIDIA CORPORATION and its licensors retain all intellectual property
- * and proprietary rights in and to this software, related documentation
- * and any modifications thereto. Any use, reproduction, disclosure or
- * distribution of this software and related documentation without an express
- * license agreement from NVIDIA CORPORATION is strictly prohibited.
- */
-// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
-// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
-
-
-#include <atomic>
-#include "nn/os/os_Mutex.h"
-#include "PsFoundation.h"
-#include "PsAllocator.h"
-#include "PsMutex.h"
-#include "PsThread.h"
-
-namespace physx
-{
-namespace shdfnd
-{
-
-namespace
-{
- struct MutexNXImpl
- {
- nn::os::MutexType lock;
- Thread::Id owner;
- };
-
- MutexNXImpl* getMutex(MutexImpl* impl)
- {
- return reinterpret_cast<MutexNXImpl*>(impl);
- }
-}
-
-MutexImpl::MutexImpl()
-{
- nn::os::InitializeMutex(&getMutex(this)->lock, true, 0);
-}
-
-MutexImpl::~MutexImpl()
-{
- nn::os::FinalizeMutex(&getMutex(this)->lock);
-}
-
-void MutexImpl::lock()
-{
- nn::os::LockMutex(&getMutex(this)->lock);
-
-#ifdef PX_DEBUG
- getMutex(this)->owner = Thread::getId();
-#endif
-}
-
-bool MutexImpl::trylock()
-{
- bool success = nn::os::TryLockMutex(&getMutex(this)->lock);
-#ifdef PX_DEBUG
- if (success)
- getMutex(this)->owner = Thread::getId();
-#endif
- return success;
-}
-
-void MutexImpl::unlock()
-{
-#ifdef PX_DEBUG
- // ensure we are already holding the lock
- if (getMutex(this)->owner != Thread::getId())
- {
- getFoundation().error(PxErrorCode::eINVALID_OPERATION, __FILE__, __LINE__, "Mutex must be unlocked only by thread that has already acquired lock");
- return;
- }
-#endif
-
- nn::os::UnlockMutex(&getMutex(this)->lock);
-}
-
-static const PxU32 gSize = sizeof(MutexNXImpl);
-
-const PxU32& MutexImpl::getSize() { return gSize; }
-
-class ReadWriteLockImpl
-{
- PX_NOCOPY(ReadWriteLockImpl)
-public:
- ReadWriteLockImpl() : readerCount(0) {}
- Mutex mutex;
- std::atomic<int> readerCount; //handle recursive writer locking
-};
-
-ReadWriteLock::ReadWriteLock()
-{
- mImpl = reinterpret_cast<ReadWriteLockImpl*>(PX_ALLOC(sizeof(ReadWriteLockImpl), PX_DEBUG_EXP("ReadWriteLockImpl")));
- PX_PLACEMENT_NEW(mImpl, ReadWriteLockImpl);
-}
-
-ReadWriteLock::~ReadWriteLock()
-{
- mImpl->~ReadWriteLockImpl();
- PX_FREE( mImpl );
-}
-
-void ReadWriteLock::lockReader()
-{
- mImpl->mutex.lock();
-
- mImpl->readerCount.fetch_add(1);
-
- mImpl->mutex.unlock();
-}
-
-void ReadWriteLock::lockWriter()
-{
- mImpl->mutex.lock();
-
- // spin lock until no readers
- while (mImpl->readerCount);
-}
-
-void ReadWriteLock::unlockReader()
-{
- mImpl->readerCount.fetch_sub(1);
-}
-
-void ReadWriteLock::unlockWriter()
-{
- mImpl->mutex.unlock();
-}
-
-} // namespace shdfnd
-} // namespace physx
-
diff --git a/PxShared/src/foundation/src/nx/PsNXPrintString.cpp b/PxShared/src/foundation/src/nx/PsNXPrintString.cpp
deleted file mode 100644
index be5f5ec..0000000
--- a/PxShared/src/foundation/src/nx/PsNXPrintString.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
- *
- * NVIDIA CORPORATION and its licensors retain all intellectual property
- * and proprietary rights in and to this software, related documentation
- * and any modifications thereto. Any use, reproduction, disclosure or
- * distribution of this software and related documentation without an express
- * license agreement from NVIDIA CORPORATION is strictly prohibited.
- */
-// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
-// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
-
-#include "PsString.h"
-
-#include <cstdio>
-#include <cstdarg>
-
-#include "nn/nn_Log.h"
-
-namespace physx
-{
-namespace shdfnd
-{
-
-void printString(const char* str)
-{
- NN_LOG(str);
- NN_LOG("\n");
-}
-
-} // namespace shdfnd
-} // namespace physx
diff --git a/PxShared/src/foundation/src/nx/PsNXSList.cpp b/PxShared/src/foundation/src/nx/PsNXSList.cpp
deleted file mode 100644
index b6258cf..0000000
--- a/PxShared/src/foundation/src/nx/PsNXSList.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
- *
- * NVIDIA CORPORATION and its licensors retain all intellectual property
- * and proprietary rights in and to this software, related documentation
- * and any modifications thereto. Any use, reproduction, disclosure or
- * distribution of this software and related documentation without an express
- * license agreement from NVIDIA CORPORATION is strictly prohibited.
- */
-// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
-// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
-
-
-#include "PsThread.h" // for PxSpinLockPause()
-#include "PsSList.h"
-
-namespace physx
-{
-namespace shdfnd
-{
- namespace
- {
- struct ScopedSpinLock
- {
- private:
- PX_NOCOPY(ScopedSpinLock)
-
- public:
- // !!!pthread version need to check
- PX_FORCE_INLINE ScopedSpinLock(volatile PxI32& lock): mLock(lock)
- {
- while (__sync_lock_test_and_set(&mLock, 1))
- {
- // spinning without atomics is usually
- // causing less bus traffic. -> only one
- // CPU is modifying the cache line.
- while(lock)
- PxSpinLockPause();
- }
- }
-
- PX_FORCE_INLINE ~ScopedSpinLock()
- {
- __sync_lock_release(&mLock);
- }
- private:
- volatile PxI32& mLock;
- };
-
- struct SListDetail
- {
- SListEntry* head;
- volatile PxI32 lock;
- };
-
- template <typename T>
- SListDetail* getDetail(T* impl)
- {
- return reinterpret_cast<SListDetail*>(impl);
- }
- }
-
- SListImpl::SListImpl()
- {
- getDetail(this)->head = NULL;
- getDetail(this)->lock = 0; // 0 == unlocked
- }
-
- SListImpl::~SListImpl()
- {
- }
-
- void SListImpl::push(SListEntry* entry)
- {
- ScopedSpinLock lock(getDetail(this)->lock);
- entry->mNext = getDetail(this)->head;
- getDetail(this)->head = entry;
- }
-
- SListEntry* SListImpl::pop()
- {
- ScopedSpinLock lock(getDetail(this)->lock);
- SListEntry* result = getDetail(this)->head;
- if( result != NULL )
- getDetail(this)->head = result->mNext;
- return result;
- }
-
- SListEntry* SListImpl::flush()
- {
- ScopedSpinLock lock(getDetail(this)->lock);
- SListEntry* result = getDetail(this)->head;
- getDetail(this)->head = NULL;
- return result;
- }
-
- static const PxU32 gSize = sizeof(SListDetail);
-
- const PxU32& SListImpl::getSize()
- {
- return gSize;
- }
-
-} // namespace shdfnd
-} // namespace physx
diff --git a/PxShared/src/foundation/src/nx/PsNXSocket.cpp b/PxShared/src/foundation/src/nx/PsNXSocket.cpp
deleted file mode 100644
index 735ab20..0000000
--- a/PxShared/src/foundation/src/nx/PsNXSocket.cpp
+++ /dev/null
@@ -1,417 +0,0 @@
-/*
- * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
- *
- * NVIDIA CORPORATION and its licensors retain all intellectual property
- * and proprietary rights in and to this software, related documentation
- * and any modifications thereto. Any use, reproduction, disclosure or
- * distribution of this software and related documentation without an express
- * license agreement from NVIDIA CORPORATION is strictly prohibited.
- */
-// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
-// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
-
-#include "PsFoundation.h"
-#include "PsSocket.h"
-#include "PsThread.h"
-#include "PsArray.h"
-#include "foundation/PxMemory.h"
-
-#include <nn/socket.h>
-#include <nn/nn_Log.h>
-
-#define SOCKET_ERROR -1
-
-namespace physx
-{
-namespace shdfnd
-{
-
-const PxU32 Socket::DEFAULT_BUFFER_SIZE = 32768;
-
-class SocketImpl
-{
-public:
- SocketImpl(bool isBlocking);
- virtual ~SocketImpl();
-
- bool init();
- bool connect(const char* host, PxU16 port, PxU32 timeout);
- void disconnect();
- bool listen(PxU16 /*port*/)
- {
- return false; // not implemented on this platform
- }
- bool accept(bool /*block*/)
- {
- return false; // not implemented on this platform
- }
-
- void setBlocking(bool blocking);
-
- virtual PxU32 write(const PxU8* data, PxU32 length);
- virtual bool flush();
-
- PxU32 read(PxU8* data, PxU32 length);
-
- static void* allocate(size_t size) { return PX_ALLOC(size, "Socket"); }
- static void deallocate(void* mem, size_t) { PX_FREE(mem); }
-
- PX_FORCE_INLINE bool isBlocking() const { return mIsBlocking; }
- PX_FORCE_INLINE bool isConnected() const { return mIsConnected; }
- PX_FORCE_INLINE const char* getHost() const { return mHost; }
- PX_FORCE_INLINE PxU16 getPort() const { return mPort; }
-
-protected:
- int mSocket;
- const char* mHost;
- PxU16 mPort;
- bool mIsConnected;
- bool mIsBlocking;
-};
-
-
-class BufferedSocketImpl: public SocketImpl
-{
-public:
- BufferedSocketImpl(bool isBlocking);
- virtual ~BufferedSocketImpl() {};
- bool flush();
- PxU32 write(const PxU8* data, PxU32 length);
-
-private:
- PxU32 mBufferPos;
- PxU8 mBuffer[Socket::DEFAULT_BUFFER_SIZE];
-};
-
-BufferedSocketImpl::BufferedSocketImpl(bool isBlocking)
- : SocketImpl(isBlocking)
- , mBufferPos(0)
-{}
-
-
-SocketImpl::SocketImpl(bool isBlocking)
- : mSocket(SOCKET_ERROR)
- , mHost(NULL)
- , mPort(0)
- , mIsConnected(false)
- , mIsBlocking(isBlocking)
-{
-}
-
-
-SocketImpl::~SocketImpl()
-{
-}
-
-
-bool SocketImpl::init()
-{
- mSocket = nn::socket::Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- return (mSocket != SOCKET_ERROR);
-}
-
-
-void SocketImpl::setBlocking(bool blocking)
-{
- if (blocking != mIsBlocking)
- {
- int mode = nn::socket::Fcntl(mSocket, F_GETFL, 0);
- if (!blocking)
- mode |= O_NONBLOCK;
- else
- mode &= ~O_NONBLOCK;
- int ret = nn::socket::Fcntl(mSocket, F_SETFL, mode);
- if (ret != SOCKET_ERROR)
- mIsBlocking = blocking;
- }
-}
-
-
-bool SocketImpl::flush()
-{
- return true;
-};
-
-
-bool SocketImpl::connect(const char* host, PxU16 port, PxU32 timeout)
-{
- if (!init())
- return false;
-
- setBlocking(false);
-
- sockaddr_in socketAddress;
- socketAddress.sin_family = AF_INET;
- socketAddress.sin_port = nn::socket::InetHtons(port);
-
- // get host part
- int result = nn::socket::InetPton(AF_INET, host, &socketAddress.sin_addr);
- PX_UNUSED(result);
- PX_ASSERT(result != SOCKET_ERROR);
-
- if (nn::socket::Connect(mSocket, (sockaddr*)&socketAddress, sizeof(socketAddress)) < 0)
- {
- if (nn::socket::GetLastErrno() != EINPROGRESS)
- {
- disconnect();
- return false;
- }
-
- //Use poll function call to monitor the connect call.
- pollfd socketDesc;
- socketDesc.fd = mSocket;
- socketDesc.events = POLLOUT;
- socketDesc.revents = 0;
- int pollret = nn::socket::Poll(&socketDesc, 1, static_cast<int>(timeout));
- if (pollret != 1 || (socketDesc.revents & POLLERR) || !(socketDesc.revents & POLLOUT))
- {
- disconnect();
- return false;
- }
-
- // check if we are really connected, above code seems to return
- // true if host is a unix machine even if the connection was
- // not accepted.
- char buffer;
- if(nn::socket::Recv(mSocket, (void*)&buffer, 0, 0) < 0)
- {
- if(nn::socket::GetLastErrno() != EWOULDBLOCK)
- {
- disconnect();
- return false;
- }
- }
- }
-
- setBlocking(mIsBlocking);
- mIsConnected = true;
- mPort = port;
- mHost = host;
-
- return true;
-}
-
-
-void SocketImpl::disconnect()
-{
- if (mSocket != SOCKET_ERROR)
- {
- int result;
- if (mIsConnected)
- {
- setBlocking(true);
- result = nn::socket::Shutdown(mSocket, SHUT_RDWR);
- PX_UNUSED(result);
- PX_ASSERT(result != SOCKET_ERROR);
- }
-
- result = nn::socket::Close(mSocket);
- PX_UNUSED(result);
- PX_ASSERT(result != SOCKET_ERROR);
- mSocket = SOCKET_ERROR;
- }
-
- mIsConnected = false;
- mPort = 0;
- mHost = NULL;
-}
-
-
-PxU32 SocketImpl::write(const PxU8* data, PxU32 length)
-{
- int sent = 0;
- while((sent = nn::socket::Send(mSocket, (const void*)data, (size_t)length, 0)) == SOCKET_ERROR)
- {
- if(nn::socket::GetLastErrno() != EWOULDBLOCK)
- {
- mIsConnected = false;
- return 0;
- }
- }
-
- return (PxU32)sent;
-}
-
-
-PxU32 SocketImpl::read(PxU8* data, PxU32 length)
-{
- int bytesReceived = 0;
-
- // If out of receive buffer, increase it
- while((bytesReceived = nn::socket::Recv(mSocket, (void*)data, (size_t)length, 0)) == SOCKET_ERROR &&
- nn::socket::GetLastErrno() == ENOBUFS)
- {
- int iBuffSize = (int)length;
-
- // terminate the loop if we cannot increase the buffer size
- if(nn::socket::SetSockOpt(mSocket, SOL_SOCKET, SO_RCVBUF, (void*)&iBuffSize, sizeof(int)) != 0)
- break;
- }
-
- if(bytesReceived <= 0)
- {
- bytesReceived = 0;
- mIsConnected = false;
- }
-
- return PxU32(bytesReceived);
-}
-
-
-bool BufferedSocketImpl::flush()
-{
- PxU32 totalBytesWritten = 0;
- PxI32 bytesWritten = 1;
- while(totalBytesWritten < mBufferPos && bytesWritten > 0)
- {
- bytesWritten = SocketImpl::write(mBuffer+totalBytesWritten, mBufferPos-totalBytesWritten);
- if(bytesWritten > 0)
- totalBytesWritten += bytesWritten;
- }
- bool ret = (totalBytesWritten == mBufferPos);
- mBufferPos = 0;
- return ret;
-}
-
-
-PxU32 BufferedSocketImpl::write(const PxU8* data, PxU32 length)
-{
- PxU32 bytesWritten = 0;
- while(length > (Socket::DEFAULT_BUFFER_SIZE - mBufferPos))
- {
- PxU32 currentChunk = Socket::DEFAULT_BUFFER_SIZE - mBufferPos;
- PxMemCopy(mBuffer+mBufferPos, data+bytesWritten, currentChunk);
- mBufferPos = Socket::DEFAULT_BUFFER_SIZE;
- if(!flush())
- {
- disconnect();
- return bytesWritten;
- }
- bytesWritten += currentChunk;
- length -= currentChunk;
- }
- if(length > 0)
- {
- PxMemCopy(mBuffer+mBufferPos, data+bytesWritten, length);
- bytesWritten += length;
- mBufferPos += length;
- }
- if(mBufferPos == Socket::DEFAULT_BUFFER_SIZE)
- {
- if (!flush())
- {
- disconnect();
- return bytesWritten;
- }
- }
- return bytesWritten;
-}
-
-
-Socket::Socket(bool inEnableBuffering, bool blocking)
-{
- if (inEnableBuffering)
- {
- void* mem = PX_ALLOC(sizeof(BufferedSocketImpl), PX_DEBUG_EXP("BufferedSocketImpl"));
- mImpl = PX_PLACEMENT_NEW(mem, BufferedSocketImpl)(blocking);
- }
- else
- {
- void* mem = PX_ALLOC(sizeof(SocketImpl), PX_DEBUG_EXP("SocketImpl"));
- mImpl = PX_PLACEMENT_NEW(mem, SocketImpl)(blocking);
- }
-}
-
-
-Socket::~Socket()
-{
- mImpl->flush();
- mImpl->disconnect();
- mImpl->~SocketImpl();
- PX_FREE(mImpl);
-}
-
-
-bool Socket::connect(const char* host, PxU16 port, PxU32 timeout)
-{
- return mImpl->connect(host, port, timeout);
-}
-
-
-bool Socket::listen(PxU16 port)
-{
- return mImpl->listen(port);
-}
-
-
-bool Socket::accept(bool block)
-{
- return mImpl->accept(block);
-}
-
-
-void Socket::disconnect()
-{
- mImpl->disconnect();
-}
-
-
-bool Socket::isConnected() const
-{
- return mImpl->isConnected();
-}
-
-
-const char* Socket::getHost() const
-{
- return mImpl->getHost();
-}
-
-
-PxU16 Socket::getPort() const
-{
- return mImpl->getPort();
-}
-
-
-bool Socket::flush()
-{
- if(!mImpl->isConnected())
- return false;
- return mImpl->flush();
-}
-
-
-PxU32 Socket::write(const PxU8* data, PxU32 length)
-{
- if(!mImpl->isConnected())
- return 0;
- return mImpl->write(data, length);
-}
-
-
-PxU32 Socket::read(PxU8* data, PxU32 length)
-{
- if(!mImpl->isConnected())
- return 0;
- return mImpl->read(data, length);
-}
-
-
-void Socket::setBlocking(bool blocking)
-{
- if(!mImpl->isConnected())
- return;
- mImpl->setBlocking(blocking);
-}
-
-
-bool Socket::isBlocking() const
-{
- if(!mImpl->isConnected())
- return true;
- return mImpl->isBlocking();
-}
-
-} // namespace shdfnd
-} // namespace physx
diff --git a/PxShared/src/foundation/src/nx/PsNXSync.cpp b/PxShared/src/foundation/src/nx/PsNXSync.cpp
deleted file mode 100644
index 0a9566d..0000000
--- a/PxShared/src/foundation/src/nx/PsNXSync.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
- *
- * NVIDIA CORPORATION and its licensors retain all intellectual property
- * and proprietary rights in and to this software, related documentation
- * and any modifications thereto. Any use, reproduction, disclosure or
- * distribution of this software and related documentation without an express
- * license agreement from NVIDIA CORPORATION is strictly prohibited.
- */
-// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
-// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
-
-
-#include "nn/os/os_ConditionVariable.h"
-#include "nn/os/os_Tick.h"
-#include "nn/nn_TimeSpan.h"
-#include "nn/os/os_Mutex.h"
-#include "foundation/PxAssert.h"
-#include "PsSync.h"
-
-
-namespace physx
-{
-namespace shdfnd
-{
- namespace
- {
- class _SyncImpl
- {
- public:
- nn::os::ConditionVariableType syncCondVar; // note: nn::os::EventType is not used because nn::os::ClearEvent() is not atomic
- nn::os::MutexType syncMutex;
- volatile PxI32 setCounter;
- volatile bool is_set;
- };
-
- _SyncImpl* getSync(SyncImpl* impl)
- {
- return reinterpret_cast<_SyncImpl*>(impl);
- }
- }
-
- static const PxU32 gSize = sizeof(_SyncImpl);
- const PxU32& SyncImpl::getSize() { return gSize; }
-
- struct PxNXScopedLock
- {
- private:
- PX_NOCOPY(PxNXScopedLock)
-
- public:
- PxNXScopedLock(nn::os::MutexType& lock) : mLock(lock) { nn::os::LockMutex(&mLock); }
- ~PxNXScopedLock() { nn::os::UnlockMutex(&mLock); }
-
- private:
- nn::os::MutexType& mLock;
- };
-
- SyncImpl::SyncImpl()
- {
- _SyncImpl* syncImpl = getSync(this);
- nn::os::InitializeMutex(&syncImpl->syncMutex, false, 0); // non-recursive is correct even if it might be slightly confusing the way it is used but nn::os::WaitConditionVariable() unlocks and locks again
- nn::os::InitializeConditionVariable(&syncImpl->syncCondVar);
- syncImpl->setCounter = 0;
- syncImpl->is_set = false;
- }
-
- SyncImpl::~SyncImpl()
- {
- _SyncImpl* syncImpl = getSync(this);
- nn::os::FinalizeConditionVariable(&syncImpl->syncCondVar);
- nn::os::FinalizeMutex(&syncImpl->syncMutex);
- }
-
- void SyncImpl::reset()
- {
- _SyncImpl* syncImpl = getSync(this);
- PxNXScopedLock lock(syncImpl->syncMutex);
- syncImpl->is_set = false;
- }
-
- void SyncImpl::set()
- {
- _SyncImpl* syncImpl = getSync(this);
- PxNXScopedLock lock(syncImpl->syncMutex);
- if(!syncImpl->is_set)
- {
- syncImpl->setCounter++;
- syncImpl->is_set = true;
- nn::os::BroadcastConditionVariable(&syncImpl->syncCondVar);
- }
- }
-
- bool SyncImpl::wait(PxU32 milliseconds)
- {
- _SyncImpl* syncImpl = getSync(this);
- PxNXScopedLock lock(syncImpl->syncMutex);
- PxI32 lastSetCounter = syncImpl->setCounter;
- if(!getSync(this)->is_set)
- {
- if(milliseconds == static_cast<PxU32>(-1))
- {
- // have to loop here and check is_set since WaitConditionVariable can return even
- // if it was not signaled by BroadcastConditionVariable
- while((!syncImpl->is_set) && (lastSetCounter == syncImpl->setCounter))
- nn::os::WaitConditionVariable(&syncImpl->syncCondVar, &syncImpl->syncMutex);
- PX_ASSERT(syncImpl->is_set || (lastSetCounter != syncImpl->setCounter));
- }
- else
- {
- const int64_t ticksToWait = (static_cast<int64_t>(milliseconds) * nn::os::GetSystemTickFrequency()) / 1000;
- const int64_t targetCounter = nn::os::GetSystemTick().GetInt64Value() + ticksToWait;
- const int64_t targetCounterWithMargin = targetCounter - (targetCounter >> 4) + 1; // allow for a bit of error in the wait time (around 6%)
-
- // have to loop here and check is_set since TimedWaitConditionVariable can return even
- // if it was not signaled by BroadcastConditionVariable. Note: to keep it simple, the elapsed
- // time is not taken into account in such a case and the original wait time will be used again.
- bool timeLimitOk = true;
- while((!syncImpl->is_set) && (lastSetCounter == syncImpl->setCounter) && timeLimitOk)
- {
- nn::os::TimedWaitConditionVariable(&syncImpl->syncCondVar, &syncImpl->syncMutex, nn::os::ConvertToTimeSpan(nn::os::Tick(ticksToWait)));
- timeLimitOk = nn::os::GetSystemTick().GetInt64Value() <= targetCounterWithMargin;
- }
- PX_ASSERT(syncImpl->is_set || (lastSetCounter != syncImpl->setCounter) || (!timeLimitOk));
- }
- }
-
- return syncImpl->is_set || (lastSetCounter != syncImpl->setCounter);
- }
-
-} // namespace shdfnd
-} // namespace physx
diff --git a/PxShared/src/foundation/src/nx/PsNXThread.cpp b/PxShared/src/foundation/src/nx/PsNXThread.cpp
deleted file mode 100644
index a792a66..0000000
--- a/PxShared/src/foundation/src/nx/PsNXThread.cpp
+++ /dev/null
@@ -1,404 +0,0 @@
-/*
- * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
- *
- * NVIDIA CORPORATION and its licensors retain all intellectual property
- * and proprietary rights in and to this software, related documentation
- * and any modifications thereto. Any use, reproduction, disclosure or
- * distribution of this software and related documentation without an express
- * license agreement from NVIDIA CORPORATION is strictly prohibited.
- */
-// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
-// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
-
-#include <atomic>
-#include "PsFoundation.h"
-#include "nn/os/os_Thread.h"
-#include "nn/nn_TimeSpan.h"
-
-#include "PsBitUtils.h"
-#include "PsThread.h"
-#include "foundation/PxAssert.h"
-
-
-namespace physx
-{
-namespace shdfnd
-{
-
-namespace
-{
- class _ThreadImpl
- {
- PX_NOCOPY(_ThreadImpl)
-
- public:
- enum State
- {
- NotStarted,
- Started,
- Stopped
- };
-
- nn::os::ThreadType nativeThread;
-
- PxU8* stackMemory;
- int threadAffinity;
-
- std::atomic<int> quitNow;
- State state;
-
- ThreadImpl::ExecuteFn fn;
- void* arg;
-
- static const int sInvalidAffinityMask = 0xffffffff;
- };
-
- _ThreadImpl* getThread(ThreadImpl* impl)
- {
- return reinterpret_cast<_ThreadImpl*>(impl);
- }
-
- PX_FORCE_INLINE void initThreadImpl(_ThreadImpl* threadImpl)
- {
- threadImpl->nativeThread._basePriority = nn::os::DefaultThreadPriority;
- threadImpl->nativeThread._namePointer = NULL;
- threadImpl->state = _ThreadImpl::NotStarted;
- threadImpl->quitNow = 0;
- threadImpl->threadAffinity = _ThreadImpl::sInvalidAffinityMask;
- threadImpl->fn = NULL;
- threadImpl->arg = NULL;
- threadImpl->stackMemory = NULL;
- }
-
- void ThreadStart(void* ptrArg)
- {
- // then run either the passed in function or execute from the derived class (Runnable).
- _ThreadImpl* impl = getThread(reinterpret_cast<ThreadImpl*>(ptrArg));
- if(impl->fn)
- (*impl->fn)(impl->arg);
- else if(impl->arg)
- (static_cast<Runnable*>(impl->arg))->execute();
- }
-
- PX_FORCE_INLINE void* allocateStackMemory(size_t size)
- {
- size_t pad = (nn::os::StackRegionAlignment - 1) + sizeof(size_t); // store offset for delete.
- PxU8* base = reinterpret_cast<PxU8*>(::malloc(size + pad));
- if (!base)
- return NULL;
-
- PxU8* ptr = reinterpret_cast<PxU8*>(size_t(base + pad) & ~(nn::os::StackRegionAlignment - 1)); // aligned pointer
- (reinterpret_cast<size_t*>(ptr))[-1] = static_cast<size_t>(ptr - base); // store offset
-
- return ptr;
- }
-
- PX_FORCE_INLINE void freeStackMemory(void* ptr)
- {
- if (ptr == NULL)
- return;
-
- PxU8* base = reinterpret_cast<PxU8*>(ptr) - (reinterpret_cast<size_t*>(ptr))[-1];
- ::free(base);
- }
-}
-
-static const PxU32 gSize = sizeof(_ThreadImpl);
-const PxU32& ThreadImpl::getSize() { return gSize; }
-
-
-ThreadImpl::Id ThreadImpl::getId()
-{
- return reinterpret_cast<Id>(nn::os::GetCurrentThread());
-}
-
-ThreadImpl::ThreadImpl()
-{
- initThreadImpl(getThread(this));
-}
-
-ThreadImpl::ThreadImpl(ExecuteFn fn, void* arg)
-{
- _ThreadImpl* tImpl = getThread(this);
-
- initThreadImpl(tImpl);
-
- tImpl->fn = fn;
- tImpl->arg = arg;
-
- start(0, NULL);
-}
-
-ThreadImpl::~ThreadImpl()
-{
- _ThreadImpl* tImpl = getThread(this);
-
- if ((tImpl->state != _ThreadImpl::NotStarted) && (tImpl->stackMemory != NULL))
- {
- nn::os::DestroyThread(&tImpl->nativeThread);
- freeStackMemory(reinterpret_cast<void*>(tImpl->stackMemory));
- }
-}
-
-PxU32 ThreadImpl::getDefaultStackSize()
-{
- const PxU32 defaultSize = 524288;
- PX_COMPILE_TIME_ASSERT((defaultSize % nn::os::StackRegionAlignment) == 0);
- return defaultSize;
-}
-
-void ThreadImpl::start(PxU32 stackSize, Runnable* runnable)
-{
- _ThreadImpl* tImpl = getThread(this);
- if(tImpl->state != _ThreadImpl::NotStarted)
- return;
- tImpl->state = _ThreadImpl::Started;
-
- PxU32 newStackSize = getDefaultStackSize();
- if(stackSize != 0)
- newStackSize = stackSize;
-
- PX_ASSERT((newStackSize % nn::os::StackRegionAlignment) == 0);
-
- // need to provide stack memory as well
- // (for other platforms, the system allocates the stack memory, hence it seems ok to not use the user allocator for this)
- PxU8* mem = reinterpret_cast<PxU8*>(allocateStackMemory(newStackSize));
-
- if (mem)
- {
- tImpl->stackMemory = mem;
-
- if(runnable && !tImpl->arg && ! tImpl->fn)
- tImpl->arg = runnable;
-
- const int priority = tImpl->nativeThread._basePriority;
- PX_ASSERT((priority <= nn::os::LowestThreadPriority) && (priority >= nn::os::HighestThreadPriority));
-
- nn::Result result = nn::os::CreateThread(&tImpl->nativeThread, ThreadStart, this, mem, newStackSize, priority);
-
- if (result.IsSuccess())
- {
- if (tImpl->threadAffinity != _ThreadImpl::sInvalidAffinityMask)
- nn::os::SetThreadCoreMask(&tImpl->nativeThread, nn::os::IdealCoreDontCare, static_cast<nn::Bit64>(tImpl->threadAffinity));
-
- if (tImpl->nativeThread._namePointer)
- nn::os::SetThreadNamePointer(&tImpl->nativeThread, tImpl->nativeThread._namePointer);
-
- nn::os::StartThread(&tImpl->nativeThread);
- }
- else
- {
- freeStackMemory(reinterpret_cast<void*>(mem));
- tImpl->stackMemory = NULL;
- PX_ALWAYS_ASSERT();
- }
- }
-}
-
-void ThreadImpl::signalQuit()
-{
- getThread(this)->quitNow.fetch_add(1);
-}
-
-bool ThreadImpl::waitForQuit()
-{
- _ThreadImpl* tImpl = getThread(this);
-
- if(tImpl->state == _ThreadImpl::NotStarted)
- return false;
-
- nn::os::WaitThread(&tImpl->nativeThread);
-
- return true;
-}
-
-bool ThreadImpl::quitIsSignalled()
-{
- _ThreadImpl* tImpl = getThread(this);
- int expected = 0;
- return !tImpl->quitNow.compare_exchange_strong(expected, 0);
-}
-
-void ThreadImpl::quit()
-{
- getThread(this)->state = _ThreadImpl::Stopped;
-
- // nothing to call. The thread will return and that will trigger all waiting threads to be informed.
-}
-
-void ThreadImpl::kill()
-{
- PX_ASSERT(!"kill() is not implemented for this platform");
-
- // nn::os::DestroyThread() waits for the thread to exit, which does seem the wrong behavior for kill()
-}
-
-void ThreadImpl::sleep(PxU32 ms)
-{
- nn::os::SleepThread(nn::TimeSpan::FromMilliSeconds(ms));
-}
-
-void ThreadImpl::yield()
-{
- nn::os::YieldThread();
-}
-
-PxU32 ThreadImpl::setAffinityMask(PxU32 mask)
-{
- PX_ASSERT((mask & (~nn::os::GetThreadAvailableCoreMask())) == 0);
-
- _ThreadImpl* tImpl = getThread(this);
-
- if (tImpl->state == _ThreadImpl::NotStarted)
- {
- const int previousMask = tImpl->threadAffinity;
- tImpl->threadAffinity = static_cast<int>(mask);
-
- if (previousMask == _ThreadImpl::sInvalidAffinityMask)
- return 0;
- else
- return static_cast<PxU32>(previousMask);
- }
- else
- {
- nn::Bit64 affMask;
- nn::os::GetThreadCoreMask(NULL, &affMask, &tImpl->nativeThread);
-
- nn::os::SetThreadCoreMask(&tImpl->nativeThread, nn::os::IdealCoreDontCare, static_cast<nn::Bit64>(mask));
-
- return static_cast<PxU32>(affMask);
- }
-}
-
-void ThreadImpl::setName(const char* name)
-{
- // important: The memory has to be allocated and managed by the caller
-
- _ThreadImpl* tImpl = getThread(this);
- if(tImpl->state == _ThreadImpl::Started)
- nn::os::SetThreadNamePointer(&tImpl->nativeThread, name);
- else
- tImpl->nativeThread._namePointer = name;
-}
-
-void ThreadImpl::setPriority(ThreadPriority::Enum prio)
-{
- _ThreadImpl* tImpl = getThread(this);
-
- int convertedPriority = ThreadPriority::eNORMAL; // compiler complains if no default is set (even though all values are covered in the switch statement)
- switch(prio)
- {
- case ThreadPriority::eHIGH:
- convertedPriority = nn::os::HighestThreadPriority;
- break;
- case ThreadPriority::eABOVE_NORMAL:
- convertedPriority = (nn::os::HighestThreadPriority + nn::os::DefaultThreadPriority) / 2;
- break;
- case ThreadPriority::eNORMAL:
- convertedPriority = nn::os::DefaultThreadPriority;
- break;
- case ThreadPriority::eBELOW_NORMAL:
- convertedPriority = (nn::os::LowestThreadPriority + nn::os::DefaultThreadPriority) / 2;
- break;
- case ThreadPriority::eLOW:
- convertedPriority = nn::os::LowestThreadPriority;
- break;
- case ThreadPriority::eFORCE_DWORD:
- PX_ALWAYS_ASSERT();
- convertedPriority = nn::os::DefaultThreadPriority;
- break;
- }
-
- if (tImpl->state == _ThreadImpl::Started)
- nn::os::ChangeThreadPriority(&tImpl->nativeThread, convertedPriority);
- else
- tImpl->nativeThread._basePriority = convertedPriority;
-}
-
-ThreadPriority::Enum ThreadImpl::getPriority(Id tID)
-{
- const nn::os::ThreadType* thread = reinterpret_cast<const nn::os::ThreadType*>(tID);
- int prio = nn::os::GetThreadCurrentPriority(thread);
- ThreadPriority::Enum convertedPriority;
-
- switch(prio)
- {
- case nn::os::HighestThreadPriority:
- convertedPriority = ThreadPriority::eHIGH;
- break;
- case ((nn::os::HighestThreadPriority + nn::os::DefaultThreadPriority) / 2):
- convertedPriority = ThreadPriority::eABOVE_NORMAL;
- break;
- case nn::os::DefaultThreadPriority:
- convertedPriority = ThreadPriority::eNORMAL;
- break;
- case ((nn::os::LowestThreadPriority + nn::os::DefaultThreadPriority) / 2):
- convertedPriority = ThreadPriority::eBELOW_NORMAL;
- break;
- case nn::os::LowestThreadPriority:
- convertedPriority = ThreadPriority::eLOW;
- break;
- default:
- PX_ALWAYS_ASSERT();
- convertedPriority = ThreadPriority::eNORMAL;
- break;
- }
-
- return convertedPriority;
-}
-
-PxU32 ThreadImpl::getNbPhysicalCores()
-{
- nn::Bit64 mask = nn::os::GetThreadAvailableCoreMask();
- PX_ASSERT(mask > 0);
-
- const uint32_t count = bitCount(static_cast<const uint32_t>(mask));
- return count;
-}
-
-
-PxU32 TlsAlloc()
-{
- // note: only nn::os::TlsSlotCountMax Tls slots are available (which used to be 16)
-
- nn::os::TlsSlot tlsSlot;
- nn::Result result = nn::os::AllocateTlsSlot(&tlsSlot, NULL);
-
- if (result.IsSuccess())
- return static_cast<PxU32>(tlsSlot._innerValue);
- else
- {
- PX_ALWAYS_ASSERT();
- return 0xffffffff;
- }
-}
-
-void TlsFree(PxU32 index)
-{
- nn::os::TlsSlot tlsSlot;
- tlsSlot._innerValue = static_cast<uint32_t>(index);
-
- nn::os::FreeTlsSlot(tlsSlot);
-}
-
-void* TlsGet(PxU32 index)
-{
- nn::os::TlsSlot tlsSlot;
- tlsSlot._innerValue = static_cast<uint32_t>(index);
-
- return reinterpret_cast<void*>(nn::os::GetTlsValue(tlsSlot));
-}
-
-PxU32 TlsSet(PxU32 index, void* value)
-{
- nn::os::TlsSlot tlsSlot;
- tlsSlot._innerValue = static_cast<uint32_t>(index);
-
- nn::os::SetTlsValue(tlsSlot, reinterpret_cast<uintptr_t>(value));
-
- return 1;
-}
-
-
-} // namespace shdfnd
-} // namespace physx
diff --git a/PxShared/src/foundation/src/nx/PsNXTime.cpp b/PxShared/src/foundation/src/nx/PsNXTime.cpp
deleted file mode 100644
index 977e6ce..0000000
--- a/PxShared/src/foundation/src/nx/PsNXTime.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
- *
- * NVIDIA CORPORATION and its licensors retain all intellectual property
- * and proprietary rights in and to this software, related documentation
- * and any modifications thereto. Any use, reproduction, disclosure or
- * distribution of this software and related documentation without an express
- * license agreement from NVIDIA CORPORATION is strictly prohibited.
- */
-// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
-// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
-
-
-#include "PsTime.h"
-#include "nn/os/os_Tick.h"
-
-
-namespace physx
-{
-namespace shdfnd
-{
-
-namespace
-{
- static double sRecipFrequency = 1.0 / nn::os::GetSystemTickFrequency();
-}
-
-static const CounterFrequencyToTensOfNanos gCounterFreq = Time::getCounterFrequency();
-
-const CounterFrequencyToTensOfNanos& Time::getBootCounterFrequency()
-{
- return gCounterFreq;
-}
-
-CounterFrequencyToTensOfNanos Time::getCounterFrequency()
-{
- return CounterFrequencyToTensOfNanos( Time::sNumTensOfNanoSecondsInASecond, static_cast<PxU64>(nn::os::GetSystemTickFrequency()));
-}
-
-
-PxU64 Time::getCurrentCounterValue()
-{
- nn::os::Tick tick = nn::os::GetSystemTick();
- return static_cast<PxU64>(tick.GetInt64Value());
-}
-
-Time::Time(): mTickCount(0)
-{
- getElapsedSeconds();
-}
-
-Time::Second Time::getElapsedSeconds()
-{
- PxI64 lastTickCount = mTickCount;
- mTickCount = static_cast<PxI64>(nn::os::GetSystemTick().GetInt64Value());
- return (mTickCount - lastTickCount) * sRecipFrequency;
-}
-
-Time::Second Time::peekElapsedSeconds()
-{
- return (static_cast<PxI64>(nn::os::GetSystemTick().GetInt64Value()) - mTickCount) * sRecipFrequency;
-}
-
-Time::Second Time::getLastTime() const
-{
- return mTickCount * sRecipFrequency;
-}
-
-} // namespace shdfnd
-} // namespace physx