-
首页
-
C4D R23.110 C++ SDK
ThreadRefTemplate< INTERFACE > Class Template Reference
线程
#include <thread.h>
详细描述
template<typename INTERFACE>
class maxon::ThreadRefTemplate< INTERFACE >
Reference to a thread (
ThreadInterface
).
-
Template Parameters
-
INTERFACE
|
Interface class for the ThreadRef (inherits from
ThreadInterface
).
|
公共成员函数
|
|
MAXON_DEFAULT_REFERENCE_CONSTRUCTORS
(
ThreadRefTemplate
,
Ptr
)
|
MAXON_IMPLICIT
|
ThreadRefTemplate
(const
Ptr
&
src
)
|
MAXON_IMPLICIT
|
ThreadRefTemplate
(
Ptr
&&
src
)
|
Bool
|
IsRunning
() const
|
Bool
|
Wait
(
TimeValue
timeout=
TIMEVALUE_INFINITE
,
WAITMODE
mode=
WAITMODE::DEFAULT
) const
|
Result
< void >
|
GetResult
(
TimeValue
timeout=
TIMEVALUE_INFINITE
,
WAITMODE
mode=
WAITMODE::DEFAULT
) const
|
void
|
取消
()
|
Bool
|
IsCancelled
() const
|
void
|
CancelAndWait
(
WAITMODE
mode=
WAITMODE::DEFAULT
)
|
Result
< void >
|
开始
(
THREADPRIORITY
priority=
THREADPRIORITY::NORMAL
)
|
ObservableFinishedBase< INTERFACE >
|
ObservableFinished
()
|
String
|
ToString
(const
FormatStatement
*formatStatement=nullptr) const
|
Bool
|
operator==
(const
ThreadRefTemplate
&other) const
|
Bool
|
operator!=
(const
ThreadRefTemplate
&other) const
|
T *
|
GetPointer
()
|
ConstReferencedType
*
|
GetPointer
() const
|
T *
|
operator->
()
|
ConstReferencedType
*
|
operator->
() const
|
T &
|
operator*
()
|
ConstReferencedType
&
|
operator*
() const
|
|
operator T*
()
|
|
operator ConstReferencedType *
() const
|
|
operator Bool
() const
|
|
operator Bool
()
|
const T &
|
operator[]
(
Int
) const =delete
|
ResultRef
< typename std::remove_const< T >::type >
|
MakeWritable
(
Bool
resetOnError=true)
|
T &
|
GetOrNull
() const
|
|
BaseRef
()
|
MAXON_IMPLICIT
|
BaseRef
(std::nullptr_t)=delete
|
MAXON_IMPLICIT
|
BaseRef
(T *o)
|
template<typename PTR >
|
|
BaseRef
(
ForwardResultPtr
< PTR > o)
|
|
BaseRef
(
ResultPtr
< T > o,
Int
)
|
|
BaseRef
(const
BaseRef
&
src
)
|
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type>
|
MAXON_IMPLICIT
|
BaseRef
(const REF &
src
)
|
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type>
|
MAXON_IMPLICIT
|
BaseRef
(REF &
src
)
|
BaseRef
&
|
operator=
(T *
src
)
|
BaseRef
&
|
operator=
(std::nullptr_t
src
)
|
BaseRef
&
|
operator=
(const
BaseRef
&
src
)
|
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type>
|
BaseRef
&
|
operator=
(const REF &
src
)
|
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type>
|
BaseRef
&
|
operator=
(REF &
src
)
|
|
BaseRef
(
BaseRef
&&
src
)
|
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(const, REF) && !STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type>
|
MAXON_IMPLICIT
|
BaseRef
(REF &&
src
)
|
BaseRef
&
|
operator=
(
BaseRef
&&
src
)
|
template<typename REF , typename = typename std::enable_if<!STD_IS_REPLACEMENT(const, REF) && !STD_IS_REPLACEMENT(base_of, BaseRef, REF) && maxon::HasErasedBase<typename REF::ReferencedType, ReferencedType>::value>::type>
|
BaseRef
&
|
operator=
(REF &&
src
)
|
|
~BaseRef
()
|
Bool
|
operator==
(const
BaseRef
&b) const
|
Bool
|
operator!=
(const
BaseRef
&b) const
|
Bool
|
operator==
(const T *b) const
|
Bool
|
operator!=
(const T *b) const
|
Bool
|
operator==
(typename std::remove_const< T >::type *b) const
|
Bool
|
operator!=
(typename std::remove_const< T >::type *b) const
|
Bool
|
operator==
(std::nullptr_t) const
|
Bool
|
operator!=
(std::nullptr_t) const
|
HashInt
|
GetHashCode
() const
|
T *
|
Disconnect
()
|
void
|
PrivateSetTarget
(
ResultPtr
< T >
src
)
|
void
|
PrivateSetPointer
(T *ptr)
|
静态公共成员函数
|
template<THREADCANCELLATION B = THREADCANCELLATION::AUTOMATIC, typename FN , typename... ARGS>
|
static auto
|
创建
(FN &&
src
, ARGS &&... args) ->
ResultMemT
<
ThreadResultRef
< decltype(
src
(std::forward< ARGS >(args)...))>>
|
static
StrongRef
< const INTERFACE >
|
GetCurrentThread
()
|
static
Int
|
GetCurrentThreadCount
()
|
static
Bool
|
IsMainThread
()
|
static
THREADTYPE
|
GetCurrentThreadType
()
|
static
THREADTYPE
|
GetCurrentThreadType
(
Int
&threadIdentifier)
|
static
Result
< void >
|
AssimilateAlienThread
()
|
static
Bool
|
IsCurrentThreadCancelled
(const
ThreadInterface
*optionalThread=nullptr)
|
static
Bool
|
IsCurrentThreadCancelled
(const
ThreadRefTemplate
< INTERFACE > &optionalThread)
|
template<THREADCANCELLATION B = THREADCANCELLATION::AUTOMATIC, typename FN >
|
static
MAXON_WARN_UNUSED
auto
|
Run
(FN &&
src
,
THREADPRIORITY
priority=
THREADPRIORITY::NORMAL
) ->
ResultMemT
<
ThreadResultRef
< decltype(
src
())>>
|
template<THREADCANCELLATION B = THREADCANCELLATION::AUTOMATIC, typename FN , typename... ARGS>
|
static auto
|
Run
(FN &&
src
,
THREADPRIORITY
priority, ARGS &&... args) ->
ResultMemT
<
ThreadResultRef
< decltype(
src
(std::forward< ARGS >(args)...))>>
|
static const
ThreadRefTemplate
&
|
NullValue
()
|
static std::false_type
|
GenericVarianceCheck
(const void *)
|
template<typename... ARGS>
|
static
MAXON_ATTRIBUTE_FORCE_INLINE
ResultMemT
<
BaseRef
>
|
创建
(ARGS &&... args)
|
static const
BaseRef
&
|
NullValueRef
()
|
static std::conditional<
Bool
(HANDLER::KIND &
VALUEKIND::UNIQUE_REFERENCE
),
BaseRef
, const
BaseRef
& >::type
|
NullValue
()
|
Static Private Member Functions
|
template<JOBCANCELLATION B, typename FN , typename... ARGS>
|
static INTERFACE *
|
CreateThread
(FN &&
src
, ARGS &&... args)
|
Member Typedef Documentation
◆
Ptr
构造函数 & 析构函数文档编制
◆
ThreadRefTemplate()
[1/2]
◆
ThreadRefTemplate()
[2/2]
成员函数文档编制
◆
MAXON_DEFAULT_REFERENCE_CONSTRUCTORS()
◆
Create()
Creates a reference to a thread with n arguments.
-
参数
-
[in]
|
src
|
Lambda or object with operator ().
|
[in]
|
args
|
Arguments for the function.
|
-
Template Parameters
-
B
|
Behaviour for early thread cancellation.
|
FN
|
Type of function/lambda, deduced by the compiler.
|
ARGS
|
Parameter types.
|
-
返回
-
OK on success.
◆
IsRunning()
Checks whether this thread is currently running. Will return false for a null reference. THREADSAFE.
-
返回
-
False if the thread wasn't running anymore.
◆
Wait()
Waits until the referenced thread has been executed. As long as a thread hasn't been started it is considered not to have finished yet. Once it has run this will return immediately until you restart the thread.
Wait()
might execute other jobs in the current queue until the one you are waiting for has finished or is timed out. Therefore you may never lock a shared resource another job might use as well and then wait. For one this could dead-lock and conceptually this would result in single-threaded performance.
If you call
Wait()
from within an enqueued job
you must have started what you are waiting for
. Otherwise
Wait()
will immediately return false because this would lead to a deadlock. The same applies if a thread tries to wait for itself.
Instead of waiting for a thread to start some action after it has finished you can subscribe to
ObservableFinished()
. This cannot dead-lock, is more efficient and can even be used to run the observer in a different queue. For example you can run a thread and register an observer for it that will run on the main thread's queue and updates the UI. THREADSAFE.
-
参数
-
[in]
|
timeout
|
Maximum wait interval (or TIMEVALUE_INFINITE for no time-out).
|
[in]
|
mode
|
WAITMODE::DEFAULT
by default.
WAITMODE::RETURN_ON_CANCEL
means that
Wait()
will return if the caller has been cancelled even if the condition has not been set yet.
|
-
返回
-
True if successful, false if you try to wait inside an enqueued job or there is no job at all.
◆
GetResult()
Waits until this thread has been executed and returns the result. THREADSAFE.
-
参数
-
[in]
|
timeout
|
Maximum wait interval (or TIMEVALUE_INFINITE for no time-out).
|
[in]
|
mode
|
WAITMODE::DEFAULT
by default.
WAITMODE::RETURN_ON_CANCEL
means that
Wait()
will return if the caller has been cancelled even if the condition has not been set yet.
|
-
返回
-
OK on success.
◆
Cancel()
Asks the thread to cancel execution. The call will not wait for the thread to cancel. THREADSAFE.
◆
IsCancelled()
Bool
IsCancelled
|
(
|
|
)
|
const
|
Checks if the thread should stop. Will return true for a null reference. THREADSAFE.
-
返回
-
True if the thread has been asked to cancel.
◆
CancelAndWait()
Asks the thread to cancel execution and waits until it has finished. THREADSAFE.
-
参数
-
◆
Start()
Starts a thread to execute this job's worker method (will add a reference and remove it when the object is no longer needed). If you try to start an already running thread this will fail and return an error.
-
参数
-
-
返回
-
OK on success. Fails if the thread is already running or no more threads are available.
◆
ObservableFinished()
ObservableFinishedBase<INTERFACE> ObservableFinished
|
(
|
|
)
|
|
ObservableFinished is an observable that is triggered after this job has been executed. THREADSAFE.
-
返回
-
Custom observable.
◆
GetCurrentThread()
static
StrongRef
<const INTERFACE> GetCurrentThread
|
(
|
|
)
|
|
|
static
|
Returns a pointer to the currently running thread. If you call this from a job or a thread you have created by using OS APIs a nullptr is returned. THREADSAFE.
-
返回
-
This thread's ThreadInterface* or nullptr (worker, main or other OS thread)
◆
GetCurrentThreadCount()
static
Int
GetCurrentThreadCount
|
(
|
|
)
|
|
|
static
|
Returns the number of worker threads for the current job context. This might be different from the actual CPU core or thread count. THREADSAFE.
-
返回
-
Number of worker threads, guaranteed to be > 0.
◆
IsMainThread()
static
Bool
IsMainThread
|
(
|
|
)
|
|
|
static
|
Checks if this thread is the main application thread. THREADSAFE.
-
返回
-
True if this is the main application thread.
◆
GetCurrentThreadType()
[1/2]
Returns information about the current thread. THREADSAFE.
-
返回
-
See THREADTYPE.
◆
GetCurrentThreadType()
[2/2]
static
THREADTYPE
GetCurrentThreadType
|
(
|
Int
&
|
threadIdentifier
|
)
|
|
|
static
|
Returns information about the current thread. THREADSAFE.
-
参数
-
[out]
|
threadIdentifier
|
For
THREADTYPE::WORKER
the the index of the worker thread is returned, for
THREADTYPE::MAIN
0 is returned if it currently executes jobs. Otherwise this is an opaque identifier for the current thread.
|
-
返回
-
See THREADTYPE.
◆
AssimilateAlienThread()
static
Result
<void> AssimilateAlienThread
|
(
|
|
)
|
|
|
static
|
Allocates internal resources for an alien thread (CoreThread, unique thread index and so on). THREADSAFE.
-
返回
-
OK on success.
◆
IsCurrentThreadCancelled()
[1/2]
Checks if the currently running thread (or job) should stop. Works for jobs and threads. THREADSAFE.
-
参数
-
[in]
|
optionalThread
|
Optional thread which should also be checked for cancellation.
|
-
返回
-
True if the thread has been asked to cancel.
◆
IsCurrentThreadCancelled()
[2/2]
Checks if the currently running thread (or job) should stop. Works for jobs and threads. THREADSAFE.
-
参数
-
[in]
|
optionalThread
|
Thread which should also be checked for cancellation.
|
-
返回
-
True if the thread has been asked to cancel.
◆
Run()
[1/2]
Runs a lambda or object with operator () and n arguments in a thread. THREADSAFE.
-
参数
-
-
Template Parameters
-
B
|
Behaviour for early thread cancellation.
|
FN
|
Type of function/lambda, deduced by the compiler.
|
-
返回
-
The
ThreadInterface
encapsulating the closure, might be nullptr if starting the thread failed.
◆
Run()
[2/2]
Runs a lambda or object with operator () and n arguments in a thread. THREADSAFE.
-
参数
-
-
Template Parameters
-
B
|
Behaviour for early thread cancellation.
|
FN
|
Type of function/lambda, deduced by the compiler.
|
ARGS
|
Parameter types.
|
-
返回
-
The
ThreadInterface
encapsulating the closure, might be nullptr if starting the thread failed.
◆
ToString()
Returns a readable string of the content.
-
参数
-
[in]
|
formatStatement
|
Nullptr or additional formatting instruction. Currently no additional formatting instructions are supported.
|
-
返回
-
The converted result.
◆
operator==()
◆
operator!=()
◆
NullValue()
◆
GCCWorkaroundRun()
Workaround for buggy gcc 4.7. It mixes up the member method Run(priority) and the static method Run(fn, priority). THREADSAFE.
-
参数
-
-
返回
-
The
ThreadInterface
encapsulating the closure, might be nullptr if memory allocation or thread start failed.
◆
CreateThread()
static INTERFACE* CreateThread
|
(
|
FN &&
|
src
,
|
|
|
ARGS &&...
|
args
|
|
)
|
|
|
|
static
private
|