1919ErlNifResourceType * edf_channel_resource_type = NULL ;
2020static edf_channel_resource_table_t edf_channel_resource_table_internal = {._link = {.next = NULL , .prev = NULL }};
2121edf_channel_resource_table_t * edf_channel_resource_table = & edf_channel_resource_table_internal ;
22- static edf_channel_index_table_t edf_channel_index_table_internal = {._link = {.next = NULL , .prev = NULL }};
23- edf_channel_index_table_t * edf_channel_index_table = & edf_channel_index_table_internal ;
2422
2523/* Static Declarations */
2624
@@ -30,8 +28,6 @@ static void edf_channel_resource_type_down(ErlNifEnv *env, void *obj, ErlNifPid
3028static int edf_channel_create (ErlNifEnv * env , size_t packet_size , ERL_NIF_TERM sysname , uint32_t creation , uint32_t connection_id ,
3129 uint64_t dflags , edf_channel_resource_t * resource , edf_channel_t * * channelp ,
3230 ERL_NIF_TERM * error_term );
33- static void edf_channel_stats_init_empty (edf_channel_stats_t * stats );
34- static void edf_channel_stats_dop_init_empty (edf_channel_stats_dop_t * dop );
3531
3632/* Function Definitions */
3733
@@ -59,15 +55,6 @@ edf_channel_load(ErlNifEnv *env)
5955 (void )linklist_init_anchor (& edf_channel_resource_table -> _link );
6056 }
6157
62- if (!linklist_is_linked (& edf_channel_index_table -> _link )) {
63- retval = enif_tsd_key_create ("erldist_filter.channel_index_table_tsd_key" , & edf_channel_index_table -> key );
64- if (retval != 0 ) {
65- return retval ;
66- }
67- (void )core_rwlock_create (& edf_channel_index_table -> rwlock , "erldist_filter.channel_index_table_rwlock" );
68- (void )linklist_init_anchor (& edf_channel_index_table -> _link );
69- }
70-
7158 return retval ;
7259}
7360
@@ -114,7 +101,7 @@ edf_channel_resource_open(ErlNifEnv *env, size_t packet_size, ERL_NIF_TERM sysna
114101 // Don't release the resource here, so a reference is kept on the root table.
115102 // (void)enif_release_resource((void *)resource);
116103
117- ( void ) atomic_fetch_add ( & edf_world -> channels_created , 1 );
104+ WORLD_STATS_COUNT ( channel , create , 1 );
118105
119106 if (resourcep != NULL ) {
120107 * resourcep = resource ;
@@ -198,6 +185,8 @@ edf_channel_create(ErlNifEnv *env, size_t packet_size, ERL_NIF_TERM sysname, uin
198185 channel -> creation = creation ;
199186 channel -> connection_id = connection_id ;
200187 channel -> dflags = dflags ;
188+ channel -> rx .router_name = edf_channel_router_name (env , channel -> sysname );
189+ channel -> rx .sort = 0 ;
201190 channel -> rx .packet_size = packet_size ;
202191 channel -> rx .state = EDF_CHANNEL_RX_STATE_PACKET_HEADER ;
203192 (void )ioq_init_free (& channel -> rx .ioq );
@@ -287,93 +276,16 @@ edf_channel_destroy(ErlNifEnv *env, edf_channel_resource_t *resource, edf_channe
287276 }
288277 resource -> inner = NULL ;
289278 (void )enif_free ((void * )channel );
290- ( void ) atomic_fetch_add ( & edf_world -> channels_destroyed , 1 );
279+ WORLD_STATS_COUNT ( channel , destroy , 1 );
291280 return ;
292281}
293282
294- edf_channel_index_slot_t *
295- edf_channel_index_get_slow (void )
296- {
297- edf_channel_index_slot_t * slot = NULL ;
298- slot = (void * )enif_tsd_get (edf_channel_index_table -> key );
299- if (slot == NULL ) {
300- slot = enif_alloc (sizeof (edf_channel_index_slot_t ));
301- if (slot == NULL ) {
302- unreachable ();
303- (void )perror ("Too many processors or threads on this machine: OOM, unable to allocate edf_channel_index_slot_t!" );
304- abort ();
305- return NULL ;
306- }
307- slot -> _link .prev = NULL ;
308- slot -> _link .next = NULL ;
309- (void )edf_channel_stats_init_empty (& slot -> rx_stats );
310- (void )core_rwlock_write_lock (& edf_channel_index_table -> rwlock );
311- (void )linklist_insert (& edf_channel_index_table -> _link , & slot -> _link );
312- (void )core_rwlock_write_unlock (& edf_channel_index_table -> rwlock );
313- (void )enif_tsd_set (edf_channel_index_table -> key , (void * )slot );
314- return slot ;
315- }
316- return slot ;
317- }
318-
319- void
320- edf_channel_stats_init_empty (edf_channel_stats_t * stats )
283+ ERL_NIF_TERM
284+ edf_channel_router_name (ErlNifEnv * env , ERL_NIF_TERM sysname )
321285{
322- stats -> packet_count = 0 ;
323- stats -> emit_count = 0 ;
324- stats -> drop_count = 0 ;
325- stats -> dist_header_count = 0 ;
326- stats -> dist_frag_header_count = 0 ;
327- stats -> dist_frag_cont_count = 0 ;
328- stats -> dist_pass_through_count = 0 ;
329- stats -> atom_cache_read_count = 0 ;
330- stats -> atom_cache_write_count = 0 ;
331- stats -> atom_cache_overwrite_count = 0 ;
332- stats -> rewrite_fragment_header_count = 0 ;
333- stats -> rollback_atom_cache_count = 0 ;
334- stats -> compact_external_count = 0 ;
335- stats -> compact_fragment_count = 0 ;
336- stats -> control_has_export_ext = 0 ;
337- stats -> control_has_new_fun_ext = 0 ;
338- stats -> payload_has_export_ext = 0 ;
339- stats -> payload_has_new_fun_ext = 0 ;
340- (void )edf_channel_stats_dop_init_empty (& stats -> dop_link );
341- (void )edf_channel_stats_dop_init_empty (& stats -> dop_send );
342- (void )edf_channel_stats_dop_init_empty (& stats -> dop_exit );
343- (void )edf_channel_stats_dop_init_empty (& stats -> dop_unlink );
344- (void )edf_channel_stats_dop_init_empty (& stats -> dop_reg_send );
345- (void )edf_channel_stats_dop_init_empty (& stats -> dop_group_leader );
346- (void )edf_channel_stats_dop_init_empty (& stats -> dop_exit2 );
347- (void )edf_channel_stats_dop_init_empty (& stats -> dop_send_tt );
348- (void )edf_channel_stats_dop_init_empty (& stats -> dop_exit_tt );
349- (void )edf_channel_stats_dop_init_empty (& stats -> dop_reg_send_tt );
350- (void )edf_channel_stats_dop_init_empty (& stats -> dop_exit2_tt );
351- (void )edf_channel_stats_dop_init_empty (& stats -> dop_monitor_p );
352- (void )edf_channel_stats_dop_init_empty (& stats -> dop_demonitor_p );
353- (void )edf_channel_stats_dop_init_empty (& stats -> dop_monitor_p_exit );
354- (void )edf_channel_stats_dop_init_empty (& stats -> dop_send_sender );
355- (void )edf_channel_stats_dop_init_empty (& stats -> dop_send_sender_tt );
356- (void )edf_channel_stats_dop_init_empty (& stats -> dop_payload_exit );
357- (void )edf_channel_stats_dop_init_empty (& stats -> dop_payload_exit_tt );
358- (void )edf_channel_stats_dop_init_empty (& stats -> dop_payload_exit2 );
359- (void )edf_channel_stats_dop_init_empty (& stats -> dop_payload_exit2_tt );
360- (void )edf_channel_stats_dop_init_empty (& stats -> dop_payload_monitor_p_exit );
361- (void )edf_channel_stats_dop_init_empty (& stats -> dop_spawn_request );
362- (void )edf_channel_stats_dop_init_empty (& stats -> dop_spawn_request_tt );
363- (void )edf_channel_stats_dop_init_empty (& stats -> dop_spawn_reply );
364- (void )edf_channel_stats_dop_init_empty (& stats -> dop_spawn_reply_tt );
365- (void )edf_channel_stats_dop_init_empty (& stats -> dop_alias_send );
366- (void )edf_channel_stats_dop_init_empty (& stats -> dop_alias_send_tt );
367- (void )edf_channel_stats_dop_init_empty (& stats -> dop_unlink_id );
368- (void )edf_channel_stats_dop_init_empty (& stats -> dop_unlink_id_ack );
369- return ;
370- }
286+ ErlNifUInt64 router_number ;
371287
372- inline void
373- edf_channel_stats_dop_init_empty (edf_channel_stats_dop_t * dop )
374- {
375- dop -> seen = 0 ;
376- dop -> emit = 0 ;
377- dop -> drop = 0 ;
378- return ;
288+ router_number = enif_hash (ERL_NIF_INTERNAL_HASH , sysname , 0 );
289+ router_number %= erldist_filter_router_count ;
290+ return erldist_filter_router_names [router_number ];
379291}
0 commit comments