GCC/uthread callbacks on blocking syscalls (XCC)
[akaros.git] / user / parlib / include / arc.h
1 // Header for Asynch Remote Call, currently only support remote syscalls.
2 #ifndef _ARC_H
3 #define _ARC_H
4
5 #ifdef __cplusplus
6   extern "C" {
7 #endif
8
9 #include <parlib.h>
10 #include <error.h>
11 #include <pool.h>
12 #include <assert.h>
13 #include <sys/queue.h>
14 #include <ros/ring_syscall.h>
15
16 extern syscall_front_ring_t syscallfrontring;
17 extern sysevent_back_ring_t syseventbackring;
18
19 /*
20  * Syscall Descriptor: This helps userspace track a specific syscall.  Includes
21  * a cleanup function to be run when this syscall is complete.  Linked list of
22  * these for now. (Tail Queue)
23  */
24 typedef struct syscall_desc syscall_desc_t;
25 struct syscall_desc {
26         TAILQ_ENTRY(syscall_desc) next;
27         syscall_front_ring_t* sysfr;
28         uint32_t idx;
29         // cleanup
30         void (*cleanup)(void* data);
31         void* data;
32 };
33 TAILQ_HEAD(syscall_desc_list, syscall_desc);
34 typedef struct syscall_desc_list syscall_desc_list_t;
35
36
37 // TODO: where to declare async syscalls?
38
39 // async callback
40 #define MAX_SYSCALLS 100
41 #define MAX_ASYNCCALLS 100
42
43 // The high-level object a process waits on, with multiple syscalls within.
44 typedef struct async_desc {
45         syscall_desc_list_t syslist;
46         void (*cleanup)(void* data);
47         void* data;
48 } async_desc_t;
49
50 // Response to an async call.  Should be some sort of aggregation of the
51 // syscall responses.
52 typedef struct async_rsp_t {
53         int32_t retval;
54 } async_rsp_t;
55
56 // This is per-thread, and used when entering a async library call to properly
57 // group syscall_desc_t used during the processing of that async call
58 extern async_desc_t* current_async_desc;
59
60 // This pooltype contains syscall_desc_t, which is how you wait on one syscall.
61 POOL_TYPE_DEFINE(syscall_desc_t, syscall_desc_pool, MAX_SYSCALLS);
62 POOL_TYPE_DEFINE(async_desc_t, async_desc_pool, MAX_ASYNCCALLS);
63
64 // These are declared in asynccall.c
65 extern syscall_desc_pool_t syscall_desc_pool;
66 extern async_desc_pool_t async_desc_pool;
67
68 /* Initialize front and back rings of syscall/event ring */
69 void init_arc();
70
71 /* Generic Async Call */
72 int waiton_syscall(syscall_desc_t* desc, syscall_rsp_t* rsp);
73
74 /* Async group call */
75 int waiton_async_call(async_desc_t* desc, async_rsp_t* rsp);
76
77 int async_syscall(syscall_req_t* req, syscall_desc_t* desc);
78
79 async_desc_t* get_async_desc(void);
80 syscall_desc_t* get_sys_desc(async_desc_t* desc);
81 int get_all_desc(async_desc_t** a_desc, syscall_desc_t** s_desc);
82
83 #ifdef __cplusplus
84   }
85 #endif
86
87 #endif