CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
ThreadsCounter.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24#ifndef _THREADS_COUNTER_H_
25#define _THREADS_COUNTER_H_
26
27#include "TD_PackPush.h"
28#include "OdMutex.h"
29
38{
39public:
40 OdMutexPtr(): m_ptr(0){}
42 OdMutex* get() { if(!m_ptr) create(); return m_ptr; }
43 void clear();
44private:
45 void create();
46
47private:
48 static OdMutex s_mt;
49 OdMutex* m_ptr;
50};
51
65{
66public:
69 OdMutexPtrAutoLock(OdMutex* mutex) : m_mutex(mutex), m_bEnable(false)
70 {
71 lock();
72 }
73
75 {
76 unlock();
77 }
78
79 void lock() { set(true); }
80 void unlock() { set(false); }
81
82protected:
83 OdMutexPtrAutoLock(): m_mutex(NULL), m_bEnable(false){}
84 void set(bool bEnable)
85 {
86 if(m_mutex && (m_bEnable != bEnable))
87 {
88 m_bEnable = bEnable;
89 if(bEnable)
90 m_mutex->lock();
91 else
92 m_mutex->unlock();
93 }
94 }
95protected:
97private:
98 bool m_bEnable;
99};
100
108{
109 public:
111
118 //FELIX_CHANGE_BEGIN [DESKTOP-240896] Workaround for pure virtual call
119 /*
120 virtual void addRef() = 0;
121 */
122 virtual void addRef() {};
123 //FELIX_CHANGE_END
124
131 //FELIX_CHANGE_BEGIN [DESKTOP-240896] Workaround for pure virtual call
132 /*
133 virtual void release() = 0;
134 */
135 virtual void release() {};
136 //FELIX_CHANGE_END
137
144 virtual void increase(unsigned /*nThreads*/, const unsigned* /*aThreads*/, unsigned /*nThreadAttributes*/) { }
151 virtual void decrease(unsigned /*nThreads*/, const unsigned* /*aThreads*/, unsigned /*nThreadAttributes*/) { }
152
158 virtual void startThread(unsigned /*nThreadId*/, unsigned /*nThreadAttributes*/) { }
164 virtual void stopThread(unsigned /*nThreadId*/, unsigned /*nThreadAttributes*/) { }
165 protected:
167};
168
169// Function for execute in the main thread
170typedef void (*MainThreadFunc)(void*);
171// Function for initiate execution in the main thread by external process
173
175
183{
184public:
186 {
187 kNoAttributes = 0, // Simple Mt-process which doesn't require any special initializations
188
189 kMtLoadingAttributes = (1 << 0), // Actual for both MtLoading and loading of DB's in multiple threads
190 kMtRegenAttributes = (1 << 1), // Multithread regeneration
191 kStRegenAttributes = (1 << 2), // Regeneration w/o cache (local heaps not required)
192 kMtDisplayAttributes = (1 << 3), // Multithread display
193 kMtModelerAttributes = (1 << 4), // Modeling operations in parallel threads
194 kAllAttributes = 0xFFFFFFFF // Applicable for Mt functionality tests
195 };
196protected:
198 : m_count(1)
199 , m_mainThreadFunc(NULL)
200 , m_threadPool(NULL) { }
202public:
206 operator bool() const { return m_count > 1; }
207
226 bool hasReactor(ThreadsCounterReactor *pReactor) const;
230 int nReactors() const;
231
232 /* Following methods are intended for internal usage by ODA Platform libraries and not recommended for usage outside. */
233
243
250 void increase(unsigned nThreads, const unsigned* aThreads, unsigned nThreadAttributes = ThreadsCounter::kNoAttributes)
251 { if (nThreads && aThreads) { ++m_count; increaseProc(nThreads, aThreads, nThreadAttributes); } }
252
257 void decrease(unsigned nThreads, const unsigned* aThreads)
258 { if (nThreads && aThreads) { --m_count; decreaseProc(nThreads, aThreads); } }
259
268
274 bool hasThread(unsigned nThreadId, unsigned *pThreadAttributes)
275 { return hasThreadProc(nThreadId, pThreadAttributes); }
276
286
287protected:
288 void increaseProc(unsigned nThreads, const unsigned* aThreads, unsigned nThreadAttributes);
289 void decreaseProc(unsigned nThreads, const unsigned* aThreads);
292 bool hasThreadProc(unsigned nThreadId, unsigned *pThreadAttributes);
293
294protected:
298};
299
301
302FIRSTDLL_EXPORT bool odExecuteMainThreadAction(MainThreadFunc mtFunc, void *pArg, bool bExecST = true);
303
306
307#define TD_AUTOLOCK_P(Mutex) OdMutexPtrAutoLock autoLock(Mutex);
308#define TD_AUTOLOCK_P_DEF(Mutex) OdMutexPtrAutoLock autoLock(odThreadsCounter() ? Mutex.get() : NULL);
309
310#include "TD_PackPop.h"
311
312#endif //_THREADS_COUNTER_H_
false
Definition DimVarDefs.h:165
int OdRefCounter
Definition OdMutex.h:478
#define FIRSTDLL_EXPORT
Definition RootExport.h:39
FIRSTDLL_EXPORT void odThreadYield()
void(* ExecuteMainThreadFunc)(MainThreadFunc, void *)
FIRSTDLL_EXPORT bool odExecuteMainThreadAction(MainThreadFunc mtFunc, void *pArg, bool bExecST=true)
void(* MainThreadFunc)(void *)
FIRSTDLL_EXPORT ThreadsCounter & odThreadsCounter()
FIRSTDLL_EXPORT unsigned odGetCurrentThreadId()
void set(bool bEnable)
OdMutexPtrAutoLock(OdMutex *mutex)
void clear()
OdMutex * get()
void increaseProc(unsigned nThreads, const unsigned *aThreads, unsigned nThreadAttributes)
void startThreadProc()
void setThreadPoolService(OdRxThreadPoolService *pService)
bool removeReactor(ThreadsCounterReactor *pReactor)
OdRefCounter m_count
ExecuteMainThreadFunc m_mainThreadFunc
bool hasThreadProc(unsigned nThreadId, unsigned *pThreadAttributes)
OdRxThreadPoolService * getThreadPoolService()
ExecuteMainThreadFunc getMainThreadFunc()
void stopThreadProc()
void setMainThreadFunc(ExecuteMainThreadFunc func)
void decreaseProc(unsigned nThreads, const unsigned *aThreads)
OdRxThreadPoolService * m_threadPool
bool hasReactor(ThreadsCounterReactor *pReactor) const
bool hasThread(unsigned nThreadId, unsigned *pThreadAttributes)
void decrease(unsigned nThreads, const unsigned *aThreads)
int nReactors() const
void increase(unsigned nThreads, const unsigned *aThreads, unsigned nThreadAttributes=ThreadsCounter::kNoAttributes)
bool addReactor(ThreadsCounterReactor *pReactor)
virtual void decrease(unsigned, const unsigned *, unsigned)
virtual void startThread(unsigned, unsigned)
virtual void increase(unsigned, const unsigned *, unsigned)
virtual void stopThread(unsigned, unsigned)
GLenum func
Definition gles2_ext.h:262
typedef void(APIENTRYP PFNGLACTIVETEXTUREPROC)(GLenum texture)