1 /*************************************************************************/
2 /* rw_lock_windows.cpp */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /*************************************************************************/
30
31 #if defined(WINDOWS_ENABLED)
32
33 #include "rw_lock_windows.h"
34
35 #include "core/error_macros.h"
36 #include "core/os/memory.h"
37
38 #include <stdio.h>
39
read_lock()40 void RWLockWindows::read_lock() {
41
42 AcquireSRWLockShared(&lock);
43 }
44
read_unlock()45 void RWLockWindows::read_unlock() {
46
47 ReleaseSRWLockShared(&lock);
48 }
49
read_try_lock()50 Error RWLockWindows::read_try_lock() {
51
52 if (TryAcquireSRWLockShared(&lock) == 0) {
53 return ERR_BUSY;
54 } else {
55 return OK;
56 }
57 }
58
write_lock()59 void RWLockWindows::write_lock() {
60
61 AcquireSRWLockExclusive(&lock);
62 }
63
write_unlock()64 void RWLockWindows::write_unlock() {
65
66 ReleaseSRWLockExclusive(&lock);
67 }
68
write_try_lock()69 Error RWLockWindows::write_try_lock() {
70 if (TryAcquireSRWLockExclusive(&lock) == 0) {
71 return ERR_BUSY;
72 } else {
73 return OK;
74 }
75 }
76
create_func_windows()77 RWLock *RWLockWindows::create_func_windows() {
78
79 return memnew(RWLockWindows);
80 }
81
make_default()82 void RWLockWindows::make_default() {
83
84 create_func = create_func_windows;
85 }
86
RWLockWindows()87 RWLockWindows::RWLockWindows() {
88
89 InitializeSRWLock(&lock);
90 }
91
~RWLockWindows()92 RWLockWindows::~RWLockWindows() {
93 }
94
95 #endif
96