]> rtime.felk.cvut.cz Git - frescor/fwp.git/commitdiff
Do not use preallocated memory for VRESes
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 10 Nov 2009 10:35:33 +0000 (11:35 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 10 Nov 2009 10:35:43 +0000 (11:35 +0100)
This was unnecessarily limiting. VRES creation in FWP in not meant to be
hard real-time, so one more malloc() doesn't hurt us.

fwp/lib/fwp/fwp.c
fwp/lib/fwp/fwp_vres.c
fwp/lib/fwp/fwp_vres.h

index 55560a94e24aaa70206b2c0cbf7d4eeb0d8954f6..03e5634931cea3ff55bf84c63ee6c000927c07bf 100644 (file)
@@ -54,19 +54,6 @@ UL_LOGREG_SINGLE_DOMAIN_INIT_FUNCTION(init_ulogd_fwo, ulogd_fwp);
 
 int fwp_init()
 {
-       int rv;
-
-       if (/*(rv = fwp_endpoint_table_init(fwp_configuration.max_endpoints))||
-           (rv = fwp_vres_table_init(fwp_configuration.max_vres)))*/
-           (rv = fwp_vres_table_init(20)))
-               return rv;
-       
-/*     if (fwp_configuration.mngt) { 
-               //frsh_resource_register(FRSH_WIFI, &fwp_resource);
-               rv = fwp_mngt_init(); 
-               return rv;
-       }*/
-
        return 0;
 }
 
index ad5bacbf36e92cd160a64cef2d65be66b90dedee..3d593efb9ec0e0f95f09326c4d53ed57e4847b0a 100644 (file)
@@ -58,7 +58,6 @@
 static void* fwp_vres_tx_thread(void *_vres);
 
 typedef enum {
-       USED,
        UNTOUCHED,
        CHANGED,
        QUEUED,
@@ -96,20 +95,6 @@ struct fwp_vres{
        struct fwp_msgq                 msg_queue;   
 };
 
-typedef
-struct fwp_vres_table {
-       unsigned int                    max_vres; 
-       fwp_vres_t                      *entry;
-       pthread_mutex_t                 lock;
-} fwp_vres_table_t;
-
-/* Global variable - vres table */
-static fwp_vres_table_t  fwp_vres_table = {
-       .max_vres = 0,
-       .entry = NULL,
-       .lock = PTHREAD_MUTEX_INITIALIZER,
-};
-
 /**< mapping priority to ac*/
 static const int prio_to_ac[8] = {2,3,3,2,1,1,0,0};
 /**< IP tos for AC_VI, AC_VO, AC_BE, AC_BK */ 
@@ -160,19 +145,7 @@ static inline void clear_all_flags(fwp_vres_t *vres)
 
 static inline void fwp_vres_free(fwp_vres_t *vres)
 {
-       /* Clear USED flag */
-       clear_all_flags(vres);
-}
-
-static inline int fwp_vres_is_valid(fwp_vres_t *vres)
-{
-       int id  = vres - fwp_vres_table.entry;
-
-       if ((id < 0) || (id > fwp_vres_table.max_vres - 1) || 
-               (!get_flag(vres, USED))) 
-               return 0;
-       
-       return 1; 
+       free(vres);
 }
 
 /*inline int fwp_vres_get(fwp_vres_id_t vres_id, fwp_vres_t **vres )
@@ -184,19 +157,6 @@ static inline int fwp_vres_is_valid(fwp_vres_t *vres)
 }
 */
 
-int fwp_vres_table_init(unsigned int max_vres)
-{
-       unsigned int table_size = max_vres * sizeof(fwp_vres_t);
-
-       fwp_vres_table.entry = (fwp_vres_t*) malloc(table_size);
-       if (!fwp_vres_table.entry) 
-               return -1;      /* Errno is set by malloc */
-
-       memset((void*) fwp_vres_table.entry, 0, table_size);
-       fwp_vres_table.max_vres = max_vres;
-       return 0;
-}
-
 /**
  * Allocate vres
  *
@@ -204,28 +164,10 @@ int fwp_vres_table_init(unsigned int max_vres)
  */
 fwp_vres_t *fwp_vres_alloc()
 {
-       int i;
-       unsigned int max_vres;
-
-       /* find free vres id */
-       pthread_mutex_lock(&fwp_vres_table.lock);
-       i = 0;
-       max_vres = fwp_vres_table.max_vres;
-       while ((i < max_vres) && 
-               (get_flag(&fwp_vres_table.entry[i], USED))) {
-               i++;
-       }
-       
-       if (i == max_vres) {
-               pthread_mutex_unlock(&fwp_vres_table.lock);
-               errno = ENOBUFS;
-               return NULL;
-       }
-
-       FWP_DEBUG("Allocated vres id = %d\n",i);
-       set_flag(&fwp_vres_table.entry[i], USED);
-       pthread_mutex_unlock(&fwp_vres_table.lock);
-       return (&fwp_vres_table.entry[i]);
+       fwp_vres_t *vres = malloc(sizeof(fwp_vres_t));
+       if (vres)
+               FWP_DEBUG("Allocated vres\n");
+       return vres;
 }
 
 static int apply_params(fwp_vres_t *vres)
@@ -255,7 +197,7 @@ int fwp_vres_set_params(fwp_vres_t *vres, fwp_vres_params_t *params)
 {
        int rv = 0;
 
-       if (!fwp_vres_is_valid(vres)) {
+       if (!vres) {
                errno = EINVAL;
                return -1;
        }
@@ -335,7 +277,7 @@ err:
  */
 int fwp_vres_destroy(fwp_vres_t *vres)
 {      
-       if (!fwp_vres_is_valid(vres)) {
+       if (!vres) {
                errno = EINVAL;
                return -1;
        }
@@ -511,7 +453,7 @@ int fwp_vres_bind(fwp_vres_t *vres, struct fwp_endpoint *ep, int sockd, struct i
 {
        int rv = 0;
 
-       if (!fwp_vres_is_valid(vres)) {
+       if (!vres) {
                errno = EINVAL;
                rv = -1;
                goto err;
@@ -535,7 +477,7 @@ err:
 
 int fwp_vres_unbind(fwp_vres_t *vres)
 {
-       if (!fwp_vres_is_valid(vres)) {
+       if (!vres) {
                errno = EINVAL;
                return -1;
        }
index f6a9b0629c8599a9bfd0f3074bc048c7abae3887..c0bf84c3f07cd6b66943359d488fabe07ef4fd16 100644 (file)
@@ -85,8 +85,6 @@ struct fwp_vres_params {
        struct in_addr  src;
 } fwp_vres_params_t;
 
-int fwp_vres_table_init(unsigned int max_vres);
-
 fwp_vres_t *fwp_vres_alloc();
 int fwp_vres_set_params(fwp_vres_t *vres, fwp_vres_params_t *params);
 int fwp_vres_create(fwp_vres_params_t *params, fwp_vres_t **vresp);