]> rtime.felk.cvut.cz Git - frescor/fwp.git/blobdiff - fwp/lib/fwp/fwp_vres.c
RESCHED flag renamed to CHANGED
[frescor/fwp.git] / fwp / lib / fwp / fwp_vres.c
index d5dae0b42a11a14f8aa4b5cbf28c035df43c6b78..4fcb21891e26259f1f131ef1a32a5224e1d74c93 100644 (file)
 
 #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             = ,
-       FWP_VF_BOUND            = ,
-       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 = {
@@ -269,7 +272,7 @@ inline int _fwp_vres_set_params(fwp_vres_t *vres, fwp_vres_params_t *params)
        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;
 }
@@ -320,7 +323,7 @@ int fwp_vres_create(fwp_vres_params_t *params, fwp_vres_d_t *vresdp)
        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){
@@ -370,7 +373,7 @@ static inline void
 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;
@@ -378,7 +381,7 @@ fwp_vres_sched_update(fwp_vres_t *vres, struct timespec *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);
        }
 }
 
@@ -405,7 +408,7 @@ static void* fwp_vres_tx_thread(void *_vres)
        /* 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 */
@@ -465,7 +468,7 @@ int fwp_vres_send(fwp_vres_d_t vresd, struct fwp_msgb* msgb)
        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;
        }
 }
@@ -484,7 +487,7 @@ int fwp_vres_bind(fwp_vres_d_t vresd, int sockd)
        }
        
        if (fwp_vres_get_flag(vres, FWP_VF_BOUND)) { /*if already bounded */
-               errno = EPERM;  
+               errno = EBUSY;
                rv = -1;
                goto err;
        }