summaryrefslogtreecommitdiff
path: root/src/slices_evt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/slices_evt.c')
-rw-r--r--src/slices_evt.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/slices_evt.c b/src/slices_evt.c
new file mode 100644
index 0000000..4ed07c6
--- /dev/null
+++ b/src/slices_evt.c
@@ -0,0 +1,29 @@
+#include "slices_evt.h"
+
+#include <stdio.h>
+#include <pthread.h>
+
+// Event-aware version of sliceSplit (reusing it, of course)
+int sliceEvtSplit(slices_evt_t *slicesEvt, slice_t *initialSlice, address_t splitAt, sliceStatus_t statusBefore, sliceStatus_t statusAt, sliceStatus_t statusAfter) {
+ int res;
+ res=sliceSplit(slicesEvt->data, initialSlice, splitAt, statusBefore, statusAt, statusAfter);
+
+ pthread_mutex_lock(&(slicesEvt->eventListenerMutex));
+ if ( slicesEvt->eventListener != NULL ) {
+ switch(res) {
+ case 3:
+ slicesEvt->eventListener(slicesEvt, initialSlice->next->next);
+ case 2:
+ slicesEvt->eventListener(slicesEvt, initialSlice->next);
+ case 1:
+ slicesEvt->eventListener(slicesEvt, initialSlice);
+ break;
+ default:
+ // No events on split errors
+ break;
+ }
+ }
+ pthread_mutex_unlock(&(slicesEvt->eventListenerMutex));
+ return res;
+}
+