diff options
| author | 2021-11-10 00:54:13 -0500 | |
|---|---|---|
| committer | 2021-11-10 00:54:13 -0500 | |
| commit | beb08eb751fa8e1f72042f263316ab5e5ddb596d (patch) | |
| tree | 3b00df983527648bdae610ac7b88cb639b1f1828 /src/lib/mt | |
| parent | fbc30002ab3438356c0476e70c4577a0310d52c0 (diff) | |
New upstream version 2.4.0+dfsg.upstream/2.4.0+dfsgupstream
Diffstat (limited to 'src/lib/mt')
| -rw-r--r-- | src/lib/mt/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/lib/mt/CondVar.cpp | 6 | ||||
| -rw-r--r-- | src/lib/mt/CondVar.h | 6 | ||||
| -rw-r--r-- | src/lib/mt/Lock.cpp | 4 | ||||
| -rw-r--r-- | src/lib/mt/Lock.h | 4 | ||||
| -rw-r--r-- | src/lib/mt/Mutex.cpp | 4 | ||||
| -rw-r--r-- | src/lib/mt/Mutex.h | 4 | ||||
| -rw-r--r-- | src/lib/mt/Thread.cpp | 46 | ||||
| -rw-r--r-- | src/lib/mt/Thread.h | 35 | ||||
| -rw-r--r-- | src/lib/mt/XMT.cpp | 4 | ||||
| -rw-r--r-- | src/lib/mt/XMT.h | 4 | ||||
| -rw-r--r-- | src/lib/mt/XThread.h | 14 |
12 files changed, 43 insertions, 92 deletions
diff --git a/src/lib/mt/CMakeLists.txt b/src/lib/mt/CMakeLists.txt index 9ee5ea4..19d1829 100644 --- a/src/lib/mt/CMakeLists.txt +++ b/src/lib/mt/CMakeLists.txt @@ -1,11 +1,11 @@ # barrier -- mouse and keyboard sharing utility # Copyright (C) 2012-2016 Symless Ltd. # Copyright (C) 2009 Nick Bolton -# +# # This package is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # found in the file LICENSE that should have accompanied this file. -# +# # This package is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/mt/CondVar.cpp b/src/lib/mt/CondVar.cpp index 11318f9..b9cf565 100644 --- a/src/lib/mt/CondVar.cpp +++ b/src/lib/mt/CondVar.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -24,7 +24,7 @@ // CondVarBase // -CondVarBase::CondVarBase(Mutex* mutex) : +CondVarBase::CondVarBase(Mutex* mutex) : m_mutex(mutex) { assert(m_mutex != NULL); diff --git a/src/lib/mt/CondVar.h b/src/lib/mt/CondVar.h index 0ab956b..fc18748 100644 --- a/src/lib/mt/CondVar.h +++ b/src/lib/mt/CondVar.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -78,7 +78,7 @@ public: signalled, otherwise up to \c timeout seconds or until signalled, whichever comes first. Returns true if the object was signalled during the wait, false otherwise. - + The proper way to wait for a condition is: \code cv.lock(); diff --git a/src/lib/mt/Lock.cpp b/src/lib/mt/Lock.cpp index 80721b9..6614858 100644 --- a/src/lib/mt/Lock.cpp +++ b/src/lib/mt/Lock.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/mt/Lock.h b/src/lib/mt/Lock.h index 4a3f311..e4bbacf 100644 --- a/src/lib/mt/Lock.h +++ b/src/lib/mt/Lock.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/mt/Mutex.cpp b/src/lib/mt/Mutex.cpp index e9a62e8..02d34c9 100644 --- a/src/lib/mt/Mutex.cpp +++ b/src/lib/mt/Mutex.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/mt/Mutex.h b/src/lib/mt/Mutex.h index 51a9649..53b8f45 100644 --- a/src/lib/mt/Mutex.h +++ b/src/lib/mt/Mutex.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/mt/Thread.cpp b/src/lib/mt/Thread.cpp index 7474c16..755c0e6 100644 --- a/src/lib/mt/Thread.cpp +++ b/src/lib/mt/Thread.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -28,12 +28,10 @@ // Thread // -Thread::Thread(IJob* job) +Thread::Thread(const std::function<void()>& fun) { - m_thread = ARCH->newThread(&Thread::threadFunc, job); + m_thread = ARCH->newThread([=](){ threadFunc(fun); }); if (m_thread == NULL) { - // couldn't create thread - delete job; throw XMTThreadUnavailable(); } } @@ -69,7 +67,7 @@ Thread::operator=(const Thread& thread) void Thread::exit(void* result) { - throw XThreadExit(result); + throw XThreadExit(); } void @@ -108,15 +106,6 @@ Thread::wait(double timeout) const return ARCH->wait(m_thread, timeout); } -void* -Thread::getResult() const -{ - if (wait()) - return ARCH->getResultOfThread(m_thread); - else - return NULL; -} - IArchMultithread::ThreadID Thread::getID() const { @@ -135,8 +124,7 @@ Thread::operator!=(const Thread& thread) const return !ARCH->isSameThread(m_thread, thread.m_thread); } -void* -Thread::threadFunc(void* vjob) +void Thread::threadFunc(const std::function<void()>& func) { // get this thread's id for logging IArchMultithread::ThreadID id; @@ -146,42 +134,26 @@ Thread::threadFunc(void* vjob) ARCH->closeThread(thread); } - // get job - IJob* job = static_cast<IJob*>(vjob); - - // run job - void* result = NULL; try { // go LOG((CLOG_DEBUG1 "thread 0x%08x entry", id)); - job->run(); + func(); LOG((CLOG_DEBUG1 "thread 0x%08x exit", id)); } catch (XThreadCancel&) { // client called cancel() LOG((CLOG_DEBUG1 "caught cancel on thread 0x%08x", id)); - delete job; throw; } - catch (XThreadExit& e) { - // client called exit() - result = e.m_result; - LOG((CLOG_DEBUG1 "caught exit on thread 0x%08x, result %p", id, result)); + catch (XThreadExit&) { + LOG((CLOG_DEBUG1 "caught exit on thread 0x%08x", id)); } catch (XBase& e) { LOG((CLOG_ERR "exception on thread 0x%08x: %s", id, e.what())); - delete job; throw; } catch (...) { LOG((CLOG_ERR "exception on thread 0x%08x: <unknown>", id)); - delete job; throw; } - - // done with job - delete job; - - // return exit result - return result; } diff --git a/src/lib/mt/Thread.h b/src/lib/mt/Thread.h index a7434fd..141d59f 100644 --- a/src/lib/mt/Thread.h +++ b/src/lib/mt/Thread.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -19,13 +19,12 @@ #pragma once #include "arch/IArchMultithread.h" - -class IJob; +#include <functional> //! Thread handle /*! Creating a Thread creates a new context of execution (i.e. thread) that -runs simulatenously with the calling thread. A Thread is only a handle +runs simultaneously with the calling thread. A Thread is only a handle to a thread; deleting a Thread does not cancel or destroy the thread it refers to and multiple Thread objects can refer to the same thread. @@ -44,10 +43,9 @@ class Thread { public: //! Run \c adoptedJob in a new thread /*! - Create and start a new thread executing the \c adoptedJob. The - new thread takes ownership of \c adoptedJob and will delete it. + Create and start a new thread executing the \c fun. */ - Thread(IJob* adoptedJob); + Thread(const std::function<void()>& fun); //! Duplicate a thread handle /*! @@ -79,8 +77,7 @@ public: /*! Terminate the calling thread. This function does not return but the stack is unwound and automatic objects are destroyed, as if - exit() threw an exception (which is, in fact, what it does). The - argument is saved as the result returned by getResult(). If you + exit() threw an exception (which is, in fact, what it does). If you have \c catch(...) blocks then you should add the following before each to avoid catching the exit: \code @@ -98,7 +95,7 @@ public: enabled. If cancellation is disabled then the cancel is remembered but not acted on until the first call to a cancellation point after cancellation is enabled. - + A cancellation point is a function that can act on cancellation. A cancellation point does not return if there's a cancel pending. Instead, it unwinds the stack and destroys automatic objects, as @@ -110,7 +107,7 @@ public: objects (like Lock). Clients are strongly encouraged to do the latter. During cancellation, further cancel() calls are ignored (i.e. a thread cannot be interrupted by a cancel during cancellation). - + Clients that \c catch(XThreadCancel) must always rethrow the exception. Clients that \c catch(...) must either rethrow the exception or include a \c catch(XThreadCancel) handler that @@ -122,7 +119,7 @@ public: /*! Change the priority of the thread. Normal priority is 0, 1 is the next lower, etc. -1 is the next higher, etc. but boosting - the priority may not be permitted and will be silenty ignored. + the priority may not be permitted and will be silently ignored. */ void setPriority(int n); @@ -167,16 +164,6 @@ public: */ 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 /*! Returns an integer id for this thread. This id must not be used to @@ -203,7 +190,7 @@ public: private: Thread(ArchThread); - static void* threadFunc(void*); + static void threadFunc(const std::function<void()>& func); private: ArchThread m_thread; diff --git a/src/lib/mt/XMT.cpp b/src/lib/mt/XMT.cpp index 2274a6b..2282d63 100644 --- a/src/lib/mt/XMT.cpp +++ b/src/lib/mt/XMT.cpp @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/mt/XMT.h b/src/lib/mt/XMT.h index 9e48fd9..ec4a683 100644 --- a/src/lib/mt/XMT.h +++ b/src/lib/mt/XMT.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/src/lib/mt/XThread.h b/src/lib/mt/XThread.h index acc32e3..41172b3 100644 --- a/src/lib/mt/XThread.h +++ b/src/lib/mt/XThread.h @@ -2,11 +2,11 @@ * barrier -- mouse and keyboard sharing utility * Copyright (C) 2012-2016 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -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 XThreadExit, XThread, or ...). */ -class XThreadExit : public XThread { -public: - //! \c result is the result of the thread - XThreadExit(void* result) : m_result(result) { } - ~XThreadExit() { } - -public: - void* m_result; -}; +class XThreadExit : public XThread {}; |
