aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2020-04-13 11:15:20 +0200
committercbdev <cb@cbcdn.com>2020-04-13 11:15:20 +0200
commitf9ae5d3a21f520380b3f761b71e211e6c438227a (patch)
tree1a93426bdddb8cd0faf69f9820a6b4d64fd2f895
parent1891979d878e946941c6f236c3393cae943a4f1d (diff)
downloadmidimonster-f9ae5d3a21f520380b3f761b71e211e6c438227a.tar.gz
midimonster-f9ae5d3a21f520380b3f761b71e211e6c438227a.tar.bz2
midimonster-f9ae5d3a21f520380b3f761b71e211e6c438227a.zip
Introduce core iteration limit to break deadlocks
-rw-r--r--midimonster.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/midimonster.c b/midimonster.c
index 5109eab..8100607 100644
--- a/midimonster.c
+++ b/midimonster.c
@@ -10,6 +10,7 @@
#define MM_API __attribute__((dllexport))
#endif
#define BACKEND_NAME "core"
+#define MM_SWAP_LIMIT 20
#include "midimonster.h"
#include "config.h"
#include "backend.h"
@@ -339,7 +340,7 @@ static int args_parse(int argc, char** argv, char** cfg_file){
static int core_process(size_t nfds, managed_fd* signaled_fds){
event_collection* secondary = NULL;
- size_t u;
+ size_t u, swaps = 0;
//run backend processing, collect events
DBGPF("%lu backend FDs signaled\n", nfds);
@@ -347,7 +348,8 @@ static int core_process(size_t nfds, managed_fd* signaled_fds){
return 1;
}
- while(routing.events->n){
+ //limit number of collector swaps per iteration to prevent complete deadlock
+ while(routing.events->n && swaps < MM_SWAP_LIMIT){
//swap primary and secondary event collectors
DBGPF("Swapping event collectors, %lu events in primary\n", routing.events->n);
for(u = 0; u < sizeof(routing.pool) / sizeof(routing.pool[0]); u++){
@@ -368,6 +370,10 @@ static int core_process(size_t nfds, managed_fd* signaled_fds){
secondary->n = 0;
}
+ if(swaps == MM_SWAP_LIMIT){
+ LOG("Iteration swap limit hit, a backend may be configured to route events in an infinite loop");
+ }
+
return 0;
}