#include <opennurbs_terminator.h>
◆ ON_Terminator()
ON_Terminator::ON_Terminator |
( |
| ) |
|
◆ ~ON_Terminator()
ON_Terminator::~ON_Terminator |
( |
| ) |
|
◆ CallbackContext()
ON__UINT_PTR ON_Terminator::CallbackContext |
( |
| ) |
const |
◆ CallbackFunction()
ON__UINT_PTR ON_Terminator::CallbackFunction |
( |
| ) |
const |
◆ RequestTermination() [1/2]
void ON_Terminator::RequestTermination |
( |
| ) |
|
Sets m_bTerminationRequested = true. All future calls to TerminationRequested(this) will return true.
◆ RequestTermination() [2/2]
static void ON_Terminator::RequestTermination |
( |
ON_Terminator * |
terminator | ) |
|
|
static |
If terminator is not nullptr, sets terminator->m_bTerminationRequested = true. If terminator is not nullptr, all future calls to TerminationRequested(terminator) will return true.
- Parameters
-
terminator | [in] (can be nullptr) |
This is convenience function and is identical to the code
if (nullptr != terminator) terminator->RequestTermination();
◆ SetTerminationQueryCallbackFunction()
void ON_Terminator::SetTerminationQueryCallbackFunction |
( |
bool(*)(ON__UINT_PTR context) |
callback_function, |
|
|
ON__UINT_PTR |
callback_context |
|
) |
| |
Set the function that is called when a calculation wants to determine if the calculation should stop or continue.
- Parameters
-
callback_function | [in]
- The function that is called when a calculation wants to determine if the calculation should stop or continue.
- If this callback function returns true, the calculation will terminate as soon as possible.
- If this callback function returns false, the calculation will continue.
- The calculation thread calls in this callback function.
- The callback function should do something that is fast and simple. Parameters passed to the callback function:
|
context | [in] the value of callback_context. |
bool bStopCalculation = false;
bool StopCalculation( ON__UINT_PTR context )
{
if ( 0 != context )
{
const bool* p = (const bool*)context;
if ( *p )
return true;
}
return false;
}
...
ON_Terminator terminator;
terminator.SetTerminationQueryCallbackFunction(StopCalculation,(ON__UINT_PTR)(&bStopCalculation));
...
Pass &terminator to a calculation and then set bStopCalculation = true to terminate it.
The calculation will generally be running in another thread, but can be in the same
thread if it is structured to pump windows messages or something similar.
◆ SetThreadId()
void ON_Terminator::SetThreadId |
( |
ON__UINT_PTR |
thread_id | ) |
|
◆ TerminationRequested()
static bool ON_Terminator::TerminationRequested |
( |
ON_Terminator * |
terminator | ) |
|
|
static |
A calculation calls ON_Terminator::TerminationRequested(terminator) to determine if it should continue or quit.
- Parameters
-
- Returns
- True if the calculation should terminate as soon as possible. False if the calculation should continue.
{
for ( i = 0; i < count; i++ )
{
break;
...
}
}
◆ TerminationRequestedExpert()
static bool ON_Terminator::TerminationRequestedExpert |
( |
ON_Terminator * |
terminator, |
|
|
ON__UINT64 |
callback_delta |
|
) |
| |
|
static |
An expert user function to determine if a calculation should continue.
- Parameters
-
terminator | [in] A pointer to an ON_Terminator or null pointer. |
callback_delta | [in] Minimum amount of time to delay between calls to the registered callback function in clock() time units. 0 will omit making any call to the registered function. ON_Terminator::TerminationRequested( terminator ) uses a value of callback_delta = CLOCKS_PER_SEC/10 meaning a maximum of 10 callbacks per second. |
- Returns
- True if the calculation should terminate as soon as possible. False if the calculation should continue.
In general, call the ON_Terminator::TerminationRequested( terminator ).
◆ ThreadId()
ON__UINT_PTR ON_Terminator::ThreadId |
( |
| ) |
const |