[core] change con joblist to singly-linked-list
avoids separate memory allocation for list of pointers adds ability to check if con is already in joblist, so do not re-add con if already in joblist since con is checked if in joblist before being added to joblist, there is no longer need for two lists and jobs can be processed before poll() for to process new eventspersonal/stbuehler/tests-path
parent
81a107b4e6
commit
dc2d1dfe47
18
src/base.h
18
src/base.h
|
@ -22,6 +22,7 @@ struct connection {
|
|||
|
||||
int fd; /* the FD for this connection */
|
||||
fdnode *fdn; /* fdevent (fdnode *) object */
|
||||
connection *jqnext;
|
||||
|
||||
/* fd states */
|
||||
signed char is_readable;
|
||||
|
@ -64,6 +65,18 @@ struct connection {
|
|||
connection *prev;
|
||||
};
|
||||
|
||||
/* log_con_jqueue is in log.c to be defined in shared object */
|
||||
#define joblist_append(con) connection_jq_append(con)
|
||||
extern connection *log_con_jqueue;
|
||||
static inline void connection_jq_append(connection * const restrict con);
|
||||
static inline void connection_jq_append(connection * const restrict con)
|
||||
{
|
||||
if (!con->jqnext) {
|
||||
con->jqnext = log_con_jqueue;
|
||||
log_con_jqueue = con;
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
connection **ptr;
|
||||
uint32_t size;
|
||||
|
@ -153,10 +166,6 @@ struct server {
|
|||
/* buffers */
|
||||
buffer *tmp_buf;
|
||||
|
||||
connections joblist_A;
|
||||
connections joblist_B;
|
||||
connections fdwaitqueue;
|
||||
|
||||
/* counters */
|
||||
int con_opened;
|
||||
int con_read;
|
||||
|
@ -172,6 +181,7 @@ struct server {
|
|||
uint32_t lim_conns;
|
||||
connection *conns;
|
||||
connection *conns_pool;
|
||||
connections fdwaitqueue;
|
||||
|
||||
log_error_st *errh;
|
||||
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
connections *connection_joblist;
|
||||
|
||||
__attribute_cold__
|
||||
static void connection_list_resize(connections *conns) {
|
||||
conns->size += 16;
|
||||
|
|
|
@ -22,8 +22,6 @@ connection * connection_accepted(server *srv, const struct server_socket *srv_so
|
|||
|
||||
void connection_state_machine(connection *con);
|
||||
|
||||
extern connections *connection_joblist;
|
||||
#define joblist_append(con) connection_list_append(connection_joblist, (con))
|
||||
void connection_list_append(connections *conns, connection *con);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
# include <syslog.h>
|
||||
#endif
|
||||
|
||||
/* log_con_jqueue instance here to be defined in shared object (see base.h) */
|
||||
connection *log_con_jqueue;
|
||||
|
||||
unix_time64_t log_epoch_secs = 0;
|
||||
unix_time64_t log_monotonic_secs = 0;
|
||||
|
||||
|
|
44
src/server.c
44
src/server.c
|
@ -262,12 +262,8 @@ __attribute_cold__
|
|||
static server *server_init(void) {
|
||||
server *srv = calloc(1, sizeof(*srv));
|
||||
force_assert(srv);
|
||||
#define CLEAN(x) \
|
||||
srv->x = buffer_init();
|
||||
|
||||
CLEAN(tmp_buf);
|
||||
#undef CLEAN
|
||||
connection_joblist = &srv->joblist_A;
|
||||
srv->tmp_buf = buffer_init();
|
||||
|
||||
strftime_cache_reset();
|
||||
|
||||
|
@ -307,6 +303,8 @@ static server *server_init(void) {
|
|||
srv->loadavg[2] = 0.0;
|
||||
srv->stdin_fd = -1;
|
||||
|
||||
log_con_jqueue = (connection *)(uintptr_t)&log_con_jqueue;/*(sentinel)*/
|
||||
|
||||
return srv;
|
||||
}
|
||||
|
||||
|
@ -327,19 +325,12 @@ static void server_free(server *srv) {
|
|||
close(srv->stdin_fd);
|
||||
}
|
||||
|
||||
#define CLEAN(x) \
|
||||
buffer_free(srv->x);
|
||||
|
||||
CLEAN(tmp_buf);
|
||||
|
||||
#undef CLEAN
|
||||
buffer_free(srv->tmp_buf);
|
||||
|
||||
fdevent_free(srv->ev);
|
||||
|
||||
config_free(srv);
|
||||
|
||||
free(srv->joblist_A.ptr);
|
||||
free(srv->joblist_B.ptr);
|
||||
free(srv->fdwaitqueue.ptr);
|
||||
|
||||
stat_cache_free();
|
||||
|
@ -1926,12 +1917,12 @@ static void server_handle_sigchld (server * const srv) {
|
|||
}
|
||||
|
||||
__attribute_hot__
|
||||
static void server_run_con_queue (connections * const restrict joblist) {
|
||||
connection * const * const restrict conlist = joblist->ptr;
|
||||
const uint32_t used = joblist->used;
|
||||
joblist->used = 0;
|
||||
for (uint32_t i = 0; i < used; ++i) {
|
||||
connection_state_machine(conlist[i]);
|
||||
__attribute_nonnull__
|
||||
static void server_run_con_queue (connection * const restrict joblist, const connection * const sentinel) {
|
||||
for (connection *con = joblist, *jqnext; con != sentinel; con = jqnext) {
|
||||
jqnext = con->jqnext;
|
||||
con->jqnext = NULL;
|
||||
connection_state_machine(con);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1984,17 +1975,14 @@ static void server_main_loop (server * const srv) {
|
|||
server_process_fdwaitqueue(srv);
|
||||
}
|
||||
|
||||
connections * const joblist = connection_joblist;
|
||||
static connection * const sentinel =
|
||||
(connection *)(uintptr_t)&log_con_jqueue;
|
||||
connection * const joblist = log_con_jqueue;
|
||||
log_con_jqueue = sentinel;
|
||||
server_run_con_queue(joblist, sentinel);
|
||||
|
||||
if (fdevent_poll(srv->ev, joblist->used ? 0 : 1000) > 0) {
|
||||
if (fdevent_poll(srv->ev, log_con_jqueue != sentinel ? 0 : 1000) > 0)
|
||||
last_active_ts = log_monotonic_secs;
|
||||
}
|
||||
|
||||
connection_joblist = (joblist == &srv->joblist_A)
|
||||
? &srv->joblist_B
|
||||
: &srv->joblist_A;
|
||||
|
||||
server_run_con_queue(joblist);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue