-
Notifications
You must be signed in to change notification settings - Fork 65
/
workerTask.c
46 lines (36 loc) · 1.17 KB
/
workerTask.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "workerTask.h"
#include <stdio.h>
#include <ffi.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
/* newWorkerTask
* creates a new WorkerTask.
* IMPORTANT: is responsibility of the caller to free the created task
*/
WorkerTask *worker_task_new(void *externalFunction, ffi_cif *cif, void *parameters, void *returnHolder, int semaphoreIndex) {
WorkerTask *task = malloc(sizeof(WorkerTask));
task->type = CALLOUT;
task->anExternalFunction = externalFunction;
task->cif = (ffi_cif*) cif;
task->parametersAddress = parameters;
task->returnHolderAddress = returnHolder;
task->semaphoreIndex = semaphoreIndex;
task->queueHandle = NULL;
return task;
}
WorkerTask *worker_task_new_callback(CallbackInvocation* invocation) {
WorkerTask *task = malloc(sizeof(WorkerTask));
task->callbackSemaphore = invocation->payload;
task->type = CALLBACK_RETURN;
return task;
}
WorkerTask *worker_task_new_release() {
WorkerTask *task = malloc(sizeof(WorkerTask));
task->callbackSemaphore = NULL;
task->type = WORKER_RELEASE;
return task;
}
void worker_task_release(WorkerTask *task) {
free(task);
}