@@ -123,6 +123,7 @@ static struct pollfd *g_fds;
123
123
static connection_list_element * g_connection_list_head = NULL ;
124
124
static connection_list_element * g_accept_connection_list_head = NULL ;
125
125
static miner_list_element * g_miner_list_head = NULL ;
126
+ static uint32_t g_connection_changed = 0 ;
126
127
static pthread_mutex_t g_descriptors_mutex = PTHREAD_MUTEX_INITIALIZER ;
127
128
static pthread_mutex_t g_pool_mutex = PTHREAD_MUTEX_INITIALIZER ;
128
129
@@ -468,6 +469,7 @@ static void close_connection(connection_list_element *connection, const char *me
468
469
pthread_mutex_lock (& g_descriptors_mutex );
469
470
LL_DELETE (g_connection_list_head , connection );
470
471
-- g_connections_count ;
472
+ g_connection_changed = 1 ;
471
473
472
474
close (conn_data -> connection_descriptor .fd );
473
475
@@ -815,17 +817,22 @@ void *pool_main_thread(void *arg)
815
817
{
816
818
LL_DELETE (g_accept_connection_list_head , elt );
817
819
LL_APPEND (g_connection_list_head , elt );
820
+ g_connection_changed = 1 ;
818
821
}
819
-
820
822
int index = 0 ;
821
- LL_FOREACH (g_connection_list_head , elt )
822
- {
823
- memcpy (g_fds + index , & elt -> connection_data .connection_descriptor , sizeof (struct pollfd ));
824
- ++ index ;
823
+ if (g_connection_changed ) {
824
+ g_connection_changed = 0 ;
825
+ LL_FOREACH (g_connection_list_head , elt )
826
+ {
827
+ memcpy (g_fds + index , & elt -> connection_data .connection_descriptor , sizeof (struct pollfd ));
828
+ ++ index ;
829
+ }
825
830
}
831
+
832
+ int connections_count = g_connections_count ;
826
833
pthread_mutex_unlock (& g_descriptors_mutex );
827
834
828
- int res = poll (g_fds , index , 1000 );
835
+ int res = poll (g_fds , connections_count , 1000 );
829
836
830
837
if (!res ) continue ;
831
838
0 commit comments