CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
thread.h
1
2#ifndef _aspose_system_threading_thread_h_
3#define _aspose_system_threading_thread_h_
4
5#include <thread>
6#include <mutex>
7#include <condition_variable>
8
9#include <system/multicast_delegate.h>
10#include <system/globalization/culture_info.h>
11#include <system/threading/thread_state.h>
12
13
14
15namespace System {
16
17 namespace ComponentModel {
18 class BackgroundWorker;
19 }
20
21 namespace Threading {
22
24using ParameterizedThreadStart = System::MulticastDelegate<void(System::SharedPtr<System::Object>)>;
26using ThreadStart = System::MulticastDelegate<void()>;
27
57class ASPOSECPP_SHARED_CLASS Thread final: public System::Object
58{
60 friend class ThreadPoolImpl;
62
63public:
65 ASPOSECPP_SHARED_API Thread();
68 ASPOSECPP_SHARED_API Thread(ThreadStart thread_function);
71 ASPOSECPP_SHARED_API Thread(ParameterizedThreadStart thread_function);
72
76 ASPOSECPP_SHARED_API Thread & operator = (const Thread &t);
79 ASPOSECPP_SHARED_API Thread(Thread &t);
81 virtual ASPOSECPP_SHARED_API ~Thread();
82
88 ASPOSECPP_SHARED_API void set_CurrentCulture(const SharedPtr<Globalization::CultureInfo>& ci);
89
92 static ASPOSECPP_SHARED_API System::SharedPtr<Thread> get_CurrentThread();
93
98 ASPOSECPP_SHARED_API void set_CurrentUICulture(const SharedPtr<Globalization::CultureInfo>& ci);
99
102 ASPOSECPP_SHARED_API bool get_IsAlive();
105 ASPOSECPP_SHARED_API bool get_IsBackground();
108 ASPOSECPP_SHARED_API void set_IsBackground(bool is_background);
111 ASPOSECPP_SHARED_API bool get_IsThreadPoolThread();
114 ASPOSECPP_SHARED_API int get_ManagedThreadId() const;
117 ASPOSECPP_SHARED_API System::String get_Name();
120 ASPOSECPP_SHARED_API void set_Name(const System::String& name);
121
124 ASPOSECPP_SHARED_API ThreadState get_ThreadState();
125
127 ASPOSECPP_SHARED_API void Join();
131 ASPOSECPP_SHARED_API bool Join(int millisecondsTimeout);
135 ASPOSECPP_SHARED_API bool Join(TimeSpan timeout);
138 static ASPOSECPP_SHARED_API void Sleep(int millisecondsTimeout);
141 static ASPOSECPP_SHARED_API void Sleep(TimeSpan timeout);
144 static ASPOSECPP_SHARED_API void SpinWait(int iterations);
145
147 ASPOSECPP_SHARED_API void Start();
150 ASPOSECPP_SHARED_API void Start(const System::SharedPtr<System::Object>& o);
152 ASPOSECPP_SHARED_API void Abort();
154 ASPOSECPP_SHARED_API void Interrupt();
156 static ASPOSECPP_SHARED_API bool Yield();
157
160 static ASPOSECPP_SHARED_API int GetCurrentThreadId();
161
163 virtual ASPOSECPP_SHARED_API int GetHashCode() const override;
164
166 static ASPOSECPP_SHARED_API void MemoryBarrier();
167
168private:
170 struct TlsData
171 {
173 System::String name;
175 ThreadState state = Unstarted;
177 bool is_backgroung = false;
179 bool is_thread_pool_thread = false;
180 // Whether the thread is ready
181 bool is_ready = false;
183 std::timed_mutex m_timed_mutex;
185 std::condition_variable m_cv_sleep;
187 std::mutex m_mtx_cv_sleep;
189 int m_thread_id;
191 TlsData();
192 };
193
195 bool m_is_pts;
199 ThreadStart m_ts;
201 std::thread m_thread;
203 static std::shared_ptr<TlsData>& GetTlsData();
205 std::shared_ptr<TlsData> m_data;
206
208 static void StartHelper(const SharedPtr<Thread>& thread, const ThreadStart& worker);
209
213 static ASPOSECPP_SHARED_API void CheckIsValidTimeout(TimeSpan timeout);
214
216 static ASPOSECPP_SHARED_API void InitTlsData();
217};
218
219}} // namespace System::Threading
220
221#endif // _aspose_system_threading_thread_h_
Objects of this class should only be allocated using System::MakeObject() function....
Definition: background_worker.h:20
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
Object & operator=(Object const &x)
Assignment operator. Doesn't copy anything, really, just initializes new object and enables copy cons...
Definition: object.h:81
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:122
Thread implementation. Objects of this class should only be allocated using System::MakeObject() func...
Definition: thread.h:58
static void Sleep(TimeSpan timeout)
Stops current thread for specified timeout.
bool Join(TimeSpan timeout)
Joins managed thread. Performs limited waiting.
void Abort()
Aborts thread. Not implemented.
static System::SharedPtr< Thread > get_CurrentThread()
Gets object which describes current thread.
bool Join(int millisecondsTimeout)
Joins managed thread. Performs limited waiting.
static void Sleep(int millisecondsTimeout)
Stops current thread for specified timeout.
void set_Name(const System::String &name)
Sets thread name.
ThreadState get_ThreadState()
Gets thread state.
Thread(ParameterizedThreadStart thread_function)
Constructor.
void set_CurrentCulture(const SharedPtr< Globalization::CultureInfo > &ci)
Sets thread culture.
bool get_IsBackground()
Checks whether thread is background.
static int GetCurrentThreadId()
Gets identifier of current thread.
virtual ~Thread()
Destructor.
System::String get_Name()
Gets thread name.
int get_ManagedThreadId() const
Gets identifier of thread. Can be got from OS, but if OS thread identifier exceeds int limits,...
static void MemoryBarrier()
Synchronizes memory access.
virtual int GetHashCode() const override
Thread(ThreadStart thread_function)
Constructor.
void Join()
Joins managed thread. Performs unlimited waiting if required.
void Start(const System::SharedPtr< System::Object > &o)
Starts thread.
bool get_IsThreadPoolThread()
Checks if thread is owned by a thread pool.
void set_CurrentUICulture(const SharedPtr< Globalization::CultureInfo > &ci)
Sets user interface culture used by thread.
static void SpinWait(int iterations)
Waits for specific number of loop iterations.
static bool Yield()
Yields thread.
SharedPtr< Globalization::CultureInfo > get_CurrentUICulture()
Gets user interface culture used by thread.
SharedPtr< Globalization::CultureInfo > get_CurrentCulture()
Gets thread culture.
void Interrupt()
Interrupt thread. Not implemented.
void set_IsBackground(bool is_background)
Sets thread to background or foreground.
Thread(Thread &t)
Copy constructor.
bool get_IsAlive()
Checks whether thread is alive.
void Start()
Starts thread using null argument object.
Thread pool internal data. This is a singleton type with memory management done by access function(s)...
Definition: thread_pool.h:23
Represents a time interval. This type should be allocated on stack and passed to functions by value o...
Definition: timespan.h:59
System::MulticastDelegate< void(System::SharedPtr< System::Object >)> ParameterizedThreadStart
Thread function with single parameter.
Definition: thread.h:24
System::MulticastDelegate< void()> ThreadStart
Thread function with no parameters.
Definition: thread.h:26
ThreadState
State of the thread.
Definition: thread_state.h:9
@ Unstarted
Thread is not started.
Definition: thread_state.h:19
Definition: db_command.h:9