polar-objc 5.44
An Objective-C runtime library
Loading...
Searching...
No Matches
interfaces/polar-runtime-service-thread-sync.c
1/* Internal API: @synchronized() support service interface for polar-objc.
2 Copyright (C) 2022-2025 Michael Malicoat <[email protected]>
3
4 This file is part of polar-objc.
5
6 polar-objc is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
8
9 polar-objc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
10 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 details.
12
13 You should have received a copy of the GNU General Public License along with this program; see the file LICENSE. If
14 not, see <http://www.gnu.org/licenses/>.
15*/
16
17// Private =============================================================================================================
18
19enum
20{
21 POLAR_RTSQ_THREAD_SYNC_BEGIN = 0,
22 POLAR_RTSQ_THREAD_SYNC_END,
23
24 // Sentinel value
25 POLAR_RTSQ_THREAD_SYNC_LAST
26};
27
29{
30 intptr_t result;
31 void *object_target;
32};
33
35{
36 intptr_t result;
37 void *object_target;
38};
39
40// Public ==============================================================================================================
41
42// objc_sync_enter(object) => polar_runtime_thread_sync_begin(object)
43POLAR_FUNCTION_INTERNAL intptr_t
44polar_runtime_thread_sync_begin( void *object_target )
45{
46 struct polar_rtsq_thread_sync_begin request_data;
47
48 assert( object_target != NULL );
49 assert( thrd_current() != polar_id_rts_thread );
50
51 request_data.result = OBJC_THREAD_SYNC_FAILED;
52 request_data.object_target = object_target;
53
54 polar_runtime_service_request(POLAR_SERVICE_THREAD_SYNC, POLAR_RTSQ_THREAD_SYNC_BEGIN, &request_data);
55
56 return request_data.result;
57}
58
59// objc_sync_exit(object) => polar_runtime_thread_sync_end(object)
60POLAR_FUNCTION_INTERNAL intptr_t
61polar_runtime_thread_sync_end( void *object_target )
62{
63 struct polar_rtsq_thread_sync_end request_data;
64
65 assert( object_target != NULL );
66 assert( thrd_current() != polar_id_rts_thread );
67
68 request_data.result = OBJC_THREAD_SYNC_FAILED;
69 request_data.object_target = object_target;
70
71 polar_runtime_service_request(POLAR_SERVICE_THREAD_SYNC, POLAR_RTSQ_THREAD_SYNC_END, &request_data);
72
73 return request_data.result;
74}
static thrd_t thrd_current(void)
Definition polar-windows-platform-threading.h:134
Definition interfaces/polar-runtime-service-thread-sync.c:29
Definition interfaces/polar-runtime-service-thread-sync.c:35