libseat: Convert clients to linked_list

This commit is contained in:
Kenny Levinsen 2020-08-03 02:32:33 +02:00
parent fc7116ffad
commit e25688fed6
3 changed files with 21 additions and 11 deletions

View file

@ -26,7 +26,6 @@
#include "backend.h" #include "backend.h"
#include "drm.h" #include "drm.h"
#include "libseat.h" #include "libseat.h"
#include "list.h"
struct backend_logind { struct backend_logind {
struct libseat base; struct libseat base;

View file

@ -13,7 +13,7 @@
#include "backend.h" #include "backend.h"
#include "connection.h" #include "connection.h"
#include "libseat.h" #include "libseat.h"
#include "list.h" #include "linked_list.h"
#include "log.h" #include "log.h"
#include "protocol.h" #include "protocol.h"
@ -26,6 +26,7 @@ const struct libseat_impl seatd_impl;
const struct libseat_impl builtin_impl; const struct libseat_impl builtin_impl;
struct pending_event { struct pending_event {
struct linked_list link; // backend_seat::link
int opcode; int opcode;
}; };
@ -34,7 +35,7 @@ struct backend_seatd {
struct connection connection; struct connection connection;
struct libseat_seat_listener *seat_listener; struct libseat_seat_listener *seat_listener;
void *seat_listener_data; void *seat_listener_data;
struct list pending_events; struct linked_list pending_events;
char seat_name[MAX_SEAT_LEN]; char seat_name[MAX_SEAT_LEN];
}; };
@ -120,14 +121,23 @@ static int queue_event(struct backend_seatd *backend, int opcode) {
} }
ev->opcode = opcode; ev->opcode = opcode;
list_add(&backend->pending_events, ev); linked_list_insert(&backend->pending_events, &ev->link);
return 0; return 0;
} }
static void execute_events(struct backend_seatd *backend) { static void execute_events(struct backend_seatd *backend) {
while (backend->pending_events.length > 0) { struct linked_list list = {
struct pending_event *ev = list_pop_front(&backend->pending_events); .next = backend->pending_events.next,
.prev = backend->pending_events.prev,
};
list.next->prev = &list;
list.prev->next = &list;
linked_list_init(&backend->pending_events);
while (!linked_list_empty(&list)) {
struct pending_event *ev = (struct pending_event *)list.next;
int opcode = ev->opcode; int opcode = ev->opcode;
linked_list_remove(&ev->link);
free(ev); free(ev);
switch (opcode) { switch (opcode) {
@ -258,10 +268,11 @@ static void destroy(struct backend_seatd *backend) {
backend->connection.fd = -1; backend->connection.fd = -1;
} }
connection_close_fds(&backend->connection); connection_close_fds(&backend->connection);
for (size_t idx = 0; idx < backend->pending_events.length; idx++) { while (!linked_list_empty(&backend->pending_events)) {
free(backend->pending_events.items[idx]); struct pending_event *ev = (struct pending_event *)backend->pending_events.next;
linked_list_remove(&ev->link);
free(ev);
} }
list_free(&backend->pending_events);
free(backend); free(backend);
} }
@ -275,7 +286,7 @@ static struct libseat *_open_seat(struct libseat_seat_listener *listener, void *
backend->seat_listener_data = data; backend->seat_listener_data = data;
backend->connection.fd = fd; backend->connection.fd = fd;
backend->base.impl = &seatd_impl; backend->base.impl = &seatd_impl;
list_init(&backend->pending_events); linked_list_init(&backend->pending_events);
struct proto_header header = { struct proto_header header = {
.opcode = CLIENT_OPEN_SEAT, .opcode = CLIENT_OPEN_SEAT,

View file

@ -70,7 +70,7 @@ add_project_arguments(
private_files = [ private_files = [
'common/connection.c', 'common/connection.c',
'common/list.c', 'common/linked_list.c',
'common/log.c', 'common/log.c',
] ]