CyberEngineMkIII
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CYBThread.cpp
Go to the documentation of this file.
1 #include "CYB.hpp"
3 
6  try {
7  const auto ThreadID(Core().ThreadID());
8  API::Assert::LessThan(1ULL, ThreadID); //1 is the main thread, and if we've overflowed, someone screwed up somewhere
9  if(ThreadID > 2) //not
10  Engine::Context::GetContext().FLogger.Log(API::String::Static(u8"Thread started."), API::Logger::Level::DEV);
11 
12  AThreadable.BeginThreadedOperation();
13 
14  Engine::Context::GetContext().FLogger.Log(API::String::Static(u8"Thread finished."), API::Logger::Level::DEV);
15  }
16  catch (CYB::Exception::Base AException) {
17  auto& Logger(Engine::Context::GetContext().FLogger);
18  Logger.Log(API::String::Static(u8"Unhandled CYB exception crashed this thread. Error message follows: "), API::Logger::Level::ERR);
19  Logger.Log(AException.FMessage, API::Logger::Level::ERR);
20  }
21  catch (...) {
22  Engine::Context::GetContext().FLogger.Log(API::String::Static(u8"Unhandled unknown exception crashed this thread with no survivors."), API::Logger::Level::ERR);
23  }
24 }
25 
27  Implementation::Thread(AThreadable),
28  FCancelSubmitted(false)
29 {}
30 
32  Wait();
33 }
34 
36  if (!FCancelSubmitted && !IsFinished()) {
37  FCancelSubmitted = true;
38  FThreadable.CancelThreadedOperation();
39  }
40 }
Thread(API::Threadable &AThreadable)
Construct a Thread. Once returned, the thread will be scheduled to run and BeginThreadedOperation wil...
Definition: CYBThread.cpp:26
~Thread()
Destroy a thread. Will block the caller until the owned thread terminates.
Definition: CYBThread.cpp:31
API::String::Static FMessage
An english description of the error, guaranteed to be compatible with CYB::API::String::UTF8.
Definition: Exception.hpp:17
virtual void Log(const String::CStyle &AMessage, const Level ALevel)=0
Log a message. Will be written to a text file on the Path returned by CurrentLog. ...
A string pointing to unchanging data in the stack above it or the data segment. Must have UTF-8 encod...
Definition: StaticString.hpp:7
Definition of a platform thread object.
Definition: CYBThread.hpp:7
void DefaultContext(void) noexcept
Set the current Context to FEngineContext.
Definition: CYBCore.cpp:65
static void RunThread(API::Threadable &AThreadable) noexcept
Properly traps and logs exceptions generated by threads. And runs AThreadable.
Definition: CYBThread.cpp:4
The basic multithreading interface.
Definition: Threadable.hpp:6
Precompiled header for inter-engine operations.
Engine::Core & Core(void) noexcept
Retrieve the Core singleton.
Definition: CYBCore.cpp:69
void Cancel(void)
Cancel a thread. Calls CancelThreadedOperation on the assigned Threadable in the current thread if Is...
Definition: CYBThread.cpp:35
The interface for writing safe logs.
Definition: Logger.hpp:7
The base exception recognized by the entire engine.
Definition: Exception.hpp:7