1 // Copyright 2021 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DAWNNATIVE_CALLBACK_TASK_MANAGER_H_
16 #define DAWNNATIVE_CALLBACK_TASK_MANAGER_H_
17 
18 #include <memory>
19 #include <mutex>
20 #include <vector>
21 
22 namespace dawn_native {
23 
24     struct CallbackTask {
25       public:
26         virtual ~CallbackTask() = default;
27         virtual void Finish() = 0;
28         virtual void HandleShutDown() = 0;
29         virtual void HandleDeviceLoss() = 0;
30     };
31 
32     class CallbackTaskManager {
33       public:
34         void AddCallbackTask(std::unique_ptr<CallbackTask> callbackTask);
35         bool IsEmpty();
36         std::vector<std::unique_ptr<CallbackTask>> AcquireCallbackTasks();
37 
38       private:
39         std::mutex mCallbackTaskQueueMutex;
40         std::vector<std::unique_ptr<CallbackTask>> mCallbackTaskQueue;
41     };
42 
43 }  // namespace dawn_native
44 
45 #endif
46