recursive mutex: Stop recursive Mutex when doing handler callbacks

Move around some of the COAP_CONSTRAINED_STACK mutex locking to prevent
recursive locking (issue when a proxy initiates an ongoing reliable client
connection).
This commit is contained in:
Jon Shallow committed 2022-05-04 09:57:34 +01:00
1 parent 0691f4ff5d
commit 9cbe5757cb
2 files changed
+30 -17

No files matched your search

+18 -17
View File
@@ -1302,8 +1302,8 @@ coap_io_process_with_fds(coap_context_t *ctx, uint32_t timeout_ms,
int enfds, fd_set *ereadfds, fd_set *ewritefds,
fd_set *eexceptfds) {
#if COAP_CONSTRAINED_STACK
static coap_mutex_t static_mutex = COAP_MUTEX_INITIALIZER;
# ifndef COAP_EPOLL_SUPPORT
static coap_mutex_t static_mutex = COAP_MUTEX_INITIALIZER;
static fd_set readfds, writefds, exceptfds;
static coap_socket_t *sockets[64];
unsigned int num_sockets = 0;
@@ -1324,13 +1324,14 @@ coap_io_process_with_fds(coap_context_t *ctx, uint32_t timeout_ms,
unsigned int i;
#endif /* ! COAP_EPOLL_SUPPORT */
coap_ticks(&before);
#ifndef COAP_EPOLL_SUPPORT
#if COAP_CONSTRAINED_STACK
coap_mutex_lock(&static_mutex);
#endif /* COAP_CONSTRAINED_STACK */
coap_ticks(&before);
#ifndef COAP_EPOLL_SUPPORT
timeout = coap_io_prepare_io(ctx, sockets,
(sizeof(sockets) / sizeof(sockets[0])),
&num_sockets, before);
@@ -1400,6 +1401,15 @@ coap_io_process_with_fds(coap_context_t *ctx, uint32_t timeout_ms,
return -1;
}
}
if (ereadfds) {
*ereadfds = readfds;
}
if (ewritefds) {
*ewritefds = writefds;
}
if (eexceptfds) {
*eexceptfds = exceptfds;
}
if (result > 0) {
for (i = 0; i < num_sockets; i++) {
@@ -1416,17 +1426,12 @@ coap_io_process_with_fds(coap_context_t *ctx, uint32_t timeout_ms,
}
}
#if COAP_CONSTRAINED_STACK
coap_mutex_unlock(&static_mutex);
#endif /* COAP_CONSTRAINED_STACK */
coap_ticks(&now);
coap_io_do_io(ctx, now);
if (ereadfds) {
*ereadfds = readfds;
}
if (ewritefds) {
*ewritefds = writefds;
}
if (eexceptfds) {
*eexceptfds = exceptfds;
}
#else /* COAP_EPOLL_SUPPORT */
(void)ereadfds;
@@ -1489,10 +1494,6 @@ coap_io_process_with_fds(coap_context_t *ctx, uint32_t timeout_ms,
coap_ticks(&now);
#endif /* WITHOUT_ASYNC */
#if COAP_CONSTRAINED_STACK
coap_mutex_unlock(&static_mutex);
#endif /* COAP_CONSTRAINED_STACK */
return (int)(((now - before) * 1000) / COAP_TICKS_PER_SECOND);
}
#endif /* RIOT_VERSION */
+12
View File
@@ -1611,7 +1611,13 @@ coap_read_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now)
if (n == len) {
if (coap_pdu_parse_header(session->partial_pdu, session->proto)
&& coap_pdu_parse_opt(session->partial_pdu)) {
#if COAP_CONSTRAINED_STACK
coap_mutex_unlock(&s_static_mutex);
#endif /* COAP_CONSTRAINED_STACK */
coap_dispatch(ctx, session, session->partial_pdu);
#if COAP_CONSTRAINED_STACK
coap_mutex_lock(&s_static_mutex);
#endif /* COAP_CONSTRAINED_STACK */
}
coap_delete_pdu(session->partial_pdu);
session->partial_pdu = NULL;
@@ -1655,7 +1661,13 @@ coap_read_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now)
session->partial_read = hdr_size;
if (size == 0) {
if (coap_pdu_parse_header(session->partial_pdu, session->proto)) {
#if COAP_CONSTRAINED_STACK
coap_mutex_unlock(&s_static_mutex);
#endif /* COAP_CONSTRAINED_STACK */
coap_dispatch(ctx, session, session->partial_pdu);
#if COAP_CONSTRAINED_STACK
coap_mutex_lock(&s_static_mutex);
#endif /* COAP_CONSTRAINED_STACK */
}
coap_delete_pdu(session->partial_pdu);
session->partial_pdu = NULL;