diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index c60e6d922..8c0651709 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -203,6 +203,7 @@ extern void thread_destroy_event(event_t *arg); extern mutex_t *thread_create_mutex(void); extern void thread_close_mutex(mutex_t *arg); +extern int thread_test_mutex(mutex_t *arg); extern int thread_wait_mutex(mutex_t *arg); extern int thread_release_mutex(mutex_t *mutex); diff --git a/src/network/network.c b/src/network/network.c index fad9eacbc..48e3b928b 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -348,7 +348,7 @@ network_rx_queue(void *priv) { int ret = 1; - if (network_rx_pause) { + if (network_rx_pause || !thread_test_mutex(network_mutex)) { timer_on_auto(&network_rx_queue_timer, 0.762939453125 * 2.0 * 128.0); return; } diff --git a/src/thread.cpp b/src/thread.cpp index 4134befba..1003dd871 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -37,6 +37,16 @@ thread_create_mutex(void) return mutex; } +int +thread_test_mutex(mutex_t *_mutex) +{ + if (_mutex == nullptr) + return 0; + + auto mutex = reinterpret_cast(_mutex); + return mutex->try_lock() ? 1 : 0; +} + int thread_wait_mutex(mutex_t *_mutex) {