bdd_conversation next and prev are now ints

This commit is contained in:
aiden 2022-08-19 10:08:22 +01:00
parent a37c2b26a9
commit d3235a80cc
No known key found for this signature in database
GPG Key ID: 0D87FF3415416DB1
4 changed files with 37 additions and 30 deletions

View File

@ -85,8 +85,6 @@ struct bdd_conversation *bdd_conversation_obtain(int epoll_fd) {
io_array[idx].state = bdd_io_unused;
io_array[idx].conversation_id = id;
}
conversation->prev = NULL;
conversation->next = NULL;
conversation->state = bdd_conversation_obtained;
conversation->epoll_fd = epoll_fd;
conversation->tl = false;

View File

@ -15,6 +15,11 @@ struct bdd_service;
struct bdd_io;
#define io_conversation(io) (&(bdd_gv.conversations[io->conversation_id]))
#define _conversation_next(conversation) (&(bdd_gv.conversations[conversation->next]))
#define _conversation_prev(conversation) (&(bdd_gv.conversations[conversation->prev]))
#define conversation_next(conversation) (conversation->next != -1 ? _conversation_next(conversation) : NULL)
#define conversation_prev(conversation) (conversation->prev != -1 ? _conversation_prev(conversation) : NULL)
#define conversation_id(conversation) (conversation == NULL ? -1 : (int)(((char *)bdd_gv.conversations - (char *)conversation) / sizeof(struct bdd_conversation)))
struct bdd_associated {
void *data;
@ -32,8 +37,8 @@ struct bdd_conversation {
enum bdd_conversation_state state;
int epoll_fd;
struct bdd_conversation *next;
struct bdd_conversation *prev;
int next;
int prev;
time_t accessed_at;
bool tl : 1, remove : 1;

View File

@ -25,22 +25,22 @@
static inline void process_link(struct bdd_conversation **list, struct bdd_conversation *conversation) {
if (conversation->n_ev == 1) {
if (*list != NULL) {
(*list)->prev = conversation;
(*list)->prev = conversation_id(conversation);
}
conversation->next = *list;
conversation->prev = NULL;
conversation->next = conversation_id(*list);
conversation->prev = -1;
(*list) = conversation;
}
return;
}
static inline void process_unlink(struct bdd_conversation **list, struct bdd_conversation *conversation) {
struct bdd_conversation *next = conversation->next;
struct bdd_conversation *prev = conversation->prev;
struct bdd_conversation *next = conversation_next(conversation);
struct bdd_conversation *prev = conversation_prev(conversation);
if (next != NULL) {
next->prev = prev;
next->prev = conversation_id(prev);
}
if (prev != NULL) {
prev->next = next;
prev->next = conversation_id(next);
} else {
(*list) = next;
}
@ -97,7 +97,7 @@ void *bdd_serve(struct bdd_worker_data *worker_data) {
process_unlink(&(process_list), conversation);
}
conversation->remove = true;
conversation->next = remove_list;
conversation->next = conversation_id(remove_list);
remove_list = conversation;
}
break;
@ -125,12 +125,12 @@ void *bdd_serve(struct bdd_worker_data *worker_data) {
while (remove_list != NULL) {
struct bdd_conversation *conversation = remove_list;
remove_list = conversation->next;
remove_list = conversation_next(conversation);
bdd_conversation_discard(conversation);
}
while (process_list != NULL) {
struct bdd_conversation *conversation = process_list;
process_list = conversation->next;
process_list = conversation_next(conversation);
size_t non_removed_idx = 0;
for (size_t idx = 0; idx < conversation->n_ev;) {

View File

@ -17,41 +17,42 @@ time_t bdd_time(void) {
void bdd_tl_link(struct bdd_tl *timeout_list, struct bdd_conversation *conversation) {
conversation->tl = true;
conversation->next = NULL;
conversation->next = -1;
conversation->accessed_at = bdd_time();
if (timeout_list->head == NULL) {
assert(timeout_list->tail == NULL);
conversation->prev = NULL;
conversation->prev = -1;
timeout_list->tail = (timeout_list->head = conversation);
} else {
assert(timeout_list->tail != NULL);
conversation->prev = timeout_list->tail;
timeout_list->tail->next = conversation;
conversation->prev = conversation_id(timeout_list->tail);
timeout_list->tail->next = conversation_id(conversation);
timeout_list->tail = conversation;
}
return;
}
void bdd_tl_unlink(struct bdd_tl *timeout_list, struct bdd_conversation *conversation) {
struct bdd_conversation *n;
if ((n = conversation->prev) != NULL) {
n->next = conversation->next;
struct bdd_conversation *next = conversation_next(conversation);
struct bdd_conversation *prev = conversation_prev(conversation);
if (prev != NULL) {
prev->next = conversation->next;
}
if ((n = conversation->next) != NULL) {
n->prev = conversation->prev;
if (next != NULL) {
next->prev = conversation->prev;
}
if (timeout_list->tail == conversation) {
if ((timeout_list->tail = conversation->prev) == NULL) {
if ((timeout_list->tail = prev) == NULL) {
timeout_list->head = NULL;
}
} else if (timeout_list->head == conversation) {
if ((timeout_list->head = conversation->next) == NULL) {
if ((timeout_list->head = next) == NULL) {
timeout_list->tail = NULL;
}
}
conversation->tl = false;
conversation->next = NULL;
conversation->prev = NULL;
conversation->next = -1;
conversation->prev = -1;
return;
}
@ -65,10 +66,13 @@ void bdd_tl_process(struct bdd_tl *timeout_list) {
if (bdd_time() - conversation->accessed_at < bdd_gv.epoll_timeout) {
break;
}
timeout_list->head = conversation->next;
if (timeout_list->head != NULL) {
timeout_list->head->prev = NULL;
struct bdd_conversation *head = conversation_next(conversation);
timeout_list->head = head;
if (head != NULL) {
head->prev = -1;
}
bdd_conversation_discard(conversation);
}
return;