File indexing completed on 2026-09-25 09:21:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _SelectMgr_BVHThreadPool_HeaderFile
0015 #define _SelectMgr_BVHThreadPool_HeaderFile
0016
0017 #include <Standard_Transient.hxx>
0018 #include <OSD_Thread.hxx>
0019 #include <Select3D_SensitiveEntity.hxx>
0020 #include <Standard_Condition.hxx>
0021 #include <Message_Messenger.hxx>
0022
0023 #include <mutex>
0024
0025
0026
0027 class SelectMgr_BVHThreadPool : public Standard_Transient
0028 {
0029 DEFINE_STANDARD_RTTIEXT(SelectMgr_BVHThreadPool, Standard_Transient)
0030 public:
0031
0032 Standard_EXPORT SelectMgr_BVHThreadPool(int theNbThreads);
0033
0034
0035 Standard_EXPORT ~SelectMgr_BVHThreadPool() override;
0036
0037 public:
0038
0039 class BVHThread : public OSD_Thread
0040 {
0041 friend class SelectMgr_BVHThreadPool;
0042
0043 public:
0044 BVHThread()
0045 : myPool(nullptr),
0046
0047 myToCatchFpe(false)
0048 {
0049 }
0050
0051 BVHThread(const BVHThread& theOther)
0052 : OSD_Thread(theOther),
0053 myPool(theOther.myPool),
0054
0055 myToCatchFpe(theOther.myToCatchFpe)
0056 {
0057 }
0058
0059
0060 std::mutex& BVHMutex() { return myMutex; }
0061
0062
0063 BVHThread& operator=(const BVHThread& theCopy)
0064 {
0065 Assign(theCopy);
0066 return *this;
0067 }
0068
0069
0070 void Assign(const BVHThread& theCopy)
0071 {
0072 OSD_Thread::Assign(theCopy);
0073 myPool = theCopy.myPool;
0074 myToCatchFpe = theCopy.myToCatchFpe;
0075 }
0076
0077 private:
0078
0079 void performThread();
0080
0081
0082 static void* runThread(void* theTask);
0083
0084 private:
0085 SelectMgr_BVHThreadPool* myPool;
0086 std::mutex myMutex;
0087 bool myToCatchFpe;
0088 };
0089
0090 public:
0091
0092 Standard_EXPORT void AddEntity(const occ::handle<Select3D_SensitiveEntity>& theEntity);
0093
0094
0095 Standard_EXPORT void StopThreads();
0096
0097
0098 Standard_EXPORT void WaitThreads();
0099
0100
0101 NCollection_Array1<BVHThread>& Threads() { return myBVHThreads; }
0102
0103 public:
0104
0105 class Sentry
0106 {
0107 public:
0108
0109 Sentry(const occ::handle<SelectMgr_BVHThreadPool>& thePool)
0110 : myPool(thePool)
0111 {
0112 Lock();
0113 }
0114
0115
0116 ~Sentry() { Unlock(); }
0117
0118
0119 void Lock()
0120 {
0121 if (!myPool.IsNull())
0122 {
0123 for (int i = myPool->Threads().Lower(); i <= myPool->Threads().Upper(); ++i)
0124 {
0125 myPool->Threads().ChangeValue(i).BVHMutex().lock();
0126 }
0127 }
0128 }
0129
0130
0131 void Unlock()
0132 {
0133 if (!myPool.IsNull())
0134 {
0135 for (int i = myPool->Threads().Lower(); i <= myPool->Threads().Upper(); ++i)
0136 {
0137 myPool->Threads().ChangeValue(i).BVHMutex().unlock();
0138 }
0139 }
0140 }
0141
0142
0143 Sentry(const Sentry&);
0144
0145 Sentry& operator=(const Sentry&);
0146
0147 private:
0148 occ::handle<SelectMgr_BVHThreadPool> myPool;
0149 };
0150
0151 protected:
0152
0153 NCollection_List<occ::handle<Select3D_SensitiveEntity>> myBVHToBuildList;
0154 NCollection_Array1<BVHThread> myBVHThreads;
0155 bool myToStopBVHThread;
0156 std::mutex myBVHListMutex;
0157 Standard_Condition myWakeEvent;
0158 Standard_Condition myIdleEvent;
0159 bool myIsStarted;
0160
0161 };
0162
0163 #endif