mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-02 12:52:10 +00:00
Reduced the time SYS_ARCH_PROTECT is protecting the socket array
This commit is contained in:
parent
90bed0c5ac
commit
b0b4290c29
@ -223,15 +223,17 @@ alloc_socket(struct netconn *newconn, int accepted)
|
|||||||
SYS_ARCH_PROTECT(lev);
|
SYS_ARCH_PROTECT(lev);
|
||||||
if (!sockets[i].conn) {
|
if (!sockets[i].conn) {
|
||||||
sockets[i].conn = newconn;
|
sockets[i].conn = newconn;
|
||||||
|
/* The socket is not yet known to anyone, so no need to protect
|
||||||
|
after having marked it as used. */
|
||||||
|
SYS_ARCH_UNPROTECT(lev);
|
||||||
sockets[i].lastdata = NULL;
|
sockets[i].lastdata = NULL;
|
||||||
sockets[i].lastoffset = 0;
|
sockets[i].lastoffset = 0;
|
||||||
sockets[i].rcvevent = 0;
|
sockets[i].rcvevent = 0;
|
||||||
/* TCP sendbuf is empty, but not connected yet, so not yet writable
|
/* TCP sendbuf is empty, but the socket is not yet writable until connected
|
||||||
* (unless it has been created by accept()). */
|
* (unless it has been created by accept()). */
|
||||||
sockets[i].sendevent = (newconn->type == NETCONN_TCP ? (accepted != 0) : 1);
|
sockets[i].sendevent = (newconn->type == NETCONN_TCP ? (accepted != 0) : 1);
|
||||||
sockets[i].errevent = 0;
|
sockets[i].errevent = 0;
|
||||||
sockets[i].err = 0;
|
sockets[i].err = 0;
|
||||||
SYS_ARCH_UNPROTECT(lev);
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
SYS_ARCH_UNPROTECT(lev);
|
SYS_ARCH_UNPROTECT(lev);
|
||||||
@ -239,7 +241,7 @@ alloc_socket(struct netconn *newconn, int accepted)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Free a socket. The socket's netbuf must have been
|
/** Free a socket. The socket's netconn must have been
|
||||||
* delete before!
|
* delete before!
|
||||||
*
|
*
|
||||||
* @param sock the socket to free
|
* @param sock the socket to free
|
||||||
@ -250,13 +252,14 @@ free_socket(struct lwip_socket *sock)
|
|||||||
struct netbuf *lastdata;
|
struct netbuf *lastdata;
|
||||||
SYS_ARCH_DECL_PROTECT(lev);
|
SYS_ARCH_DECL_PROTECT(lev);
|
||||||
|
|
||||||
/* Protect socket array */
|
|
||||||
SYS_ARCH_PROTECT(lev);
|
|
||||||
lastdata = sock->lastdata;
|
lastdata = sock->lastdata;
|
||||||
sock->lastdata = NULL;
|
sock->lastdata = NULL;
|
||||||
sock->lastoffset = 0;
|
sock->lastoffset = 0;
|
||||||
sock->conn = NULL;
|
|
||||||
sock->err = 0;
|
sock->err = 0;
|
||||||
|
|
||||||
|
/* Protect socket array */
|
||||||
|
SYS_ARCH_PROTECT(lev);
|
||||||
|
sock->conn = NULL;
|
||||||
SYS_ARCH_UNPROTECT(lev);
|
SYS_ARCH_UNPROTECT(lev);
|
||||||
|
|
||||||
if (lastdata != NULL) {
|
if (lastdata != NULL) {
|
||||||
@ -335,9 +338,8 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
LWIP_ASSERT("invalid socket index", (newsock >= 0) && (newsock < NUM_SOCKETS));
|
LWIP_ASSERT("invalid socket index", (newsock >= 0) && (newsock < NUM_SOCKETS));
|
||||||
newconn->callback = event_callback;
|
LWIP_ASSERT("newconn->callback == event_callback", newconn->callback == event_callback);
|
||||||
nsock = &sockets[newsock];
|
nsock = &sockets[newsock];
|
||||||
LWIP_ASSERT("invalid socket pointer", nsock != NULL);
|
|
||||||
|
|
||||||
/* See event_callback: If data comes in right away after an accept, even
|
/* See event_callback: If data comes in right away after an accept, even
|
||||||
* though the server task might not have created a new socket yet.
|
* though the server task might not have created a new socket yet.
|
||||||
|
Loading…
Reference in New Issue
Block a user