@@ -53,27 +53,39 @@ func CreateMutex() (*Mutex, error) {
53
53
return (* Mutex )(unsafe .Pointer (mutex )), nil
54
54
}
55
55
56
- // LockMutex locks a mutex created with CreateMutex().
56
+ // Lock locks a mutex created with CreateMutex().
57
57
// (https://wiki.libsdl.org/SDL_LockMutex)
58
- func LockMutex (mutex * Mutex ) int {
59
- return int (C .SDL_LockMutex (mutex .cptr ()))
58
+ func (mutex * Mutex ) Lock () error {
59
+ ret := int (C .SDL_LockMutex (mutex .cptr ()))
60
+ if ret != 0 {
61
+ return GetError ()
62
+ }
63
+ return nil
60
64
}
61
65
62
- // TryLockMutex tries to lock a mutex without blocking.
66
+ // TryLock tries to lock a mutex without blocking.
63
67
// (https://wiki.libsdl.org/SDL_TryLockMutex)
64
- func TryLockMutex (mutex * Mutex ) int {
65
- return int (C .SDL_TryLockMutex (mutex .cptr ()))
68
+ func (mutex * Mutex ) TryLock () error {
69
+ ret := int (C .SDL_TryLockMutex (mutex .cptr ()))
70
+ if ret != 0 {
71
+ return GetError ()
72
+ }
73
+ return nil
66
74
}
67
75
68
- // UnlockMutex unlocks a mutex created with CreateMutex().
76
+ // Unlock unlocks a mutex created with CreateMutex().
69
77
// (https://wiki.libsdl.org/SDL_UnlockMutex)
70
- func UnlockMutex (mutex * Mutex ) int {
71
- return int (C .SDL_UnlockMutex (mutex .cptr ()))
78
+ func (mutex * Mutex ) Unlock () error {
79
+ ret := int (C .SDL_UnlockMutex (mutex .cptr ()))
80
+ if ret != 0 {
81
+ return GetError ()
82
+ }
83
+ return nil
72
84
}
73
85
74
- // DestroyMutex destroys a mutex created with CreateMutex().
86
+ // Destroy destroys a mutex created with CreateMutex().
75
87
// (https://wiki.libsdl.org/SDL_DestroyMutex)
76
- func DestroyMutex (mutex * Mutex ) {
88
+ func (mutex * Mutex ) Destroy ( ) {
77
89
C .SDL_DestroyMutex (mutex .cptr ())
78
90
}
79
91
@@ -87,39 +99,55 @@ func CreateSemaphore(initialValue uint32) (*Sem, error) {
87
99
return (* Sem )(unsafe .Pointer (sem )), nil
88
100
}
89
101
90
- // DestroySemaphore destroys a semaphore.
102
+ // Destroy destroys a semaphore.
91
103
// (https://wiki.libsdl.org/SDL_DestroySemaphore)
92
- func DestroySemaphore (sem * Sem ) {
104
+ func (sem * Sem ) Destroy ( ) {
93
105
C .SDL_DestroySemaphore (sem .cptr ())
94
106
}
95
107
96
- // SemWait waits until a semaphore has a positive value and then decrements it.
108
+ // Wait waits until a semaphore has a positive value and then decrements it.
97
109
// (https://wiki.libsdl.org/SDL_SemWait)
98
- func SemWait (sem * Sem ) int {
99
- return int (C .SDL_SemWait (sem .cptr ()))
110
+ func (sem * Sem ) Wait () error {
111
+ ret := int (C .SDL_SemWait (sem .cptr ()))
112
+ if ret != 0 {
113
+ return GetError ()
114
+ }
115
+ return nil
100
116
}
101
117
102
- // SemTryWait sees if a semaphore has a positive value and decrement it if it does.
118
+ // TryWait sees if a semaphore has a positive value and decrement it if it does.
103
119
// (https://wiki.libsdl.org/SDL_SemTryWait)
104
- func SemTryWait (sem * Sem ) int {
105
- return int (C .SDL_SemTryWait (sem .cptr ()))
120
+ func (sem * Sem ) TryWait () error {
121
+ ret := int (C .SDL_SemTryWait (sem .cptr ()))
122
+ if ret != 0 {
123
+ return GetError ()
124
+ }
125
+ return nil
106
126
}
107
127
108
- // SemWaitTimeout waits until a semaphore has a positive value and then decrements it.
128
+ // WaitTimeout waits until a semaphore has a positive value and then decrements it.
109
129
// (https://wiki.libsdl.org/SDL_SemWaitTimeout)
110
- func SemWaitTimeout (sem * Sem , ms uint32 ) int {
111
- return int (C .SDL_SemWaitTimeout (sem .cptr (), C .Uint32 (ms )))
130
+ func (sem * Sem ) WaitTimeout (ms uint32 ) error {
131
+ ret := int (C .SDL_SemWaitTimeout (sem .cptr (), C .Uint32 (ms )))
132
+ if ret != 0 {
133
+ return GetError ()
134
+ }
135
+ return nil
112
136
}
113
137
114
- // SemPost atomically increments a semaphore's value and wake waiting threads.
138
+ // Post atomically increments a semaphore's value and wake waiting threads.
115
139
// (https://wiki.libsdl.org/SDL_SemPost)
116
- func SemPost (sem * Sem ) int {
117
- return int (C .SDL_SemPost (sem .cptr ()))
140
+ func (sem * Sem ) Post () error {
141
+ ret := int (C .SDL_SemPost (sem .cptr ()))
142
+ if ret != 0 {
143
+ return GetError ()
144
+ }
145
+ return nil
118
146
}
119
147
120
- // SemValue returns the current value of a semaphore.
148
+ // Value returns the current value of a semaphore.
121
149
// (https://wiki.libsdl.org/SDL_SemValue)
122
- func SemValue (sem * Sem ) uint32 {
150
+ func (sem * Sem ) Value ( ) uint32 {
123
151
return uint32 (C .SDL_SemValue (sem .cptr ()))
124
152
}
125
153
@@ -128,32 +156,48 @@ func CreateCond() *Cond {
128
156
return (* Cond )(unsafe .Pointer (C .SDL_CreateCond ()))
129
157
}
130
158
131
- // DestroyCond creates a condition variable.
159
+ // Destroy creates a condition variable.
132
160
// (https://wiki.libsdl.org/SDL_DestroyCond)
133
- func DestroyCond (cond * Cond ) {
161
+ func (cond * Cond ) Destroy ( ) {
134
162
C .SDL_DestroyCond (cond .cptr ())
135
163
}
136
164
137
- // CondSignal restarts one of the threads that are waiting on the condition variable.
165
+ // Signal restarts one of the threads that are waiting on the condition variable.
138
166
// (https://wiki.libsdl.org/SDL_CondSignal)
139
- func CondSignal (cond * Cond ) int {
140
- return int (C .SDL_CondSignal (cond .cptr ()))
167
+ func (cond * Cond ) Signal () error {
168
+ ret := int (C .SDL_CondSignal (cond .cptr ()))
169
+ if ret != 0 {
170
+ return GetError ()
171
+ }
172
+ return nil
141
173
}
142
174
143
- // CondBroadcast restarts all threads that are waiting on the condition variable.
175
+ // Broadcast restarts all threads that are waiting on the condition variable.
144
176
// (https://wiki.libsdl.org/SDL_CondBroadcast)
145
- func CondBroadcast (cond * Cond ) int {
146
- return int (C .SDL_CondBroadcast (cond .cptr ()))
177
+ func (cond * Cond ) Broadcast () error {
178
+ ret := int (C .SDL_CondBroadcast (cond .cptr ()))
179
+ if ret != 0 {
180
+ return GetError ()
181
+ }
182
+ return nil
147
183
}
148
184
149
- // CondWait waits until a condition variable is signaled.
185
+ // Wait waits until a condition variable is signaled.
150
186
// (https://wiki.libsdl.org/SDL_CondWait)
151
- func CondWait (cond * Cond , mutex * Mutex ) int {
152
- return int (C .SDL_CondWait (cond .cptr (), mutex .cptr ()))
187
+ func (cond * Cond ) Wait (mutex * Mutex ) error {
188
+ ret := int (C .SDL_CondWait (cond .cptr (), mutex .cptr ()))
189
+ if ret != 0 {
190
+ return GetError ()
191
+ }
192
+ return nil
153
193
}
154
194
155
- // CondWaitTimeout waits until a condition variable is signaled or a specified amount of time has passed.
195
+ // WaitTimeout waits until a condition variable is signaled or a specified amount of time has passed.
156
196
// (https://wiki.libsdl.org/SDL_CondWaitTimeout)
157
- func CondWaitTimeout (cond * Cond , mutex * Mutex , ms uint32 ) int {
158
- return int (C .SDL_CondWaitTimeout (cond .cptr (), mutex .cptr (), C .Uint32 (ms )))
197
+ func (cond * Cond ) WaitTimeout (mutex * Mutex , ms uint32 ) error {
198
+ ret := int (C .SDL_CondWaitTimeout (cond .cptr (), mutex .cptr (), C .Uint32 (ms )))
199
+ if ret != 0 {
200
+ return GetError ()
201
+ }
202
+ return nil
159
203
}
0 commit comments