Skip to content

Commit d079a50

Browse files
committed
Minimize semaphore scope
There no need to lock while allocating a connection, only when adding it to the linked list. Signed-off-by: Nir Soffer <[email protected]>
1 parent ae7ce87 commit d079a50

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ struct state {
9494
} _state;
9595

9696
static void state_add_socket_fd(struct state *state, int socket_fd) {
97-
dispatch_semaphore_wait(state->sem, DISPATCH_TIME_FOREVER);
9897
struct conn *conn = calloc(1, sizeof(*conn));
9998
conn->socket_fd = socket_fd;
99+
dispatch_semaphore_wait(state->sem, DISPATCH_TIME_FOREVER);
100100
if (state->conns == NULL) {
101101
state->conns = conn;
102102
} else {

0 commit comments

Comments
 (0)