lib: Remove unused threading functionality related to thread results

This commit is contained in:
Povilas Kanapickas 2021-11-01 06:16:30 +02:00
parent 666460aced
commit 815e80ec4d
8 changed files with 8 additions and 79 deletions

View File

@ -235,15 +235,6 @@ public:
*/ */
virtual bool isExitedThread(ArchThread thread) = 0; virtual bool isExitedThread(ArchThread thread) = 0;
//! Returns the exit code of a thread
/*!
Waits indefinitely for \c thread to exit (if it hasn't yet) then
returns the thread's exit code.
(Cancellation point)
*/
virtual void* getResultOfThread(ArchThread thread) = 0;
//! Returns an ID for a thread //! Returns an ID for a thread
/*! /*!
Returns some ID number for \c thread. This is for logging purposes. Returns some ID number for \c thread. This is for logging purposes.

View File

@ -64,7 +64,6 @@ public:
bool m_cancel; bool m_cancel;
bool m_cancelling; bool m_cancelling;
bool m_exited; bool m_exited;
void* m_result;
void* m_networkData; void* m_networkData;
}; };
@ -76,7 +75,6 @@ ArchThreadImpl::ArchThreadImpl() :
m_cancel(false), m_cancel(false),
m_cancelling(false), m_cancelling(false),
m_exited(false), m_exited(false),
m_result(NULL),
m_networkData(NULL) m_networkData(NULL)
{ {
// do nothing // do nothing
@ -526,13 +524,6 @@ ArchMultithreadPosix::isExitedThread(ArchThread thread)
return thread->m_exited; return thread->m_exited;
} }
void*
ArchMultithreadPosix::getResultOfThread(ArchThread thread)
{
std::lock_guard<std::mutex> lock(m_threadMutex);
return thread->m_result;
}
IArchMultithread::ThreadID IArchMultithread::ThreadID
ArchMultithreadPosix::getIDOfThread(ArchThread thread) ArchMultithreadPosix::getIDOfThread(ArchThread thread)
{ {
@ -699,10 +690,8 @@ ArchMultithreadPosix::doThreadFunc(ArchThread thread)
std::lock_guard<std::mutex> lock(m_threadMutex); std::lock_guard<std::mutex> lock(m_threadMutex);
} }
void* result = NULL;
try { try {
// go (*thread->m_func)(thread->m_userData);
result = (*thread->m_func)(thread->m_userData);
} }
catch (XThreadCancel&) { catch (XThreadCancel&) {
@ -721,7 +710,6 @@ ArchMultithreadPosix::doThreadFunc(ArchThread thread)
// thread has exited // thread has exited
{ {
std::lock_guard<std::mutex> lock(m_threadMutex); std::lock_guard<std::mutex> lock(m_threadMutex);
thread->m_result = result;
thread->m_exited = true; thread->m_exited = true;
} }

View File

@ -77,7 +77,6 @@ public:
virtual bool wait(ArchThread, double timeout); virtual bool wait(ArchThread, double timeout);
virtual bool isSameThread(ArchThread, ArchThread); virtual bool isSameThread(ArchThread, ArchThread);
virtual bool isExitedThread(ArchThread); virtual bool isExitedThread(ArchThread);
virtual void* getResultOfThread(ArchThread);
virtual ThreadID getIDOfThread(ArchThread); virtual ThreadID getIDOfThread(ArchThread);
virtual void setSignalHandler(ESignal, SignalFunc, void*); virtual void setSignalHandler(ESignal, SignalFunc, void*);
virtual void raiseSignal(ESignal); virtual void raiseSignal(ESignal);

View File

@ -54,7 +54,6 @@ public:
HANDLE m_cancel; HANDLE m_cancel;
bool m_cancelling; bool m_cancelling;
HANDLE m_exit; HANDLE m_exit;
void* m_result;
void* m_networkData; void* m_networkData;
}; };
@ -65,7 +64,6 @@ ArchThreadImpl::ArchThreadImpl() :
m_func(NULL), m_func(NULL),
m_userData(NULL), m_userData(NULL),
m_cancelling(false), m_cancelling(false),
m_result(NULL),
m_networkData(NULL) m_networkData(NULL)
{ {
m_exit = CreateEvent(NULL, TRUE, FALSE, NULL); m_exit = CreateEvent(NULL, TRUE, FALSE, NULL);
@ -523,15 +521,6 @@ ArchMultithreadWindows::isExitedThread(ArchThread thread)
return (WaitForSingleObject(thread->m_exit, 0) == WAIT_OBJECT_0); return (WaitForSingleObject(thread->m_exit, 0) == WAIT_OBJECT_0);
} }
void*
ArchMultithreadWindows::getResultOfThread(ArchThread thread)
{
lockMutex(m_threadMutex);
void* result = thread->m_result;
unlockMutex(m_threadMutex);
return result;
}
IArchMultithread::ThreadID IArchMultithread::ThreadID
ArchMultithreadWindows::getIDOfThread(ArchThread thread) ArchMultithreadWindows::getIDOfThread(ArchThread thread)
{ {
@ -678,10 +667,9 @@ ArchMultithreadWindows::doThreadFunc(ArchThread thread)
lockMutex(m_threadMutex); lockMutex(m_threadMutex);
unlockMutex(m_threadMutex); unlockMutex(m_threadMutex);
void* result = NULL;
try { try {
// go // go
result = (*thread->m_func)(thread->m_userData); (*thread->m_func)(thread->m_userData);
} }
catch (XThreadCancel&) { catch (XThreadCancel&) {
@ -695,9 +683,6 @@ ArchMultithreadWindows::doThreadFunc(ArchThread thread)
} }
// thread has exited // thread has exited
lockMutex(m_threadMutex);
thread->m_result = result;
unlockMutex(m_threadMutex);
SetEvent(thread->m_exit); SetEvent(thread->m_exit);
// done with thread // done with thread

View File

@ -83,7 +83,6 @@ public:
virtual bool wait(ArchThread, double timeout); virtual bool wait(ArchThread, double timeout);
virtual bool isSameThread(ArchThread, ArchThread); virtual bool isSameThread(ArchThread, ArchThread);
virtual bool isExitedThread(ArchThread); virtual bool isExitedThread(ArchThread);
virtual void* getResultOfThread(ArchThread);
virtual ThreadID getIDOfThread(ArchThread); virtual ThreadID getIDOfThread(ArchThread);
virtual void setSignalHandler(ESignal, SignalFunc, void*); virtual void setSignalHandler(ESignal, SignalFunc, void*);
virtual void raiseSignal(ESignal); virtual void raiseSignal(ESignal);

View File

@ -69,7 +69,7 @@ Thread::operator=(const Thread& thread)
void void
Thread::exit(void* result) Thread::exit(void* result)
{ {
throw XThreadExit(result); throw XThreadExit();
} }
void void
@ -108,15 +108,6 @@ Thread::wait(double timeout) const
return ARCH->wait(m_thread, timeout); return ARCH->wait(m_thread, timeout);
} }
void*
Thread::getResult() const
{
if (wait())
return ARCH->getResultOfThread(m_thread);
else
return NULL;
}
IArchMultithread::ThreadID IArchMultithread::ThreadID
Thread::getID() const Thread::getID() const
{ {
@ -149,8 +140,6 @@ Thread::threadFunc(void* vjob)
// get job // get job
IJob* job = static_cast<IJob*>(vjob); IJob* job = static_cast<IJob*>(vjob);
// run job
void* result = NULL;
try { try {
// go // go
LOG((CLOG_DEBUG1 "thread 0x%08x entry", id)); LOG((CLOG_DEBUG1 "thread 0x%08x entry", id));
@ -163,10 +152,8 @@ Thread::threadFunc(void* vjob)
delete job; delete job;
throw; throw;
} }
catch (XThreadExit& e) { catch (XThreadExit&) {
// client called exit() LOG((CLOG_DEBUG1 "caught exit on thread 0x%08x", id));
result = e.m_result;
LOG((CLOG_DEBUG1 "caught exit on thread 0x%08x, result %p", id, result));
} }
catch (XBase& e) { catch (XBase& e) {
LOG((CLOG_ERR "exception on thread 0x%08x: %s", id, e.what())); LOG((CLOG_ERR "exception on thread 0x%08x: %s", id, e.what()));
@ -182,6 +169,5 @@ Thread::threadFunc(void* vjob)
// done with job // done with job
delete job; delete job;
// return exit result return nullptr;
return result;
} }

View File

@ -79,8 +79,7 @@ public:
/*! /*!
Terminate the calling thread. This function does not return but Terminate the calling thread. This function does not return but
the stack is unwound and automatic objects are destroyed, as if the stack is unwound and automatic objects are destroyed, as if
exit() threw an exception (which is, in fact, what it does). The exit() threw an exception (which is, in fact, what it does). If you
argument is saved as the result returned by getResult(). If you
have \c catch(...) blocks then you should add the following before have \c catch(...) blocks then you should add the following before
each to avoid catching the exit: each to avoid catching the exit:
\code \code
@ -167,16 +166,6 @@ public:
*/ */
bool wait(double timeout = -1.0) const; bool wait(double timeout = -1.0) const;
//! Get the exit result
/*!
Returns the exit result. This does an implicit wait(). It returns
NULL immediately if called by a thread on itself or on a thread that
was cancelled.
(cancellation point)
*/
void* getResult() const;
//! Get the thread id //! Get the thread id
/*! /*!
Returns an integer id for this thread. This id must not be used to Returns an integer id for this thread. This id must not be used to

View File

@ -26,12 +26,4 @@ Thrown by Thread::exit() to exit a thread. Clients of Thread
must not throw this type but must rethrow it if caught (by must not throw this type but must rethrow it if caught (by
XThreadExit, XThread, or ...). XThreadExit, XThread, or ...).
*/ */
class XThreadExit : public XThread { class XThreadExit : public XThread {};
public:
//! \c result is the result of the thread
XThreadExit(void* result) : m_result(result) { }
~XThreadExit() { }
public:
void* m_result;
};