CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
task_scheduler.h
1
2#pragma once
3
4#include <system/object.h>
5#include <system/collections/list.h>
6#include <functional>
7
8namespace System { namespace Threading { namespace Tasks {
9
11class ASPOSECPP_SHARED_CLASS TaskScheduler : public Object
12{
13 using ThisType = TaskScheduler;
14
15public:
18 static ASPOSECPP_SHARED_API const SharedPtr<TaskScheduler>& get_Default();
21 static ASPOSECPP_SHARED_API SharedPtr<TaskScheduler> get_Current();
24 virtual ASPOSECPP_SHARED_API int32_t get_MaximumConcurrencyLevel() const;
27 int32_t get_Id() const {return m_id;}
28
32
33protected:
35
36 friend Task;
37
38 ASPOSECPP_SHARED_API bool TryExecuteTask(const SharedPtr<Task>&);
39 virtual ASPOSECPP_SHARED_API bool TryExecuteTaskInline(const SharedPtr<Task>&, bool taskWasPreviouslyQueued) = 0;
40 virtual ASPOSECPP_SHARED_API void QueueTask(const SharedPtr<Task>&);
41 virtual ASPOSECPP_SHARED_API bool TryDequeue(const SharedPtr<Task>&);
42
43 int32_t m_id;
44
45 static int32_t m_next_id;
46 static thread_local Task* m_current_task;
47
49 std::recursive_mutex m_tasks_guard;
50};
51
53ASPOSECPP_SHARED_API void DispatchCurrentContext();
54
55}}} // namespace System::Threading::Tasks
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Represents an asynchronous operation that can be awaited and composed with other tasks.
Definition: task.h:29
Represents an object that handles the low-level work of queuing tasks onto threads.
Definition: task_scheduler.h:12
virtual int32_t get_MaximumConcurrencyLevel() const
Indicates the maximum concurrency level this TaskScheduler is able to support.
virtual void QueueTask(const SharedPtr< Task > &)
bool TryExecuteTask(const SharedPtr< Task > &)
virtual bool TryExecuteTaskInline(const SharedPtr< Task > &, bool taskWasPreviouslyQueued)=0
static int32_t m_next_id
Definition: task_scheduler.h:45
SharedPtr< Collections::Generic::List< TaskPtr > > m_tasks
Definition: task_scheduler.h:48
std::recursive_mutex m_tasks_guard
Definition: task_scheduler.h:49
static thread_local Task * m_current_task
Definition: task_scheduler.h:46
static const SharedPtr< TaskScheduler > & get_Default()
Gets the default TaskScheduler instance that is provided by the framework.
static SharedPtr< TaskScheduler > get_Current()
Gets the TaskScheduler associated with the currently executing task.
friend Task
Definition: task_scheduler.h:36
static SharedPtr< TaskScheduler > FromCurrentSynchronizationContext()
Creates a TaskScheduler associated with the current thread.
int32_t get_Id() const
Gets the unique ID for this TaskScheduler.
Definition: task_scheduler.h:27
int32_t m_id
Definition: task_scheduler.h:43
virtual bool TryDequeue(const SharedPtr< Task > &)
void DispatchCurrentContext()
Dispatches all tasks bound to this thread synchronously.
Definition: db_command.h:9