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#ifdef Yield
14#undef Yield
15#endif
16
17#ifdef MemoryBarrier
18#undef MemoryBarrier
19#endif
20
21namespace System {
22
23 namespace ComponentModel {
24 class BackgroundWorker;
25 }
26
27 namespace Threading {
28
30using ParameterizedThreadStart = System::MulticastDelegate<void(System::SharedPtr<System::Object>)>;
32using ThreadStart = System::MulticastDelegate<void()>;
33
63class ASPOSECPP_SHARED_CLASS Thread final: public System::Object
64{
66 friend class ThreadPoolImpl;
68
69public:
71 ASPOSECPP_SHARED_API Thread();
74 ASPOSECPP_SHARED_API Thread(ThreadStart thread_function);
77 ASPOSECPP_SHARED_API Thread(ParameterizedThreadStart thread_function);
78
82 ASPOSECPP_SHARED_API Thread & operator = (const Thread &t);
85 ASPOSECPP_SHARED_API Thread(Thread &t);
87 virtual ASPOSECPP_SHARED_API ~Thread();
88
94 ASPOSECPP_SHARED_API void set_CurrentCulture(const SharedPtr<Globalization::CultureInfo>& ci);
95
98 static ASPOSECPP_SHARED_API System::SharedPtr<Thread> get_CurrentThread();
99
105
108 ASPOSECPP_SHARED_API bool get_IsAlive();
111 ASPOSECPP_SHARED_API bool get_IsBackground();
114 ASPOSECPP_SHARED_API void set_IsBackground(bool is_background);
117 ASPOSECPP_SHARED_API bool get_IsThreadPoolThread();
120 ASPOSECPP_SHARED_API int get_ManagedThreadId() const;
123 ASPOSECPP_SHARED_API System::String get_Name();
126 ASPOSECPP_SHARED_API void set_Name(const System::String& name);
127
130 ASPOSECPP_SHARED_API ThreadState get_ThreadState();
131
133 ASPOSECPP_SHARED_API void Join();
137 ASPOSECPP_SHARED_API bool Join(int millisecondsTimeout);
141 ASPOSECPP_SHARED_API bool Join(TimeSpan timeout);
144 static ASPOSECPP_SHARED_API void Sleep(int millisecondsTimeout);
147 static ASPOSECPP_SHARED_API void Sleep(TimeSpan timeout);
150 static ASPOSECPP_SHARED_API void SpinWait(int iterations);
151
153 ASPOSECPP_SHARED_API void Start();
156 ASPOSECPP_SHARED_API void Start(const System::SharedPtr<System::Object>& o);
158 ASPOSECPP_SHARED_API void Abort();
160 ASPOSECPP_SHARED_API void Interrupt();
162 static ASPOSECPP_SHARED_API bool Yield();
163
166 static ASPOSECPP_SHARED_API int GetCurrentThreadId();
167
169 virtual ASPOSECPP_SHARED_API int GetHashCode() const override;
170
172 static ASPOSECPP_SHARED_API void MemoryBarrier();
173
174private:
176 struct TlsData
177 {
179 System::String name;
181 ThreadState state = Unstarted;
183 bool is_backgroung = false;
185 bool is_thread_pool_thread = false;
186 // Whether the thread is ready
187 bool is_ready = false;
189 std::timed_mutex m_timed_mutex;
191 std::condition_variable m_cv_sleep;
193 std::mutex m_mtx_cv_sleep;
195 int m_thread_id;
197 TlsData();
198 };
199
201 bool m_is_pts;
205 ThreadStart m_ts;
207 std::thread m_thread;
209 static std::shared_ptr<TlsData>& GetTlsData();
211 std::shared_ptr<TlsData> m_data;
212
214 static void StartHelper(const SharedPtr<Thread>& thread, const ThreadStart& worker);
215
219 static ASPOSECPP_SHARED_API void CheckIsValidTimeout(TimeSpan timeout);
220
222 static ASPOSECPP_SHARED_API void InitTlsData();
223};
224
225}} // namespace System::Threading
226
227#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:51
Object & operator=(Object const &x)
Assignment operator. Doesn't copy anything, really, just initializes new object and enables copy cons...
Definition: object.h:70
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:126
Thread implementation. Objects of this class should only be allocated using System::MakeObject() func...
Definition: thread.h:64
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:30
System::MulticastDelegate< void()> ThreadStart
Thread function with no parameters.
Definition: thread.h:32
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