Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
ThreadingError.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4
5#include "../Common/Result.h"
6
7namespace SC
8{
11
13enum class ThreadingError : uint32_t
14{
15 InvalidThreadFunction = 1,
16 ThreadAlreadyStarted,
17 ThreadNotStarted,
18 ThreadCreationFailed,
19 ThreadJoinFailed,
20 ThreadDetachFailed,
21 ThreadPoolAlreadyCreated,
22 InvalidWorkerThreadCount,
23 ThreadPoolNotCreated,
24 TaskAlreadyQueued,
25 TaskInUseByAnotherThreadPool,
26 ThreadPoolThreadCreationFailed,
27};
28
30enum class ThreadingErrorDetail : uint32_t
31{
32 None = 0,
33 PosixPthreadCreate,
34 PosixPthreadJoin,
35 PosixPthreadDetach,
36 WindowsCreateThread,
37 WindowsWaitForSingleObject,
38 WindowsCloseHandle,
39};
40
42static constexpr ResultCategory ThreadingResultCategory = ResultCategory(1);
43
48struct [[nodiscard]] ResultThreading
49{
50 Result result;
51 uint32_t nativeError = 0;
52 ThreadingErrorDetail detail = ThreadingErrorDetail::None;
53
54 explicit constexpr ResultThreading(bool valid = true) : result(valid) {}
55 constexpr ResultThreading(ThreadingError error, ThreadingErrorDetail detail = ThreadingErrorDetail::None,
56 uint32_t nativeError = 0)
57 : result(Result::Error(ThreadingResultCategory, error)), nativeError(nativeError), detail(detail)
58 {}
59 constexpr ResultThreading(Result result) : result(result) {}
60
61 template <typename ResultLike>
62 constexpr ResultThreading(const ResultLike& other) : result(other.toResult())
63 {}
64
65 explicit constexpr operator bool() const { return static_cast<bool>(result); }
66
67 constexpr operator Result() const { return result; }
68
69 constexpr Result toResult() const { return result; }
70 constexpr bool isError(ThreadingError error) const { return result.isError(ThreadingResultCategory, error); }
71};
72
74} // namespace SC
ThreadingErrorDetail
Stable detail identifying the native/backend stage of a Threading failure.
Definition ThreadingError.h:31
ThreadingError
Stable error codes returned by the Threading library.
Definition ThreadingError.h:14
Threading result retaining optional native and backend-stage details.
Definition ThreadingError.h:49