Initialize controller in two steps
There is a dependency cycle in the initialization order: - keyboard depends on controller - controller depends on acksync - acksync depends on keyboard initialization To break this cycle, bind the async instance to the controller in a second step.
This commit is contained in:
parent
a5a589c901
commit
e669028806
@ -7,8 +7,7 @@
|
||||
#define SC_CONTROL_MSG_QUEUE_MAX 64
|
||||
|
||||
bool
|
||||
sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
|
||||
struct sc_acksync *acksync) {
|
||||
sc_controller_init(struct sc_controller *controller, sc_socket control_socket) {
|
||||
sc_vecdeque_init(&controller->queue);
|
||||
|
||||
bool ok = sc_vecdeque_reserve(&controller->queue, SC_CONTROL_MSG_QUEUE_MAX);
|
||||
@ -16,7 +15,7 @@ sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
|
||||
return false;
|
||||
}
|
||||
|
||||
ok = sc_receiver_init(&controller->receiver, control_socket, acksync);
|
||||
ok = sc_receiver_init(&controller->receiver, control_socket);
|
||||
if (!ok) {
|
||||
sc_vecdeque_destroy(&controller->queue);
|
||||
return false;
|
||||
@ -43,6 +42,12 @@ sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
sc_controller_set_acksync(struct sc_controller *controller,
|
||||
struct sc_acksync *acksync) {
|
||||
controller->receiver.acksync = acksync;
|
||||
}
|
||||
|
||||
void
|
||||
sc_controller_destroy(struct sc_controller *controller) {
|
||||
sc_cond_destroy(&controller->msg_cond);
|
||||
|
@ -25,8 +25,11 @@ struct sc_controller {
|
||||
};
|
||||
|
||||
bool
|
||||
sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
|
||||
struct sc_acksync *acksync);
|
||||
sc_controller_init(struct sc_controller *controller, sc_socket control_socket);
|
||||
|
||||
void
|
||||
sc_controller_set_acksync(struct sc_controller *controller,
|
||||
struct sc_acksync *acksync);
|
||||
|
||||
void
|
||||
sc_controller_destroy(struct sc_controller *controller);
|
||||
|
@ -8,15 +8,14 @@
|
||||
#include "util/log.h"
|
||||
|
||||
bool
|
||||
sc_receiver_init(struct sc_receiver *receiver, sc_socket control_socket,
|
||||
struct sc_acksync *acksync) {
|
||||
sc_receiver_init(struct sc_receiver *receiver, sc_socket control_socket) {
|
||||
bool ok = sc_mutex_init(&receiver->mutex);
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
receiver->control_socket = control_socket;
|
||||
receiver->acksync = acksync;
|
||||
receiver->acksync = NULL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -20,8 +20,7 @@ struct sc_receiver {
|
||||
};
|
||||
|
||||
bool
|
||||
sc_receiver_init(struct sc_receiver *receiver, sc_socket control_socket,
|
||||
struct sc_acksync *acksync);
|
||||
sc_receiver_init(struct sc_receiver *receiver, sc_socket control_socket);
|
||||
|
||||
void
|
||||
sc_receiver_destroy(struct sc_receiver *receiver);
|
||||
|
@ -663,12 +663,13 @@ aoa_hid_end:
|
||||
mp = &s->mouse_sdk.mouse_processor;
|
||||
}
|
||||
|
||||
if (!sc_controller_init(&s->controller, s->server.control_socket,
|
||||
acksync)) {
|
||||
if (!sc_controller_init(&s->controller, s->server.control_socket)) {
|
||||
goto end;
|
||||
}
|
||||
controller_initialized = true;
|
||||
|
||||
sc_controller_set_acksync(&s->controller, acksync);
|
||||
|
||||
if (!sc_controller_start(&s->controller)) {
|
||||
goto end;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user