#include "fwp_msgq.h"
#include "fwp_endpoint.h"
+#include "fwp_debug.h"
#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
static void* fwp_vres_tx_thread(void *_vres);
typedef enum {
- FWP_VF_USED = 1 ,
- FWP_VF_BOUND = 2 ,
- FWP_VF_RESCHED = 4 ,
+ FWP_VF_USED = 0,
+ FWP_VF_BOUND = 1,
+ FWP_VF_CHANGED = 2,
} fwp_vres_flag_t;
fwp_vres_params_t fwp_vres_params_default = {
if (!rv)
return rv;
memcpy(&vres->params, params, sizeof(struct fwp_vres_params));
- fwp_vres_set_flag(vres, FWP_VF_RESCHED);
+ fwp_vres_set_flag(vres, FWP_VF_CHANGED);
return 0;
}
fwp_msgq_init(&vres->tx_queue);
memcpy(&vres->params, params, sizeof(struct fwp_vres_params));
- fwp_vres_set_flag(vres, FWP_VF_RESCHED);
+ fwp_vres_set_flag(vres, FWP_VF_CHANGED);
pthread_attr_init(&vres->tx_thread_attr);
if ((rv = pthread_create(&vres->tx_thread, &vres->tx_thread_attr,
fwp_vres_tx_thread, (void*) vres)) != 0){
fwp_vres_sched_update(fwp_vres_t *vres, struct timespec *period,
fwp_budget_t *budget)
{
- if (fwp_vres_get_flag(vres, FWP_VF_RESCHED)) {
+ if (fwp_vres_get_flag(vres, FWP_VF_CHANGED)) {
/*period->tv_nsec = vres->params.period % SEC_TO_USEC;
period->tv_sec = vres->params.period / SEC_TO_USEC;*/
*period = vres->params.period;
FWP_DEBUG("Vres tx thread with budget=%ld period_sec=%ld "
"period_nsec=%ld.\n",vres->params.budget,
period->tv_sec, period->tv_nsec);
- fwp_vres_clear_flag(vres, FWP_VF_RESCHED);
+ fwp_vres_clear_flag(vres, FWP_VF_CHANGED);
}
}
/* just for sure */
fwp_vres_sched_update(vres, &period, &budget);
clock_gettime(CLOCK_MONOTONIC, &start_period);
- curr_budget = budget;
+ curr_budget = 0;
while (1) {
/* wait for next period and then send */
if (fwp_vres_is_valid(vres)) {
return fwp_msgq_enqueue(&vres->tx_queue, msgb);
} else {
- errno = EPERM; /* TODO: Use more appropriate error than EPERM. */
+ errno = EINVAL;
return -1;
}
}
}
if (fwp_vres_get_flag(vres, FWP_VF_BOUND)) { /*if already bounded */
- errno = EPERM;
+ errno = EBUSY;
rv = -1;
goto err;
}