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