Skip to content

Commit cc7fece

Browse files
committed
stm32/modnwwiznet5k: Release the GIL on blocking network operations.
connect, send, recv, sendto and recvfrom now release the GIL. accept already releases the GIL because it calls mp_hal_delay_ms() within its busy-wait loop.
1 parent 0708dd4 commit cc7fece

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

ports/stm32/modnwwiznet5k.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ STATIC int wiznet5k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, m
213213
}
214214

215215
// now connect
216+
MP_THREAD_GIL_EXIT();
216217
mp_int_t ret = WIZCHIP_EXPORT(connect)(socket->u_param.fileno, ip, port);
218+
MP_THREAD_GIL_ENTER();
219+
217220
if (ret < 0) {
218221
wiznet5k_socket_close(socket);
219222
*_errno = -ret;
@@ -225,7 +228,10 @@ STATIC int wiznet5k_socket_connect(mod_network_socket_obj_t *socket, byte *ip, m
225228
}
226229

227230
STATIC mp_uint_t wiznet5k_socket_send(mod_network_socket_obj_t *socket, const byte *buf, mp_uint_t len, int *_errno) {
231+
MP_THREAD_GIL_EXIT();
228232
mp_int_t ret = WIZCHIP_EXPORT(send)(socket->u_param.fileno, (byte*)buf, len);
233+
MP_THREAD_GIL_ENTER();
234+
229235
// TODO convert Wiz errno's to POSIX ones
230236
if (ret < 0) {
231237
wiznet5k_socket_close(socket);
@@ -236,7 +242,10 @@ STATIC mp_uint_t wiznet5k_socket_send(mod_network_socket_obj_t *socket, const by
236242
}
237243

238244
STATIC mp_uint_t wiznet5k_socket_recv(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno) {
245+
MP_THREAD_GIL_EXIT();
239246
mp_int_t ret = WIZCHIP_EXPORT(recv)(socket->u_param.fileno, buf, len);
247+
MP_THREAD_GIL_ENTER();
248+
240249
// TODO convert Wiz errno's to POSIX ones
241250
if (ret < 0) {
242251
wiznet5k_socket_close(socket);
@@ -254,7 +263,10 @@ STATIC mp_uint_t wiznet5k_socket_sendto(mod_network_socket_obj_t *socket, const
254263
}
255264
}
256265

266+
MP_THREAD_GIL_EXIT();
257267
mp_int_t ret = WIZCHIP_EXPORT(sendto)(socket->u_param.fileno, (byte*)buf, len, ip, port);
268+
MP_THREAD_GIL_ENTER();
269+
258270
if (ret < 0) {
259271
wiznet5k_socket_close(socket);
260272
*_errno = -ret;
@@ -265,7 +277,9 @@ STATIC mp_uint_t wiznet5k_socket_sendto(mod_network_socket_obj_t *socket, const
265277

266278
STATIC mp_uint_t wiznet5k_socket_recvfrom(mod_network_socket_obj_t *socket, byte *buf, mp_uint_t len, byte *ip, mp_uint_t *port, int *_errno) {
267279
uint16_t port2;
280+
MP_THREAD_GIL_EXIT();
268281
mp_int_t ret = WIZCHIP_EXPORT(recvfrom)(socket->u_param.fileno, buf, len, ip, &port2);
282+
MP_THREAD_GIL_ENTER();
269283
*port = port2;
270284
if (ret < 0) {
271285
wiznet5k_socket_close(socket);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy