19#define POLAR_MSG_SERVICE_READY 0xFFFFFF51
20#define POLAR_MSG_SERVICE_SHUTDOWN 0xFFFFFF5F
45POLAR_FUNCTION_INTERNAL
void
46polar_runtime_service_thread_init_services(
void )
48 polar_func_internal_type_get_type service_get_type;
51 for( i = POLAR_ID_SERVICE_FIRST; i < POLAR_ID_SERVICE_LAST; i++ )
53 service_get_type = (polar_func_internal_type_get_type)polar_array_runtime_services[i];
54 polar_array_runtime_services[i] = (
polar_runtime_service *)polar_runtime_object_new( service_get_type() );
57 POLAR_DEBUG_FUNCTION_END;
61POLAR_FUNCTION_INTERNAL
void
62polar_runtime_service_thread_finalize_services(
void )
67 for( i = (POLAR_ID_SERVICE_LAST - 1); i > POLAR_ID_SERVICE_NONE; i-- )
71 if( service_current != NULL )
73 polar_runtime_object_free(service_current);
74 polar_array_runtime_services[i] = NULL;
78 POLAR_DEBUG_FUNCTION_END;
81OBJC_FUNCTION_HOTSPOT
void *
82polar_runtime_service_thread(
void *thread_entry_data OBJC_IGNORE_UNUSED )
85 uintptr_t id_service_desired, id_operation_desired;
88 polar_runtime_service_thread_init_services();
91 service_request = polar_thread_message_new(POLAR_MSG_SERVICE_READY, 0, NULL);
92 polar_thread_message_send(service_request, polar_inbox_main_thread);
95 service_request = polar_thread_message_queue_message_wait(polar_inbox_rts_thread);
96 while( service_request->subject_message != POLAR_MSG_SERVICE_SHUTDOWN )
99 id_service_desired = ( service_request->subject_message >> POLAR_SHIFT_SERVICE_REQUEST );
100 assert( id_service_desired > POLAR_ID_SERVICE_NONE );
101 assert( id_service_desired < POLAR_ID_SERVICE_LAST );
103 id_operation_desired = ( service_request->subject_message & POLAR_MASK_REQUEST_OPERATION );
105 polar_runtime_service_request_handle( polar_array_runtime_services[id_service_desired], id_operation_desired,
106 service_request, service_request->message_data );
109 service_request = polar_thread_message_queue_message_wait(polar_inbox_rts_thread);
116 polar_runtime_service_thread_finalize_services();
125POLAR_FUNCTION_INTERNAL intptr_t
126polar_runtime_service_thread_init(
void )
132 polar_inbox_main_thread = polar_thread_current_get_inbox();
135 polar_inbox_rts_thread = polar_thread_message_queue_new(polar_id_main_thread);
138 polar_thread_split( &polar_id_rts_thread, (polar_func_thread_enter)polar_runtime_service_thread, NULL,
139 polar_inbox_rts_thread );
141 if( polar_id_rts_thread != (
thrd_t) 0 )
148 message_service_thread_ready = polar_thread_message_queue_message_wait(polar_inbox_main_thread);
149 assert( message_service_thread_ready->subject_message == POLAR_MSG_SERVICE_READY );
153 POLAR_DEBUG_FUNCTION_END;
159POLAR_FUNCTION_INTERNAL
void
160polar_runtime_service_thread_finalize(
void )
164 if( polar_id_rts_thread != (
thrd_t)0 )
167 message_service_thread_shutdown = polar_thread_message_new(POLAR_MSG_SERVICE_SHUTDOWN, 0, NULL);
168 polar_thread_message_send(message_service_thread_shutdown, polar_inbox_rts_thread);
174 POLAR_DEBUG_FUNCTION_END;
Definition polar-runtime-object.h:31
Definition polar-runtime-service.h:28
Definition polar-thread-message-queue.h:23
Definition polar-thread-message.h:25