-
Notifications
You must be signed in to change notification settings - Fork 65
/
callbacks.h
52 lines (41 loc) · 1.53 KB
/
callbacks.h
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
46
47
48
49
50
51
52
#ifndef __CALLBACKS__
#define __CALLBACKS__
#include <ffi.h>
#include "pThreadedFFI.h"
#include "pharovm/semaphores/pharoSemaphore.h"
#include "pharovm/semaphores/pSemaphore.h"
#include "pharovm/threadSafeQueue/threadSafeQueue.h"
typedef struct _Callback Callback;
typedef struct _Runner Runner;
typedef struct _CallbackInvocation CallbackInvocation;
typedef void (*WORKER_CALLBACK_FUNCTION)(Runner* runner, CallbackInvocation* callback);
struct _Runner {
WORKER_CALLBACK_FUNCTION callbackEnterFunction;
WORKER_CALLBACK_FUNCTION callbackExitFunction;
WORKER_CALLBACK_FUNCTION callbackPrepareInvocation;
CallbackInvocation *callbackStack;
};
struct _Callback {
Runner* runner;
void* userData; // This pointer is useful to store debug information
ffi_closure *closure;
ffi_cif cif;
void *functionAddress;
ffi_type **parameterTypes;
};
struct _CallbackInvocation {
Callback *callback;
void *returnHolder;
void **arguments;
//Optional payload used by the runners
// In the same Thread strategy here we store the state of the interpreter to perform the sig long jump
// In the worker it puts a semaphore to signal if the call is from another thread that is not the worker.
// If it is the same it is NULL
void *payload;
void *previous;
};
Callback *callback_new(Runner * runner, ffi_type** parameters, sqInt count, ffi_type* returnType);
void callback_release(Callback* callbackData);
CallbackInvocation *queue_next_pending_callback();
void initilizeCallbacks(int pharo_semaphore_index);
#endif