AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Thread.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#ifdef _MSC_VER
20# pragma warning(push)
21# pragma warning( disable: 4275 ) // warning C4275: non dll-interface class
22# pragma warning(disable: 4251) // warning C4251: class X needs to have dll-interface to be used by clients of class Y
23#endif
24
25
26#include <agx/agx.h>
27#include <agx/Vector.h>
28#include <agx/HashTable.h>
29#include <agx/Timer.h>
30#include <agx/Task.h>
32
35
36#include <agx/AtomicValue.h>
37#include <agx/Job.h>
38#include <agx/Uuid.h>
39#include <agx/Notify.h>
40
41#include <queue>
42#include <thread>
43
44// Set to 1 to enable thread timeline reporting of internal steps
45#define ENABLE_VERBOSE_THREAD_TIMELINE 0
46
47
48#define AGX_MAX_NUM_THREADS 1024
49
50
51extern "C"
52{
54}
55
56namespace agxData
57{
58 class EntityStorage;
59 class EntityModel;
60}
61
62
63
64
65
66namespace agx
67{
68 class TiXmlElement;
69 class Task;
70
71
72 // AGX_DECLARE_POINTER_TYPES(Thread);
73 // AGX_DECLARE_VECTOR_TYPES(Thread);
74
75
76
83 {
84 public:
85
90 THREAD_NEW = 0, // When a BasicThread is created
91 THREAD_RUNNING = 1, // start has been called
92 THREAD_DETACHED = 2, // detach has been called
93 THREAD_DONE = 3, // After run() is done executing
94 THREAD_JOINED = 4, // After join() has been called
95 THREAD_CANCELLED = 5 // After cancel but before join
96 };
97
102
103 BasicThread( const BasicThread& other ) = delete;
104
105 BasicThread& operator=(const BasicThread& rhs ) = delete;
106
110 virtual ~BasicThread() = default;
111
116 virtual void run() { }
117
125 bool start();
126
134 void cancel();
135
139 bool join();
140
141
145 void detach();
146
150 inline bool joinable();
151
155 inline unsigned int getThreadState();
156
157
158
159
174
175
179 static std::thread::native_handle_type getCurrentThreadHandle();
180
181
182 private:
183 void launchThread();
184
185 protected:
186 std::thread m_handle;
187 std::atomic< unsigned int> m_state;
188 private:
189 std::mutex m_handleMutex;
190 };
191
192
193
199 {
200 public:
201
202
203 // The types used when communicating with the thread local storage facilities.
204 // The key type is an integer type and the data type is a pointer type.
205 #ifdef _WIN32
206 typedef unsigned long ThreadStorageKey; // Should be DWORD
207 typedef void* ThreadStorageData; // Should be LPVOID
208 #else
209 typedef pthread_key_t ThreadStorageKey;
210 typedef void* ThreadStorageData;
211 #endif
212
213 typedef std::mt19937 RandomGenerator;
214
218 bool start();
219
223 void stop();
224
231 Index getId() const;
232
244
248 static Thread *getCurrentThread();
249
255 static std::string getCurrentThreadDescription();
256
260 static Thread *getThread(size_t id);
261
265 static Thread *getMainThread();
266
272
278
284
290 RandomGenerator& getRandomGenerator();
291
292
296 static bool isMainThread();
297
298
302 static void shutdown();
303
304 static bool isShuttingDown();
305
306
308 static void setEnableJobTimeline(bool flag);
309 static bool getEnableJobTimeline();
310
320 UInt64 startTick, UInt64 endTick,
321 const char* description,
322 const char* extraDataTitle = nullptr,
323 agx::Real64 extraData = 0.0);
324
328 Real getOverheadTime() const;
329
334
335 // Allocations
336 // void *allocateBytes(size_t numBytes);
337 // void *deallocateBytes(void *ptr);
338
344
345
346
347
348
349
350
351
352 // Main thread is normally allocated automatically, special usage before main is entered
353 static void initThreadSystem();
354
355 // Dump profiling logs, called by Simulation
356 static void exportAllTimelines();
357 static void resetStartTick();
358 static void flushTimelineLogs();
359
360
361 /*
362 * Methods used for manipulating the thread local storage.
363 */
364
373
374 static bool immediateLogging;
375 static int log(const char *format, ...);
376 static void flushLogs();
378
380
381
382 static void addTask(Task *task);
383
384 // Threads that aren't "real" AGX threads, i.e., registered threads, get
385 // a pseudo-ID in this table. These IDs are unrelated from the IDs of the
386 // "real" AGX threads.
389
390 protected:
392 Thread(const Thread&) = delete;
393 virtual ~Thread();
394
395 private:
396
397
398
399 friend void AGXCORE_EXPORT setNumThreads(size_t numThreads);
401
402 class MainThreadSingleton;
403 static Thread *initMainThread();
404
405 static void performNumThreadsChange();
406 void startWaitTimer();
407 void stopWaitTimer();
408
409 virtual void run();
410
411 void freeDefaultStorages();
412 void spawn(Job *job);
413 void sortInsertJob(Job *job);
414
415 void activate();
416 void completeFrame(Task *task);
417
418 bool isActive() const;
419
420
421 template <bool THREAD_TIMELINE_STATISTICS>
422 void doWork();
423
424 void doWork();
425 void blockingDoWork();
426
427 void stealWork();
428 void wakeupThreads();
429 void pushTargetJob(Thread *target, Job *job, bool activateTarget = true);
430 static void taskCompleted(Task *task);
431
432 void initialize();
433 void sleep();
434
435 Job *getExecutionJob();
436
437 Index getRandomOtherThreadId(Index excludeIndex = InvalidIndex);
438
439 friend class Block;
440
441 friend class Job;
442 friend class Notify;
443
444 private:
445 char *m_currentPathString;
446
447 Notify::ThreadData *getNotifyData();
449
450 friend class Task;
451
452 // Simple linear congruential generator
453 class FastRandom
454 {
455 public:
456 FastRandom(UInt32 seed);
457 FastRandom();
458
459 UInt32 operator() ();
460
461 private:
462 static const UInt32 mod = ((1ULL << 32) - 5);
463 static const UInt32 mul = 69070U;
464
465 void init(UInt32 seed);
466
467 private:
468 UInt32 m_state;
469 };
470
471 FastRandom m_fastRandom;
472
473 struct Frame
474 {
475 inline Frame(Task *t = nullptr) : task(t), done(false) {}
476 inline Frame& operator=(const Frame& other) {task = other.task; done = other.done.load(); return *this;}
477 Task *task;
478 std::atomic<bool> done;
479 };
480
481 #define AGX_THREAD_FRAME_STACK_MAX_DEPTH 64
482 Frame m_frames[AGX_THREAD_FRAME_STACK_MAX_DEPTH];
483 size_t m_numFrames;
484 size_t m_activationDepth;
485 std::atomic<Int32> m_activationCount;
486
487 Thread *m_listNodeNext;
488
489 agx::SpinMutex m_jobMutex;
490 JobPtrVector m_localJobs;
491
492 struct JobCompare
493 {
494 AGX_FORCE_INLINE bool operator() (const Job *lhs, const Job *rhs) const
495 {
496 return lhs->getCostEstimate() < rhs->getCostEstimate();
497 }
498 };
499
500 typedef std::priority_queue<Job *, agx::Vector<Job *>, JobCompare> JobQueue;
501 JobQueue m_sharedJobs;
502 JobQueue m_tmpJobs;
503
504
505 Timer m_wakeupTimer;
506 Timer m_sleepTimer;
507 size_t m_numSleep;
508
509 // static THREAD_LOCAL_STORAGE Thread *s_currentThread;
510 bool m_isSleeping;
511 Block m_startBlock;
512 Block m_runBlock;
513 Block m_waitBlock;
514 agx::SpinMutex m_mutex;
515 std::atomic<bool> m_running;
516
517 agx::SpinMutex m_pushMutex;
518 JobPtrVector m_pushedJobs;
519 std::atomic<Int32> m_pushCounter;
520
521
522 Index m_id;
523 Timer m_timer;
524 Timer m_overheadTimer;
525 Real m_waitTime;
526 Real m_totJobProcessTime;
527 Real m_totJobOverheadTime;
528 int m_totJobElements;
529 Real m_startupTimestamp;
530 Real m_shutdownTimestamp;
531
532
533 // std::ostringstream m_log;
534 static Thread *s_threads[AGX_MAX_NUM_THREADS];
535 static Thread *s_mainThread;
536 static Thread *s_mainWorkThread;
537 static Thread *s_ioThread;
538 static Callback1<Task *> s_taskCompletionCallback;
539
540 agx::UuidGenerator m_uuidGenerator;
541 std::random_device m_randomDevice;
542 std::mt19937 m_mersienneTwister;
543 // Vector<AbstractMemoryPool *> m_pools;
544
545 #if 0
546 template <typename T>
547 T *allocateLocalVector(LocalVector<T> *buffer);
548
549 template <typename T>
550 void deallocateLocalVector(LocalVector<T> *buffer);
551 #endif
552
553 private:
554
556 void registerContainerAllocation(Container *container);
557 void unregisterContainerAllocation(Container *container);
558 void *allocateScratchPadBuffer(size_t numBytes);
559 void deallocateScratchPadBuffer(void *buffer, size_t numBytes);
560
561 struct ScratchPadArea
562 {
563 ScratchPadArea() : buffer(nullptr), end(nullptr), head(nullptr), m_allocator("ScratchPad")
564 {}
565
566 ~ScratchPadArea() { m_allocator.deallocateBytes(buffer); }
567
568 char *buffer;
569 char *end;
570 char *head;
571 ByteAllocator m_allocator;
572 VectorPOD<Container *> m_activeAllocations;
573 };
574
575 ScratchPadArea m_scratchPad;
576
577
578 static bool s_enableJobTimeline;
579 agxData::EntityStorageRef m_timelineEntries;
580
581 static std::exception_ptr s_unhandledException;
582
583
584 struct LocalTimelineEntry
585 {
586 LocalTimelineEntry()
587 : jobType(UNKNOWN)
588 , startTick(0)
589 , endTick(0)
590 , poolSize(0)
591 , costEstimate(0)
592 , message(nullptr)
593 , job(nullptr)
594 , extraDataTitle(nullptr)
595 , extraData(0.0)
596 {}
597
598 enum JobType { PRE, DISPATCH, POST, UNKNOWN };
599
600 agx::TaskRef task;
601 JobType jobType;
602 agx::UInt64 startTick;
603 agx::UInt64 endTick;
604 agx::UInt32 poolSize;
605 agx::UInt32 costEstimate;
606 const char* message;
607 void* job;
608
609 const char* extraDataTitle;
610 agx::Real64 extraData;
611 };
612
613 Vector<LocalTimelineEntry> m_localTimelineEntries;
614 agx::SpinMutex m_timelineMutex;
615 AGX_DECLARE_POINTER_TYPES(TimelineExportKernel);
616
617
618 void exportTimelineEntries();
619 void reportTimelineJob(Job *job);
620 void pushTimelineEntry(const LocalTimelineEntry& entry);
621
623 class LogChunk : public Referenced
624 {
625 public:
626 LogChunk(size_t numBytes);
627 char* buffer;
628 char* head;
629 char* end;
630 LogChunkRef next;
631 size_t numAvailable();
632
633 protected:
634 virtual ~LogChunk();
635 };
636
637 struct LogEntry
638 {
639 LogEntry();
640 LogEntry(agx::UInt64 timestamp_, const char* message_);
641 agx::UInt64 timestamp;
642 const char* message;
643 };
644
645 int logImplementation(const char* format, va_list ap);
646 static int cmpLogEntry(const LogEntry& entry1, const LogEntry& entry2);
647
648 LogChunkRef m_logChunk;
649 VectorPOD<LogEntry> m_logEntries;
650
651 typedef HashTable<agxData::EntityModel*, ref_ptr<Referenced>> DefaultStorageTable;
652 DefaultStorageTable m_defaultStorageTable;
653
654
657 static ThreadStorageKey s_threadObject_key;
658 };
659
661
662
663
664
665
666
667
668 /* Implementation */
670
672 {
673 return m_handle.joinable();
674 }
675
676
677
678 inline unsigned int BasicThread::getThreadState()
679 {
680 return m_state.load();
681 }
682
683
684
686 {
687 return m_id;
688 }
689
691 {
692 agxAssert(s_threads[id]);
693 return s_threads[id];
694 }
695
697 {
698 // The AGX threads store a pointer to their thread object in the thread local storage
699 // pointed to by 's_threadObject_key'. If the currently executing thread isn't a AgX
700 // thread, then nothing will have been written to 's_threadObject_key' and 0 is returned.
701 return static_cast<Thread*>( Thread::readPerThreadStorage(s_threadObject_key) );
702 }
703
705 {
706 agxAssert(s_mainThread);
707 return s_mainThread;
708 }
709
710 #if 0
711 AGX_FORCE_INLINE Thread *Thread::getMainWorkThread()
712 {
713 return s_mainWorkThread;
714 }
715 #endif
716
718 AGX_FORCE_INLINE bool Thread::isActive() const { return m_activationCount.load() > 0; }
719
720 AGX_FORCE_INLINE void Thread::startWaitTimer()
721 {
722 m_timer.reset(true);
723 }
724
725 AGX_FORCE_INLINE void Thread::stopWaitTimer()
726 {
727 m_timer.stop();
728 m_waitTime += (Real)m_timer.getTime();
729 }
730
732 {
733 return m_mersienneTwister;
734 }
735
736 AGX_FORCE_INLINE Real Thread::getOverheadTime() const { return Real(m_overheadTimer.getTime()); }
737
738
739 inline int Thread::log(const char *format, ...)
740 {
741 va_list arguments;
742 va_start(arguments, format);
743 int result = Thread::getCurrentThread()->logImplementation(format, arguments);
744 va_end(arguments);
745 return result;
746 }
747
748
749 #if 0
750 AGX_FORCE_INLINE void *Thread::allocateBytes(size_t numBytes)
751 {
752 return m_byteAllocator.allocate(numBytes);
753 }
754
755 AGX_FORCE_INLINE void *Thread::deallocateBytes(void *ptr)
756 {
757 m_byteAllocator.deallocateBytes(ptr);
758 }
759
760 template <typename T>
761 AGX_FORCE_INLINE T *Thread::allocate()
762 {
763 return this->getPool<T>()->allocate();
764 }
765
766 template <typename T>
767 AGX_FORCE_INLINE void Thread::deallocate(T *ptr)
768 {
769 this->getPool<T>()->deallocate(ptr);
770 }
771
772
773 template <typename T>
774 AGX_FORCE_INLINE T *Thread::create()
775 {
776 return this->getPool<T>()->create();
777 }
778
779 template <typename T>
780 AGX_FORCE_INLINE void Thread::destroy(T *ptr)
781 {
782 this->getPool<T>()->destroy(ptr);
783 }
784
785 template <typename T>
786 AGX_FORCE_INLINE MemoryPool<T> *Thread::getPool()
787 {
788 uint32_t id = agxData::getType<T>()->getId();
789 if (id >= m_pools.size())
790 m_pools.resize(id+1, 0);
791
792 if (!m_pools[id])
793 m_pools[id] = new MemoryPool<T>;
794
795 return static_cast<MemoryPool<T> *>(m_pools[id]);
796 }
797
798 void setCurrentConstructionObject(void *ptr);
799 void *getCurrentConstructionObject();
800 #endif
801
802
803
804
805
806 AGX_FORCE_INLINE void *Thread::allocateScratchPadBuffer(size_t numBytes)
807 {
808 /* Check if scratch pad is too small, which requires reallocation and updates to all existing container allocations */
809 if (m_scratchPad.head + numBytes > m_scratchPad.end)
810 {
811 size_t currentSize = m_scratchPad.end - m_scratchPad.buffer;
812 const Real growFactor = 1.5;
813 size_t newSize = (size_t)( Real(currentSize + numBytes) * growFactor );
814 // printf("Reallocating scratch pad for thread %d from %u to %u KB\n", this->getId(), (unsigned)(currentSize/1024), (unsigned)(newSize/1024));
815
816 char *newBuffer = (char *)m_scratchPad.m_allocator.allocateBytes(newSize, 64);
817 agxAssertN(newBuffer, "Thread %d could not allocate %u bytes for job scratch pad!", this->getId(), (unsigned)newSize);
818 if (!newBuffer)
819 return nullptr;
820
821 /* Copy active allocations */
822 size_t numUsed = m_scratchPad.head - m_scratchPad.buffer;
823
824 if ( numUsed > 0 )
825 memcpy(newBuffer, m_scratchPad.buffer, numUsed);
826
827 m_scratchPad.m_allocator.deallocateBytes(m_scratchPad.buffer);
828
829 /* Update buffer pointers for active allocations */
830 for (size_t i = 0; i < m_scratchPad.m_activeAllocations.size(); ++i)
831 {
832 Container *container = m_scratchPad.m_activeAllocations[i];
833
834 if (container->m_buffer)
835 {
836 ptrdiff_t offset = (char *)container->m_buffer - (char *)m_scratchPad.buffer;
837 container->m_buffer = newBuffer + offset;
838 }
839 }
840
841 m_scratchPad.buffer = newBuffer;
842 m_scratchPad.end = m_scratchPad.buffer + newSize;
843 m_scratchPad.head = m_scratchPad.buffer + numUsed;
844 }
845
846 void *mem = m_scratchPad.head;
847 m_scratchPad.head += numBytes;
848
849 return mem;
850 }
851
852 AGX_FORCE_INLINE void Thread::deallocateScratchPadBuffer(void *buffer, size_t numBytes)
853 {
854 agxAssert(!buffer || (buffer >= m_scratchPad.buffer && buffer < m_scratchPad.end));
855
856 if ((char *)buffer + numBytes == m_scratchPad.head)
857 m_scratchPad.head = (char *)buffer;
858 }
859
860 AGX_FORCE_INLINE void Thread::registerContainerAllocation(Container *container)
861 {
862 m_scratchPad.m_activeAllocations.push_back(container);
863 }
864
865 #ifdef AGX_DEBUG
866 AGX_FORCE_INLINE void Thread::unregisterContainerAllocation(Container *container)
867 #else
868 AGX_FORCE_INLINE void Thread::unregisterContainerAllocation(Container * /* container */)
869 #endif
870 {
871 agxAssert1(!m_scratchPad.m_activeAllocations.empty() && container == m_scratchPad.m_activeAllocations.back(), "LIFO order required!");
872 m_scratchPad.m_activeAllocations.pop_back();
873
874 /* Reset scratch pad, removing any holes from reallocations */
875 if (m_scratchPad.m_activeAllocations.empty())
876 m_scratchPad.head = m_scratchPad.buffer;
877 }
878
879}
880
881
882#if ENABLE_VERBOSE_THREAD_TIMELINE
883 #define AGX_BEGIN_TIMELINE_REPORT(variable) \
884 auto variable ## _begin_time = agx::Timer::getCurrentTick()
885
886 #define AGX_END_TIMELINE_REPORT(variable, title) \
887 auto variable ## _end_time = agx::Timer::getCurrentTick(); \
888 agx::Thread::getCurrentThread()->reportSystemJob( variable ## _begin_time , variable ## _end_time, title);
889
890 #define AGX_END_TIMELINE_REPORT_DATA(variable, title, title2, data) \
891 auto variable ## _end_time = agx::Timer::getCurrentTick(); \
892 agx::Thread::getCurrentThread()->reportSystemJob( variable ## _begin_time , variable ## _end_time, title, title2, data)
893#else
894 #define AGX_BEGIN_TIMELINE_REPORT(variable)
895 #define AGX_END_TIMELINE_REPORT(variable, title)
896 #define AGX_END_TIMELINE_REPORT_DATA(variable, title, title2, data)
897#endif
898
899
900#ifdef _MSC_VER
901# pragma warning(pop)
902#endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGX_THREAD_FRAME_STACK_MAX_DEPTH
Definition Thread.h:481
#define AGX_MAX_NUM_THREADS
Definition Thread.h:48
void agxFlushThreadLogs()
#define AGXCORE_EXPORT
#define AGXPHYSICS_EXPORT
An attribute container.
An abstract description of a data entity stored using SOA (structure of arrays) pattern in a EntitySt...
Definition EntityModel.h:64
Data storage for a collection of entity instances of a specified EntityModel.
Only use as member allocated variable.
Definition Value.h:285
Basic wrapper class aroud std::thread.
Definition Thread.h:83
BasicThread & operator=(const BasicThread &rhs)=delete
BasicThread()
Default constructor.
bool setThreadAffinity(agx::UInt64 cpumask)
Thread Affinity can be used to influence on which logical cores threads are scheduled and allowed to ...
BasicThread(const BasicThread &other)=delete
void detach()
Detaches the thread to the background.
void cancel()
Threads should normally not need to be killed.
virtual ~BasicThread()=default
Destructor.
std::atomic< unsigned int > m_state
Definition Thread.h:187
bool join()
Joins the thread.
virtual void run()
This method is invoked by start.
Definition Thread.h:116
std::thread m_handle
Definition Thread.h:186
bool joinable()
True if thread is joinable.
Definition Thread.h:671
ThreadState
States for the thread.
Definition Thread.h:89
unsigned int getThreadState()
Returns the current thread state.
Definition Thread.h:678
bool start()
Launches the thread.
static std::thread::native_handle_type getCurrentThreadHandle()
Return a native_handle for the current executing thread.
Block synchronization primitive.
The Container is the base class for several of the container classes proided by AGX,...
Definition Container.h:35
The object defining a frame of reference and providing transformations operations.
Definition agx/Frame.h:68
An abstract job/workblock representation, which allows work threads to execute arbitrary tasks.
Definition Job.h:63
Inheritance with partial specialization due to bug with ref_ptr containers.
Class for handling logging of messages.
Definition Notify.h:64
agx::UInt32 getId() const
Definition Object.h:369
Spin-lock mutex.
Definition SpinMutex.h:47
A representation of a generic task.
Definition Task.h:58
agx::Thread is a representation of an OS specific implementation of a computational thread.
Definition Thread.h:199
static void writePerThreadStorage(ThreadStorageKey key, ThreadStorageData data)
Write to the thread-local location owned by the currently executing thread.
HashTable< Thread *, Index > ThreadIdTable
Definition Thread.h:387
friend void AGXPHYSICS_EXPORT shutdown()
Shutdown of the AGX Dynamics API will be done when the number of shutdown matches the number of calls...
static void resetStartTick()
agx::Uuid generateUuid()
Generates a unique universal identifier.
void stop()
Stop the thread.
static void makeCurrentThreadMainThread()
Register current thread as main thread.
static int log(const char *format,...)
Definition Thread.h:739
static void freePerThreadStorage(ThreadStorageKey key)
Deallocate the storage location.
static void addTask(Task *task)
agxData::EntityStorage * getDefaultStorage(agxData::EntityModel *entity)
Thread(Index id)
static bool isMainThread()
Definition Thread.h:717
static Thread * getCurrentThread()
Definition Thread.h:696
void resetOverheadTime()
Reset the thread overhead time.
bool start()
Start the thread.
static void flushLogs()
void * ThreadStorageData
Definition Thread.h:210
Thread(const Thread &)=delete
static void initThreadSystem()
static void shutdown()
Shutdown the threading system.
void reportSystemJob(UInt64 startTick, UInt64 endTick, const char *description, const char *extraDataTitle=nullptr, agx::Real64 extraData=0.0)
Add an entry to the job duration log.
static std::string getCurrentThreadDescription()
static void setEnableJobTimeline(bool flag)
Enable or disable job timeline statistics.
static Thread * registerAsAgxThread()
Register the current thread as an AGX thread.
friend void AGXCORE_EXPORT setNumThreads(size_t numThreads)
Set the number of threads to use (including the main thread).
pthread_key_t ThreadStorageKey
Definition Thread.h:209
std::mt19937 RandomGenerator
Definition Thread.h:213
Index getIndex() const
Get an index suitable for use when storing per-thread data in e.g.
static ThreadStorageKey allocatePerThreadStorage()
Allocate a storage location that is unique for each thread.
agxData::EntityStorageRef popTimelineEntryStorage()
RandomGenerator & getRandomGenerator()
Return a reference to the mersienne twister used for generating random numbers.
Definition Thread.h:731
static bool immediateLogging
Definition Thread.h:374
virtual ~Thread()
static void flushTimelineLogs()
static bool isShuttingDown()
static Thread * getThread(size_t id)
Definition Thread.h:690
static Thread * getMainThread()
Definition Thread.h:704
static bool getEnableJobTimeline()
static ThreadStorageData readPerThreadStorage(ThreadStorageKey key)
Read the thread-local value for the currently executing thread associated with the given key.
static void unregisterAsAgxThread()
Remove agx attributes from current thread.
Index getId() const
Returns the thread's AGX thread ID, a value between 0 and N-1, for AGX's internal threads,...
Definition Thread.h:685
Real getOverheadTime() const
Definition Thread.h:736
static Thread::ThreadIdTable * getPromotedThreads()
static void exportAllTimelines()
Generator of UUID values based on V4 http://en.wikipedia.org/wiki/Universally_unique_identifier.
Definition Uuid.h:232
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition Uuid.h:42
Vector containing 'raw' data.
Definition agx/Vector.h:246
#define agxAssert1(expr, msg)
Definition debug.h:144
#define agxAssertN(expr, format,...)
Definition debug.h:145
#define agxAssert(expr)
Definition debug.h:143
#define AGX_FORCE_INLINE
Definition macros.h:58
Contains classes for low level data storage for AGX.
Definition Container.h:23
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
double Real64
Definition Real.h:45
uint32_t UInt32
Definition Integer.h:32
uint64_t UInt64
Definition Integer.h:33
agx::VectorPOD< Thread * > ThreadPtrVector
Definition Thread.h:660
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
AGXCORE_EXPORT Thread * getCurrentThread()
double Real
Definition Real.h:42
VectorPOD< class Job * > JobPtrVector
Definition Job.h:51
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.
UInt32 Index
Definition Integer.h:44