diff options
| author | Jonathan "Geenz" Goodman <geenz@geenzo.com> | 2026-08-11 21:39:19 -0400 |
|---|---|---|
| committer | Jonathan "Geenz" Goodman <geenz@geenzo.com> | 2026-08-11 21:39:19 -0400 |
| commit | 8cabc33e960ca93fdc1a32c77cf611269d95d51b (patch) | |
| tree | 931fcecac10bf73214efa07cc3d704ba2bd01272 /indra/llcorehttp/_thread.h | |
| parent | 9b7ab49575b54523128952af6686d17eb6696725 (diff) | |
| parent | d045f9aa32789a35628aced166145c182751acbf (diff) | |
Merge remote-tracking branch 'origin/develop-linux' into geenz/linux-to-develop
Diffstat (limited to 'indra/llcorehttp/_thread.h')
| -rw-r--r-- | indra/llcorehttp/_thread.h | 103 |
1 files changed, 42 insertions, 61 deletions
diff --git a/indra/llcorehttp/_thread.h b/indra/llcorehttp/_thread.h index 93efbbedbc..66b9689c5a 100644 --- a/indra/llcorehttp/_thread.h +++ b/indra/llcorehttp/_thread.h @@ -29,94 +29,75 @@ #include "linden_common.h" -#include <boost/thread.hpp> -#include <boost/function.hpp> -#include <boost/date_time/posix_time/posix_time_types.hpp> +#include <functional> +#include <thread> -#include "apr.h" // thread-related functions #include "_refcounted.h" namespace LLCoreInt { -class HttpThread : public RefCounted +class HttpThread { -private: - // May not be default constructed or copied - HttpThread() = delete; - HttpThread(const HttpThread&) = delete; - void operator=(const HttpThread &) = delete; - - void at_exit() - { - // the thread function has exited so we need to release our reference - // to ourself so that we will be automagically cleaned up. - release(); - } +public: + HttpThread() = delete; // Not defined + HttpThread(const HttpThread&) = delete; // Not defined + void operator=(const HttpThread &) = delete; // Not defined +private: void run() - { // THREAD CONTEXT - - // Take out additional reference for the at_exit handler - addRef(); - boost::this_thread::at_thread_exit(boost::bind(&HttpThread::at_exit, this)); - - // run the thread function - mThreadFunc(this); - - } // THREAD CONTEXT - -protected: - virtual ~HttpThread() - { - delete mThread; - } + { // THREAD CONTEXT + // run the thread function + mThreadFunc(this); + } // THREAD CONTEXT public: /// Constructs a thread object for concurrent execution but does /// not start running. Caller receives on refcount on the thread /// instance. If the thread is started, another will be taken /// out for the exit handler. - explicit HttpThread(boost::function<void (HttpThread *)> threadFunc) - : RefCounted(true), // implicit reference - mThreadFunc(threadFunc) - { - // this creates a boost thread that will call HttpThread::run on this instance - // and pass it the threadfunc callable... - boost::function<void()> f = boost::bind(&HttpThread::run, this); + explicit HttpThread(std::function<void (HttpThread *)> threadFunc) + : mThreadFunc(threadFunc) + { + // this creates a std thread that will call HttpThread::run on this instance + // and pass it the threadfunc callable... + std::function<void()> f = std::bind(&HttpThread::run, this); - mThread = new boost::thread(f); - } + mThread = std::make_unique<std::thread>(f); + mNativeHandle = mThread->native_handle(); + } - inline void join() - { - mThread->join(); - } + ~HttpThread() = default; - inline bool timedJoin(S32 millis) - { - return mThread->timed_join(boost::posix_time::milliseconds(millis)); - } + inline void join() + { + mThread->join(); + } inline bool joinable() const - { - return mThread->joinable(); - } + { + return mThread->joinable(); + } + + inline void detach() + { + mThread->detach(); + } // A very hostile method to force a thread to quit inline void cancel() - { - boost::thread::native_handle_type thread(mThread->native_handle()); -#if LL_WINDOWS - TerminateThread(thread, 0); + { +#if LL_WINDOWS + TerminateThread(mNativeHandle, 0); #else - pthread_cancel(thread); + pthread_cancel(mNativeHandle); #endif - } + } private: - boost::function<void(HttpThread *)> mThreadFunc; - boost::thread * mThread; + std::function<void(HttpThread *)> mThreadFunc; + std::unique_ptr<std::thread> mThread; + std::thread::native_handle_type mNativeHandle; }; // end class HttpThread } // end namespace LLCoreInt |
