summaryrefslogtreecommitdiff
path: root/src/ot_workqueue.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ot_workqueue.c')
-rw-r--r--src/ot_workqueue.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/ot_workqueue.c b/src/ot_workqueue.c
index 56a7cd2..cdefddc 100644
--- a/src/ot_workqueue.c
+++ b/src/ot_workqueue.c
@@ -9,6 +9,7 @@
9#include <unistd.h> 9#include <unistd.h>
10 10
11/* Opentracker */ 11/* Opentracker */
12#include "ot_fdstate.h"
12#include "ot_iovec.h" 13#include "ot_iovec.h"
13#include "ot_workqueue.h" 14#include "ot_workqueue.h"
14#include "trackerlogic.h" 15#include "trackerlogic.h"
@@ -20,6 +21,7 @@ struct ot_task {
20 ot_taskid taskid; 21 ot_taskid taskid;
21 ot_tasktype tasktype; 22 ot_tasktype tasktype;
22 int64_t sock; 23 int64_t sock;
24 uint32_t generation;
23 size_t iovec_entries; 25 size_t iovec_entries;
24 struct iovec *iovec; 26 struct iovec *iovec;
25 struct ot_task *next; 27 struct ot_task *next;
@@ -40,6 +42,7 @@ int workqueue_pushtask(int64_t sock, ot_tasktype tasktype) {
40 task->taskid = 0; 42 task->taskid = 0;
41 task->tasktype = tasktype; 43 task->tasktype = tasktype;
42 task->sock = sock; 44 task->sock = sock;
45 task->generation = fdstate_generation((int)sock);
43 task->iovec_entries = 0; 46 task->iovec_entries = 0;
44 task->iovec = NULL; 47 task->iovec = NULL;
45 task->next = 0; 48 task->next = 0;
@@ -65,22 +68,25 @@ void workqueue_canceltask(int64_t sock) {
65 /* Want exclusive access to tasklist */ 68 /* Want exclusive access to tasklist */
66 pthread_mutex_lock(&tasklist_mutex); 69 pthread_mutex_lock(&tasklist_mutex);
67 70
68 for (task = &tasklist; *task; task = &((*task)->next)) 71 task = &tasklist;
69 if ((*task)->sock == sock) { 72 while (*task) {
70 struct iovec *iovec = (*task)->iovec; 73 struct ot_task *ptask = *task;
71 struct ot_task *ptask = *task; 74 size_t i;
72 size_t i;
73
74 /* Free task's iovec, the buffers it points at and the vector itself */
75 for (i = 0; i < (*task)->iovec_entries; ++i)
76 free(iovec[i].iov_base);
77 free(iovec);
78 75
79 *task = (*task)->next; 76 if (ptask->sock != sock) {
80 free(ptask); 77 task = &ptask->next;
81 break; 78 continue;
82 } 79 }
83 80
81 /* Free task's iovec, the buffers it points at and the vector itself */
82 for (i = 0; i < ptask->iovec_entries; ++i)
83 free(ptask->iovec[i].iov_base);
84 free(ptask->iovec);
85
86 *task = ptask->next;
87 free(ptask);
88 }
89
84 /* Release lock */ 90 /* Release lock */
85 pthread_mutex_unlock(&tasklist_mutex); 91 pthread_mutex_unlock(&tasklist_mutex);
86} 92}
@@ -190,7 +196,7 @@ int workqueue_pushchunked(ot_taskid taskid, struct iovec *iovec) {
190 return task ? 0 : -1; 196 return task ? 0 : -1;
191} 197}
192 198
193int64_t workqueue_popresult(size_t *iovec_entries, struct iovec **iovec, int *is_partial) { 199int64_t workqueue_popresult(size_t *iovec_entries, struct iovec **iovec, int *is_partial, uint32_t *generation) {
194 struct ot_task **task; 200 struct ot_task **task;
195 int64_t sock = -1; 201 int64_t sock = -1;
196 202
@@ -205,6 +211,7 @@ int64_t workqueue_popresult(size_t *iovec_entries, struct iovec **iovec, int *is
205 *iovec_entries = ptask->iovec_entries; 211 *iovec_entries = ptask->iovec_entries;
206 *iovec = ptask->iovec; 212 *iovec = ptask->iovec;
207 sock = ptask->sock; 213 sock = ptask->sock;
214 *generation = ptask->generation;
208 215
209 if ((*task)->tasktype == TASK_DONE) { 216 if ((*task)->tasktype == TASK_DONE) {
210 *task = ptask->next; 217 *task = ptask->next;