AsyncTaskRunner.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
10 #include <Bentley/Tasks/Tasks.h>
12 #include <thread>
13 #include <Bentley/BeAtomic.h>
14 #include <Bentley/WString.h>
16 
17 /*--------------------------------------------------------------------------------------+
18 * @bsiclass Bentley Systems
19 +---------------+---------------+---------------+---------------+---------------+------*/
21  {
22  private:
23  BeAtomic<bool> m_isRunning;
24  BeAtomic<bool> m_isStopping;
25 
26  std::weak_ptr<ITaskScheduler> m_scheduler;
27  std::shared_ptr<ITaskScheduler> m_schedulerToHoldWhileStopping;
28  std::shared_ptr<AsyncTask> m_currentRunningTask;
29 
30  Utf8String m_name;
31  intptr_t m_id;
32 
33  std::shared_ptr<ITaskRunner> m_thisPtr;
34 
35  protected:
36  void _Run ();
37 
38  BENTLEYDLL_EXPORT virtual void _RunAsyncTasksLoop ();
39 
40  BENTLEYDLL_EXPORT void SetCurrentRunningTask (std::shared_ptr<AsyncTask> task) { m_currentRunningTask = task; }
41 
43 
44  public:
45  BENTLEYDLL_EXPORT static std::shared_ptr<AsyncTaskRunner> Create ()
46  {
47  return std::shared_ptr <AsyncTaskRunner> (new AsyncTaskRunner());
48  }
49 
51 
52  // ITaskRunner implementation
53  BENTLEYDLL_EXPORT void Start (std::shared_ptr<ITaskScheduler> scheduler, Utf8CP name = nullptr) override;
54  BENTLEYDLL_EXPORT void Stop () override;
55  BENTLEYDLL_EXPORT void WakeUp() override;
56  BENTLEYDLL_EXPORT bool IsRunning () const override;
57  BENTLEYDLL_EXPORT bool IsStopping () const override;
58 
59  BENTLEYDLL_EXPORT intptr_t GetId () const override;
60 
61  BENTLEYDLL_EXPORT std::shared_ptr<AsyncTask> GetCurrentRunningTask () override;
62  BENTLEYDLL_EXPORT std::shared_ptr<ITaskScheduler> GetTaskScheduler () override;
63  };
64 
Contains a UTF-8 encoded string.
Definition: WString.h:275
#define BENTLEYDLL_EXPORT
Definition: Bentley.h:249
virtual bool IsStopping() const =0
Definition: ITaskRunner.h:21
virtual bool IsRunning() const =0
virtual intptr_t GetId() const =0
virtual void Start(std::shared_ptr< ITaskScheduler > scheduler, Utf8CP name=nullptr)=0
static std::shared_ptr< AsyncTaskRunner > Create()
Definition: AsyncTaskRunner.h:45
#define BEGIN_BENTLEY_TASKS_NAMESPACE
Definition: Tasks.h:13
Definition: AsyncTaskRunner.h:20
virtual std::shared_ptr< AsyncTask > GetCurrentRunningTask()=0
Utf8Char const * Utf8CP
Definition: Bentley.h:229
virtual std::shared_ptr< ITaskScheduler > GetTaskScheduler()=0
Provides Bentley specific implementation of the std::atomic template class (Bentley/BeAtomic.h).
#define END_BENTLEY_TASKS_NAMESPACE
Definition: Tasks.h:14
#define EXPORT_VTABLE_ATTRIBUTE
Definition: Bentley.h:67
void SetCurrentRunningTask(std::shared_ptr< AsyncTask > task)
Definition: AsyncTaskRunner.h:40

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.