polar-objc 5.44
An Objective-C runtime library
Loading...
Searching...
No Matches
polar-runtime-service-thread.h
1/* Internal API: runtime service thread 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#ifndef POLAR_RUNTIME_SERVICE_THREAD_H
17#define POLAR_RUNTIME_SERVICE_THREAD_H
18
19/* Client threads request the services of the runtime service thread by passing a message with a subject that indicates
20 the desired service and the desired operation. This is all handled transparently for client threads by the various
21 runtime service interfaces provided in "source/polar-internals/runtime-service/interfaces".
22
23 The service desired of the runtime service thread is indicated using one of the enumerated values below. The desired
24 operation will be one of the values enumerated in the corresponding service inteface file.
25
26 When compiling in debug mode, there are some assertions in place to validate that the service identifier and
27 operation identifier are within the defined ranges. If you are adding a service or operation, it is advisable to test
28 the addition in debug mode first.
29*/
30
31// These are the services offered by the runtime service thread
32enum
33{
34 POLAR_ID_SERVICE_NONE = 0,
35
36 POLAR_ID_SERVICE_DISPATCH, // Dispatch array management
37 POLAR_ID_SERVICE_MEMORY_DISPOSAL, // Threaded memory disposal
38 POLAR_ID_SERVICE_MODULE, // Compiled module management
39 POLAR_ID_SERVICE_SELECTOR, // Selector registration and management
40 POLAR_ID_SERVICE_THREAD_SYNC, // @synchronized() support
41 POLAR_ID_SERVICE_TYPE_REGISTRY, // Class and Protocol registration
42 POLAR_ID_SERVICE_TYPE_WORK, // Class and Protocol manipulation
43
44 // Sentinel value
45 POLAR_ID_SERVICE_LAST
46};
47
48#define POLAR_ID_SERVICE_FIRST ( POLAR_ID_SERVICE_NONE + 1 )
49
50#define POLAR_MASK_REQUEST_SERVICE 0xFF00
51#define POLAR_MASK_REQUEST_OPERATION 0xFF
52#define POLAR_SHIFT_SERVICE_REQUEST 8
53
54#define POLAR_SERVICE_DISPATCH ( polar_array_runtime_services[POLAR_ID_SERVICE_DISPATCH] )
55#define POLAR_SERVICE_MEMORY_DISPOSAL ( polar_array_runtime_services[POLAR_ID_SERVICE_MEMORY_DISPOSAL] )
56#define POLAR_SERVICE_MODULE ( polar_array_runtime_services[POLAR_ID_SERVICE_MODULE] )
57#define POLAR_SERVICE_SELECTOR ( polar_array_runtime_services[POLAR_ID_SERVICE_SELECTOR] )
58#define POLAR_SERVICE_THREAD_SYNC ( polar_array_runtime_services[POLAR_ID_SERVICE_THREAD_SYNC] )
59#define POLAR_SERVICE_TYPE_REGISTRY ( polar_array_runtime_services[POLAR_ID_SERVICE_TYPE_REGISTRY] )
60#define POLAR_SERVICE_TYPE_WORK ( polar_array_runtime_services[POLAR_ID_SERVICE_TYPE_WORK] )
61
62/* Array of runtime service singleton objects; initialized in the context of the runtime service thread and constant
63 thereafter.
64*/
65extern polar_runtime_service *polar_array_runtime_services[ POLAR_ID_SERVICE_LAST ];
66
67// These variables are all initialized in polar_runtime_service_thread_init()
68extern thrd_t polar_id_main_thread; // Platform ID of the main thread
69extern thrd_t polar_id_rts_thread; // Platform ID of the runtime service thread
70extern polar_thread_message_queue *polar_inbox_rts_thread; // Message queue for the runtime service thread
71
72// Called by polar_init()
73POLAR_FUNCTION_INTERNAL intptr_t
74polar_runtime_service_thread_init( void );
75
76// Called by polar_finalize()
77POLAR_FUNCTION_INTERNAL void
78polar_runtime_service_thread_finalize( void );
79
80#endif //POLAR_RUNTIME_SERVICE_THREAD_H
DWORD thrd_t
Definition polar-windows-platform-threading.h:111
Definition polar-runtime-service.h:28
Definition polar-thread-message-queue.h:23