document functions in the Thread class; add a helper detach() method for future use;

pull/51/head
Bryan Biedenkapp 2 years ago
parent 4acb60aeff
commit 1e8a842a30

@ -58,7 +58,7 @@ bool Thread::run()
} }
/// <summary> /// <summary>
/// /// Make calling thread wait for termination of the thread.
/// </summary> /// </summary>
void Thread::wait() void Thread::wait()
{ {
@ -66,7 +66,7 @@ void Thread::wait()
} }
/// <summary> /// <summary>
/// /// Set thread name visible in the kernel and its interfaces.
/// </summary> /// </summary>
/// <param name="name"></param> /// <param name="name"></param>
void Thread::setName(std::string name) void Thread::setName(std::string name)
@ -80,6 +80,19 @@ void Thread::setName(std::string name)
#endif // _GNU_SOURCE #endif // _GNU_SOURCE
} }
/// <summary>
/// Indicate that the thread is never to be joined with wait().
/// The resources of thread will therefore be freed immediately when it
/// terminates, instead of waiting for another thread to perform wait()
/// on it.
/// </summary>
void Thread::detach()
{
if (!m_started)
return;
::pthread_detach(m_thread);
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -94,7 +107,7 @@ void Thread::sleep(uint32_t ms)
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/// <summary> /// <summary>
/// /// Internal helper thats used as the entry point for the thread.
/// </summary> /// </summary>
/// <param name="arg"></param> /// <param name="arg"></param>
/// <returns></returns> /// <returns></returns>

@ -39,19 +39,25 @@ public:
/// <summary>User-defined function to run for the thread main.</summary> /// <summary>User-defined function to run for the thread main.</summary>
virtual void entry() = 0; virtual void entry() = 0;
/// <summary></summary> /// <summary>Make calling thread wait for termination of the thread.</summary>
virtual void wait(); virtual void wait();
/// <summary></summary> /// <summary>Set thread name visible in the kernel and its interfaces.</summary>
virtual void setName(std::string name); virtual void setName(std::string name);
/// <summary>Indicate that the thread is never to be joined with wait().
/// The resources of thread will therefore be freed immediately when it
/// terminates, instead of waiting for another thread to perform wait()
/// on it.</summary>
virtual void detach();
/// <summary></summary> /// <summary></summary>
static void sleep(uint32_t ms); static void sleep(uint32_t ms);
private: private:
pthread_t m_thread; pthread_t m_thread;
/// <summary></summary> /// <summary>Internal helper thats used as the entry point for the thread.</summary>
static void* helper(void* arg); static void* helper(void* arg);
public: public:

Loading…
Cancel
Save

Powered by TurnKey Linux.