diff --git a/dap-sdk/net/core/dap_events.c b/dap-sdk/net/core/dap_events.c index d8bf479eff2148f637eafcdf4b9c02ce07398ba7..3d52786e16258bb51f715bc45288b21da1e3df54 100644 --- a/dap-sdk/net/core/dap_events.c +++ b/dap-sdk/net/core/dap_events.c @@ -98,7 +98,7 @@ typedef cpuset_t cpu_set_t; // Adopt BSD CPU setstructure to POSIX variant #define LOG_TAG "dap_events" -static bool s_workers_init = false; +static int s_workers_init = 0; static uint32_t s_threads_count = 1; static dap_worker_t **s_workers = NULL; static dap_thread_t *s_threads = NULL; @@ -214,15 +214,16 @@ int dap_events_init( uint32_t a_threads_count, size_t a_conn_timeout ) if ( !s_workers || !s_threads ) return -1; - s_workers_init = true; - dap_worker_init(a_conn_timeout); if ( dap_events_socket_init() != 0 ) { log_it( L_CRITICAL, "Can't init client submodule dap_events_socket_init( )" ); goto err; } + log_it( L_NOTICE, "Initialized event socket reactor for %u threads", s_threads_count ); + s_workers_init = 1; + return 0; err: @@ -246,6 +247,8 @@ void dap_events_deinit( ) if ( s_workers ) DAP_DELETE( s_workers ); + + s_workers_init = 0; } /** @@ -313,6 +316,9 @@ void dap_events_remove_and_delete_socket_unsafe(dap_events_t *a_events, dap_even int dap_events_start( dap_events_t *a_events ) { + if ( !s_workers_init ) + log_it(L_CRITICAL, "Event socket reactor has not been fired, use dap_events_init() first"); + for( uint32_t i = 0; i < s_threads_count; i++) { dap_worker_t * l_worker = DAP_NEW_Z(dap_worker_t); @@ -413,6 +419,9 @@ int dap_events_wait( dap_events_t *a_events ) */ void dap_events_stop_all( ) { + if ( !s_workers_init ) + log_it(L_CRITICAL, "Event socket reactor has not been fired, use dap_events_init() first"); + for( uint32_t i = 0; i < s_threads_count; i ++ ) { dap_events_socket_event_signal( s_workers[i]->event_exit, 1); } @@ -427,12 +436,13 @@ void dap_events_stop_all( ) uint32_t dap_events_worker_get_index_min( ) { uint32_t min = 0; - uint32_t i; - for( i = 1; i < s_threads_count; i++ ) { + if ( !s_workers_init ) + log_it(L_CRITICAL, "Event socket reactor has not been fired, use dap_events_init() first"); - if ( s_workers[min]->event_sockets_count > s_workers[i]->event_sockets_count ) - min = i; + for( int i = 1; i < s_threads_count; i++ ) { + if ( s_workers[min]->event_sockets_count > s_workers[i]->event_sockets_count ) + min = i; } return min; @@ -449,6 +459,9 @@ uint32_t dap_events_worker_get_count() */ dap_worker_t *dap_events_worker_get_auto( ) { + if ( !s_workers_init ) + log_it(L_CRITICAL, "Event socket reactor has not been fired, use dap_events_init() first"); + return s_workers[dap_events_worker_get_index_min()]; } @@ -459,6 +472,9 @@ dap_worker_t *dap_events_worker_get_auto( ) */ dap_worker_t * dap_events_worker_get(uint8_t a_index) { + if ( !s_workers_init ) + log_it(L_CRITICAL, "Event socket reactor has not been fired, use dap_events_init() first"); + return (a_index < s_threads_count) ? s_workers[a_index] : NULL; } @@ -467,9 +483,10 @@ dap_worker_t * dap_events_worker_get(uint8_t a_index) */ void dap_events_worker_print_all( ) { + if ( !s_workers_init ) + log_it(L_CRITICAL, "Event socket reactor has not been fired, use dap_events_init() first"); for( int i = 0; i < s_threads_count; i ++ ) { - log_it( L_INFO, "Worker: %d, count open connections: %d", - s_workers[i]->id, s_workers[i]->event_sockets_count ); + log_it( L_INFO, "Worker: %d, count open connections: %d", s_workers[i]->id, s_workers[i]->event_sockets_count ); } } diff --git a/dap-sdk/net/core/include/dap_proc_queue.h b/dap-sdk/net/core/include/dap_proc_queue.h index 09800fb3c37216239968c26dd7b07591b06274cb..f3e6635c2a769733bdb56dc49a3a1e5e93004b7a 100644 --- a/dap-sdk/net/core/include/dap_proc_queue.h +++ b/dap-sdk/net/core/include/dap_proc_queue.h @@ -25,7 +25,7 @@ typedef struct dap_proc_thread dap_proc_thread_t; -typedef bool (*dap_proc_queue_callback_t)(dap_proc_thread_t*,void* ); // Callback for processor. Returns true if +typedef int (*dap_proc_queue_callback_t)(dap_proc_thread_t*,void* ); // Callback for processor. Returns true if // we want to stop callback execution and // not to go on next loop enum { diff --git a/dap-sdk/net/core/include/dap_worker.h b/dap-sdk/net/core/include/dap_worker.h index 5dcdf6851ffc6430af3ea93d7ae29304b7f72b5f..62ad3b0e67877fcefaafe1dece209dd923e18dd8 100644 --- a/dap-sdk/net/core/include/dap_worker.h +++ b/dap-sdk/net/core/include/dap_worker.h @@ -38,7 +38,7 @@ typedef struct dap_worker dap_proc_queue_t* proc_queue; dap_events_socket_t *proc_queue_input; - atomic_uint event_sockets_count; + uint32_t event_sockets_count; pthread_rwlock_t esocket_rwlock; dap_events_socket_t *esockets; // Hashmap of event sockets