MINOR: fd: pass the iocb and owner to fd_insert()
fd_insert() is currently called just after setting the owner and iocb,
but proceeding like this prevents the operation from being atomic and
requires a lock to protect the maxfd computation in another thread from
meeting an incompletely initialized FD and computing a wrong maxfd.
Fortunately for now all fdtab[].owner are set before calling fd_insert(),
and the first lock in fd_insert() enforces a memory barrier so the code
is safe.
This patch moves the initialization of the owner and iocb to fd_insert()
so that the function will be able to properly arrange its operations and
remain safe even when modified to become lockless. There's no other change
beyond the internal API.
diff --git a/src/proto_uxst.c b/src/proto_uxst.c
index 754acd2..3ab637f 100644
--- a/src/proto_uxst.c
+++ b/src/proto_uxst.c
@@ -331,13 +331,10 @@
listener->fd = fd;
listener->state = LI_LISTEN;
- /* the function for the accept() event */
- fdtab[fd].iocb = listener->proto->accept;
- fdtab[fd].owner = listener; /* reference the listener instead of a task */
- if (listener->bind_conf->bind_thread[relative_pid-1])
- fd_insert(fd, listener->bind_conf->bind_thread[relative_pid-1]);
- else
- fd_insert(fd, MAX_THREADS_MASK);
+ fd_insert(fd, listener, listener->proto->accept,
+ listener->bind_conf->bind_thread[relative_pid-1] ?
+ listener->bind_conf->bind_thread[relative_pid-1] : MAX_THREADS_MASK);
+
return err;
err_rename: