]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - frsh_api/frsh_thread.c
Further improvements in core API implementation.
[frescor/frsh.git] / frsh_api / frsh_thread.c
1 /**
2  * @file   frsh_thread.c
3  * @author Dario Faggioli <faggioli@gandalf.sssup.it>
4  *
5  * @brief  FRSH core thread related functions not implamented in managers..
6  *
7  *
8  */
9 #include <fres_contract.h>
10 #include <fres_contract_idl.h>
11 #include <frsh_core.h>
12 #include <frsh_error.h>
13 #include <fres_blocks.h>
14 #include <string.h>
15 #include <fcb.h>
16 #include "frsh_forb.h"
17 #include <fra_generic.h>
18
19 int frsh_thread_create_in_background
20   (frsh_thread_code_t thread_code,
21    const void *thread_arg,
22    const frsh_contract_label_t contract_label,
23    frsh_thread_attr_t *attr,
24    frsh_thread_id_t *thread,
25    frsh_vres_id_t *vres_id)
26 {
27         frsh_contract_t contract;
28         fosa_rel_time_t zero_msec = fosa_msec_to_rel_time(0);
29         int rv = 0;
30
31         /* Background contract creation and negotiation */
32         frsh_contract_init(&contract);
33         frsh_contract_set_resource_and_label(&contract,
34                                              FRSH_RT_PROCESSOR,
35                                              0,
36                                              contract_label);
37         frsh_contract_set_basic_params(&contract,
38                                        &zero_msec,
39                                        &zero_msec,
40                                        FRSH_WT_INDETERMINATE,
41                                        FRSH_CT_BACKGROUND);
42
43         /* It will be accepted: we are asking for 0 budget over 0 period */
44         rv = frsh_contract_negotiate(&contract, vres_id);
45         if (rv !=0) goto error;
46
47         rv = fosa_thread_create(thread, attr, thread_code, (void*) thread_arg);
48         if (rv != 0) goto error;
49
50         return 0;
51 error:
52         return rv;
53 }
54
55 int frsh_thread_get_vres_id
56   (const frsh_thread_id_t thread,
57    frsh_vres_id_t *vres_id)
58 {
59         if (!vres_id)
60                 return FRSH_ERR_BAD_ARGUMENT;
61
62         *vres_id = fra_get_vres_thread_vres(&thread);
63
64         return vres_id ? 0 : EINVAL;
65 }
66
67 int frsh_service_thread_set_data
68   (const struct timespec *budget,
69    const struct timespec *period,
70    bool *accepted)
71 {
72         return FRSH_ERR_NOT_IMPLEMENTED; 
73 }
74
75 int frsh_service_thread_get_data
76   (frsh_rel_time_t *budget,
77    frsh_rel_time_t *period)
78 {
79         return FRSH_ERR_NOT_IMPLEMENTED; 
80 }
81