• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The SwiftShader Authors. All Rights Reserved.
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 VK_EVENT_HPP_
16 #define VK_EVENT_HPP_
17 
18 #include "VkObject.hpp"
19 
20 #include "marl/mutex.h"
21 #include "marl/tsa.h"
22 
23 #include <condition_variable>
24 
25 namespace vk {
26 
27 class Event : public Object<Event, VkEvent>
28 {
29 public:
Event(const VkEventCreateInfo * pCreateInfo,void * mem)30 	Event(const VkEventCreateInfo *pCreateInfo, void *mem)
31 	{
32 	}
33 
ComputeRequiredAllocationSize(const VkEventCreateInfo * pCreateInfo)34 	static size_t ComputeRequiredAllocationSize(const VkEventCreateInfo *pCreateInfo)
35 	{
36 		return 0;
37 	}
38 
signal()39 	void signal()
40 	{
41 		{
42 			marl::lock lock(mutex);
43 			status = VK_EVENT_SET;
44 		}
45 		condition.notify_all();
46 	}
47 
reset()48 	void reset()
49 	{
50 		marl::lock lock(mutex);
51 		status = VK_EVENT_RESET;
52 	}
53 
getStatus()54 	VkResult getStatus()
55 	{
56 		marl::lock lock(mutex);
57 		auto result = status;
58 		return result;
59 	}
60 
wait()61 	void wait()
62 	{
63 		marl::lock lock(mutex);
64 		lock.wait(condition, [this]() REQUIRES(mutex) { return status == VK_EVENT_SET; });
65 	}
66 
67 private:
68 	marl::mutex mutex;
69 	VkResult status GUARDED_BY(mutex) = VK_EVENT_RESET;
70 	std::condition_variable condition;
71 };
72 
Cast(VkEvent object)73 static inline Event *Cast(VkEvent object)
74 {
75 	return Event::Cast(object);
76 }
77 
78 }  // namespace vk
79 
80 #endif  // VK_EVENT_HPP_
81