Added an asynchronous sys_null_async() call and wrappers
[akaros.git] / lib / asynccall.c
1 #include <inc/lib.h>
2 #include <inc/syscall.h>
3 #include <inc/queue.h>
4
5 async_desc_t* get_async_desc(void)
6 {
7         async_desc_t* desc = POOL_GET(&async_desc_pool);
8         if (desc)
9                 // Clear out any data that was in the old desc
10                 memset(desc, 0, sizeof(*desc));
11         return desc;
12 }
13
14 error_t waiton_async_call(async_desc_t* desc, async_rsp_t* rsp)
15 {
16         // TODO: Fill in the rsp parameter passed in here with 
17         // something meaningful
18         syscall_rsp_t syscall_rsp;
19         syscall_desc_t* d;
20         while (!(LIST_EMPTY(&desc->syslist))) {
21                 d = LIST_FIRST(&desc->syslist);
22                 waiton_syscall(d, &syscall_rsp);
23                 // consider processing the retval out of rsp here (TODO)
24                 // remove from the list and free the syscall desc
25                 LIST_REMOVE(d, next);
26                 POOL_PUT(&syscall_desc_pool, d);
27         }
28         // run a cleanup function for this desc, if available
29         if (desc->cleanup)
30                 desc->cleanup(desc->data);
31         // free the asynccall desc
32         POOL_PUT(&async_desc_pool, desc);
33         return 0;
34 }
35
36 syscall_desc_t* get_sys_desc(async_desc_t* desc)
37 {
38         syscall_desc_t* d = POOL_GET(&syscall_desc_pool);
39         if (d) {
40                 // Clear out any data that was in the old desc
41                 memset(d, 0, sizeof(*d));
42         LIST_INSERT_TAIL(&desc->syslist, d, next);
43         }
44         return d;
45 }