Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/metal-cpp/Foundation/NSLock.hpp
21066 views
1
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
2
//
3
// Foundation/NSLock.hpp
4
//
5
// Copyright 2020-2024 Apple Inc.
6
//
7
// Licensed under the Apache License, Version 2.0 (the "License");
8
// you may not use this file except in compliance with the License.
9
// You may obtain a copy of the License at
10
//
11
// http://www.apache.org/licenses/LICENSE-2.0
12
//
13
// Unless required by applicable law or agreed to in writing, software
14
// distributed under the License is distributed on an "AS IS" BASIS,
15
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
// See the License for the specific language governing permissions and
17
// limitations under the License.
18
//
19
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
20
21
22
#pragma once
23
24
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
25
26
#include "NSDefines.hpp"
27
#include "NSObject.hpp"
28
#include "NSPrivate.hpp"
29
#include "NSTypes.hpp"
30
#include "NSDate.hpp"
31
32
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
33
34
namespace NS
35
{
36
37
template <class _Class, class _Base = class Object>
38
class Locking : public _Base
39
{
40
public:
41
void lock();
42
void unlock();
43
};
44
45
class Condition : public Locking<Condition>
46
{
47
public:
48
static Condition* alloc();
49
50
Condition* init();
51
52
void wait();
53
bool waitUntilDate(Date* pLimit);
54
void signal();
55
void broadcast();
56
};
57
58
} // NS
59
60
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
61
62
template<class _Class, class _Base /* = NS::Object */>
63
_NS_INLINE void NS::Locking<_Class, _Base>::lock()
64
{
65
NS::Object::sendMessage<void>(this, _NS_PRIVATE_SEL(lock));
66
}
67
68
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
69
70
template<class _Class, class _Base /* = NS::Object */>
71
_NS_INLINE void NS::Locking<_Class, _Base>::unlock()
72
{
73
NS::Object::sendMessage<void>(this, _NS_PRIVATE_SEL(unlock));
74
}
75
76
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
77
78
_NS_INLINE NS::Condition* NS::Condition::alloc()
79
{
80
return NS::Object::alloc<NS::Condition>(_NS_PRIVATE_CLS(NSCondition));
81
}
82
83
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
84
85
_NS_INLINE NS::Condition* NS::Condition::init()
86
{
87
return NS::Object::init<NS::Condition>();
88
}
89
90
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
91
92
_NS_INLINE void NS::Condition::wait()
93
{
94
NS::Object::sendMessage<void>(this, _NS_PRIVATE_SEL(wait));
95
}
96
97
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
98
99
_NS_INLINE bool NS::Condition::waitUntilDate(NS::Date* pLimit)
100
{
101
return NS::Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(waitUntilDate_), pLimit);
102
}
103
104
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
105
106
_NS_INLINE void NS::Condition::signal()
107
{
108
NS::Object::sendMessage<void>(this, _NS_PRIVATE_SEL(signal));
109
}
110
111
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
112
113
_NS_INLINE void NS::Condition::broadcast()
114
{
115
NS::Object::sendMessage<void>(this, _NS_PRIVATE_SEL(broadcast));
116
}
117
118
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
119