From b96a55237bf07afda731980100db0dc02ee52ab7 Mon Sep 17 00:00:00 2001 From: Dennis Potter Date: Thu, 26 Jul 2018 15:46:41 +0200 Subject: [PATCH] Added pthread_testcancel() in ib_read() As discussed in issue #186 and on IM. This function check every 2048th cycle if the thread should be canceled. This also removed the need for 'kill -9' in the integration test. --- lib/nodes/infiniband.c | 4 +++- tests/integration/node-infiniband.sh | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/nodes/infiniband.c b/lib/nodes/infiniband.c index 799910dcc..a24974dcb 100644 --- a/lib/nodes/infiniband.c +++ b/lib/nodes/infiniband.c @@ -723,7 +723,9 @@ int ib_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *relea // Poll Completion Queue // If we've already posted enough receive WRs, try to pull cnt if (ib->conn.available_recv_wrs >= (ib->qp_init.cap.max_recv_wr - ib->conn.buffer_subtraction) ) { - while(1) { + for (int i = 0;; i++) { + if (i % 2048 == 2047) pthread_testcancel(); + if (n->state != STATE_CONNECTED) return 0; wcs = ibv_poll_cq(ib->ctx.recv_cq, cnt, wc); diff --git a/tests/integration/node-infiniband.sh b/tests/integration/node-infiniband.sh index a29102a28..58e9e6669 100755 --- a/tests/integration/node-infiniband.sh +++ b/tests/integration/node-infiniband.sh @@ -166,8 +166,8 @@ do sleep 2 # Stop node - kill -9 $node_pipe - kill -9 $node_proc + kill $node_pipe + kill $node_proc # Compare data villas-test-cmp ${INPUT_FILE} ${OUTPUT_FILE}