From 74a7ed4bc17ba39319d933d26d3af018d6853d90 Mon Sep 17 00:00:00 2001 From: Galik Date: Tue, 18 Apr 2017 04:39:16 +0100 Subject: [PATCH] Applied clang-format -i -style=file -assume-filename=cpp include/gsl/gsl_thread --- include/gsl/gsl_thread | 154 +++++++++++++++++++++++++---------------- 1 file changed, 95 insertions(+), 59 deletions(-) diff --git a/include/gsl/gsl_thread b/include/gsl/gsl_thread index f3f760a..23cf928 100644 --- a/include/gsl/gsl_thread +++ b/include/gsl/gsl_thread @@ -22,15 +22,15 @@ #include #ifdef _MSC_VER - #pragma warning(push) +#pragma warning(push) - // turn off some warnings that are noisy about our Expects statements - #pragma warning(disable : 4127) // conditional expression is constant +// turn off some warnings that are noisy about our Expects statements +#pragma warning(disable : 4127) // conditional expression is constant - // blanket turn off warnings from CppCoreCheck for now - // so people aren't annoyed by them when running the tool. - // more targeted suppressions will be added in a future update to the GSL - #pragma warning(disable : 26481 26482 26483 26485 26490 26491 26492 26493 26495) +// blanket turn off warnings from CppCoreCheck for now +// so people aren't annoyed by them when running the tool. +// more targeted suppressions will be added in a future update to the GSL +#pragma warning(disable : 26481 26482 26483 26485 26490 26491 26492 26493 26495) #endif // _MSC_VER namespace gsl @@ -38,96 +38,132 @@ namespace gsl class detached_thread { - friend void swap(detached_thread& t1, detached_thread& t2) noexcept; + friend void swap(detached_thread& t1, detached_thread& t2) noexcept; public: - detached_thread() noexcept = default; + detached_thread() noexcept = default; - detached_thread(detached_thread const&) = delete; - detached_thread(detached_thread&& other): t(std::move(other.t)) {} + detached_thread(detached_thread const&) = delete; + detached_thread(detached_thread&& other) : t(std::move(other.t)) {} - detached_thread(std::thread const&) = delete; - detached_thread(std::thread&& other) noexcept: t(std::move(other)) { if(t.joinable()) t.detach(); } + detached_thread(std::thread const&) = delete; + detached_thread(std::thread&& other) noexcept : t(std::move(other)) + { + if (t.joinable()) t.detach(); + } - detached_thread& operator=(detached_thread const&) = delete; - detached_thread& operator=(detached_thread&& other) noexcept { t = std::move(other.t); return *this; } + detached_thread& operator=(detached_thread const&) = delete; + detached_thread& operator=(detached_thread&& other) noexcept + { + t = std::move(other.t); + return *this; + } - detached_thread& operator=(std::thread const&) = delete; - detached_thread& operator=(std::thread&& other) noexcept { t = std::move(other); if(t.joinable()) t.detach(); return *this; } + detached_thread& operator=(std::thread const&) = delete; + detached_thread& operator=(std::thread&& other) noexcept + { + t = std::move(other); + if (t.joinable()) t.detach(); + return *this; + } - template - explicit detached_thread(Callable&& f, Args&&... args) - : t(std::forward(f), std::forward(args)...) { t.detach(); } + template + explicit detached_thread(Callable&& f, Args&&... args) + : t(std::forward(f), std::forward(args)...) + { + t.detach(); + } - bool joinable() const { return t.joinable(); } + bool joinable() const { return t.joinable(); } - std::thread::id get_id() const noexcept { return t.get_id(); } + std::thread::id get_id() const noexcept { return t.get_id(); } - std::thread::native_handle_type native_handle() { return t.native_handle(); } + std::thread::native_handle_type native_handle() { return t.native_handle(); } - void join() { t.join(); } + void join() { t.join(); } - void swap(detached_thread& other) noexcept { using std::swap; swap(t, other.t); } + void swap(detached_thread& other) noexcept + { + using std::swap; + swap(t, other.t); + } private: - std::thread t; + std::thread t; }; void swap(detached_thread& t1, detached_thread& t2) noexcept { - using std::swap; - swap(t1.t, t2.t); + using std::swap; + swap(t1.t, t2.t); } class raii_thread { - friend void swap(raii_thread& t1, raii_thread& t2) noexcept; - + friend void swap(raii_thread& t1, raii_thread& t2) noexcept; + public: - raii_thread() noexcept = default; - - raii_thread(raii_thread const&) = delete; - raii_thread(raii_thread&& other): t(std::move(other.t)) {} + raii_thread() noexcept = default; - raii_thread(std::thread const&) = delete; - raii_thread(std::thread&& other) noexcept: t(std::move(other)) {} + raii_thread(raii_thread const&) = delete; + raii_thread(raii_thread&& other) : t(std::move(other.t)) {} - raii_thread& operator=(raii_thread const&) = delete; - raii_thread& operator=(raii_thread&& other) noexcept { t = std::move(other.t); return *this; } - - raii_thread& operator=(std::thread const&) = delete; - raii_thread& operator=(std::thread&& other) noexcept { t = std::move(other); return *this; } + raii_thread(std::thread const&) = delete; + raii_thread(std::thread&& other) noexcept : t(std::move(other)) {} - template - explicit raii_thread(Callable&& f, Args&&... args) - : t(std::forward(f), std::forward(args)...) {} + raii_thread& operator=(raii_thread const&) = delete; + raii_thread& operator=(raii_thread&& other) noexcept + { + t = std::move(other.t); + return *this; + } - ~raii_thread() { if(t.joinable()) t.join(); } - - bool joinable() const { return t.joinable(); } - - std::thread::id get_id() const noexcept { return t.get_id(); } - - std::thread::native_handle_type native_handle() { return t.native_handle(); } - - void join() { t.join(); } - - void swap(raii_thread& other) noexcept { using std::swap; swap(t, other.t); } + raii_thread& operator=(std::thread const&) = delete; + raii_thread& operator=(std::thread&& other) noexcept + { + t = std::move(other); + return *this; + } + + template + explicit raii_thread(Callable&& f, Args&&... args) + : t(std::forward(f), std::forward(args)...) + { + } + + ~raii_thread() + { + if (t.joinable()) t.join(); + } + + bool joinable() const { return t.joinable(); } + + std::thread::id get_id() const noexcept { return t.get_id(); } + + std::thread::native_handle_type native_handle() { return t.native_handle(); } + + void join() { t.join(); } + + void swap(raii_thread& other) noexcept + { + using std::swap; + swap(t, other.t); + } private: - std::thread t; + std::thread t; }; void swap(raii_thread& t1, raii_thread& t2) noexcept { - using std::swap; - swap(t1.t, t2.t); + using std::swap; + swap(t1.t, t2.t); } } // namespace gsl #ifdef _MSC_VER - #pragma warning(pop) +#pragma warning(pop) #endif // _MSC_VER #endif // GSL_THREAD_H