Example #1
0
int     smem_open(char *filename, int rwmode, int *driverhandle)
 { int h, nitems, r;
   DAL_SHM_SEGHEAD *sp;


   if (NULL == filename) return(SHARED_NULPTR);
   if (NULL == driverhandle) return(SHARED_NULPTR);
   nitems = sscanf(filename, "h%d", &h);
   if (1 != nitems) return(SHARED_BADARG);

   if (SHARED_OK != (r = shared_attach(h))) return(r);

   if (NULL == (sp = (DAL_SHM_SEGHEAD *)shared_lock(h,
                ((READWRITE == rwmode) ? SHARED_RDWRITE : SHARED_RDONLY))))
     {  shared_free(h);
        return(SHARED_BADARG);
     }

   if ((h != sp->h) || (DAL_SHM_SEGHEAD_ID != sp->ID))
     { shared_unlock(h);
       shared_free(h);

       return(SHARED_BADARG);
     }

   *driverhandle = h;
   return(0);
 }
Example #2
0
static cache_vars_t* cache_init(int size,int sector){
  int num;
  cache_vars_t* s=shared_alloc(sizeof(cache_vars_t));
  if(s==NULL) return NULL;

  memset(s,0,sizeof(cache_vars_t));
  num=size/sector;
  if(num < 16){
     num = 16;
  }//32kb min_size
  s->buffer_size=num*sector;
  s->sector_size=sector;
  s->buffer=shared_alloc(s->buffer_size);

  if(s->buffer == NULL){
    shared_free(s, sizeof(cache_vars_t));
    return NULL;
  }

  s->fill_limit=8*sector;
  s->back_size=s->buffer_size/2;
#if FORKED_CACHE
  s->ppid = getpid();
#endif
  return s;
}
Example #3
0
int     smem_create(char *filename, int *driverhandle)
 { DAL_SHM_SEGHEAD *sp;
   int h, sz, nitems;

   if (NULL == filename) return(SHARED_NULPTR);         /* currently ignored */
   if (NULL == driverhandle) return(SHARED_NULPTR);
   nitems = sscanf(filename, "h%d", &h);
   if (1 != nitems) return(SHARED_BADARG);

   if (SHARED_INVALID == (h = shared_malloc(sz = 2880 + sizeof(DAL_SHM_SEGHEAD), 
                        SHARED_RESIZE | SHARED_PERSIST, h)))
     return(SHARED_NOMEM);

   if (NULL == (sp = (DAL_SHM_SEGHEAD *)shared_lock(h, SHARED_RDWRITE)))
     { shared_free(h);
       return(SHARED_BADARG);
     }

   sp->ID = DAL_SHM_SEGHEAD_ID;
   sp->h = h;
   sp->size = sz;
   sp->nodeidx = -1;

   *driverhandle = h;
   
   return(0);
 }
Example #4
0
int     shared_uncond_delete(int id)
 { int i, r;

   if (NULL == shared_gt) return(SHARED_NOTINIT);       /* not initialized */
   if (NULL == shared_lt) return(SHARED_NOTINIT);       /* not initialized */
   if (shared_debug) printf("shared_uncond_delete:");
   r = SHARED_OK;
   for (i=0; i<shared_maxseg; i++)
    { if (-1 != id) if (i != id) continue;
      if (shared_attach(i))
        { if (-1 != id) printf("no such handle\n");
          continue;
        }
      printf("handle %d:", i);
      if (NULL == shared_lock(i, SHARED_RDWRITE | SHARED_NOWAIT)) 
        { printf(" cannot lock in RW mode, not deleted\n");
          continue;
        }
      if (shared_set_attr(i, SHARED_RESIZE) >= SHARED_ERRBASE)
        { printf(" cannot clear PERSIST attribute");
        }
      if (shared_free(i))
        { printf(" delete failed\n");
        }
      else
        { printf(" deleted\n");
        }
    }
   if (shared_debug) printf(" done\n");
   return(r);                                           /* table full */
 }
Example #5
0
void cache_uninit(stream_t *s) {
  cache_vars_t* c = s->cache_data;
  if(s->cache_pid) {
#if !FORKED_CACHE
    cache_do_control(s, -2, NULL);
#else
    kill(s->cache_pid,SIGKILL);
    waitpid(s->cache_pid,NULL,0);
#endif
    s->cache_pid = 0;
  }
  if(!c) return;
  shared_free(c->buffer, c->buffer_size);
  c->buffer = NULL;
  c->stream = NULL;
  shared_free(s->cache_data, sizeof(cache_vars_t));
  s->cache_data = NULL;
}
Example #6
0
void spead_api_destroy(struct spead_api_module_shared *s, void *data)
{
  struct json_file *json;
  
  lock_spead_api_module_shared(s);

  if ((json = get_data_spead_api_module_shared(s))){ 
    
    if (json->j_name)
      shared_free(json->j_name, sizeof(char)*(strlen(json->j_name) + 1));

    destroy_raw_data_file(json->j_df);

    shared_free(json, sizeof(struct json_file));

    clear_data_spead_api_module_shared(s);
  }

  unlock_spead_api_module_shared(s);
}
Example #7
0
int pa_shared_remove(pa_core *c, const char *name) {
    pa_shared *p;

    pa_assert(c);
    pa_assert(name);
    pa_assert(c->shared);

    if (!(p = pa_hashmap_remove(c->shared, name)))
        return -1;

    shared_free(p);
    return 0;
}
Example #8
0
void spead_api_destroy(struct spead_api_module_shared *s, void *data)
{
  struct snap_shot *ss;
  
  lock_spead_api_module_shared(s);

  if ((ss = get_data_spead_api_module_shared(s)) != NULL){ 
    shared_free(ss, sizeof(struct snap_shot));

    clear_data_spead_api_module_shared(s);
#ifdef DEBUG
    fprintf(stderr, "%s: PID [%d] destroyed spead_api_shared\n", __func__, getpid());
#endif
  } else {

#ifdef DEBUG
    fprintf(stderr, "%s: PID [%d] spead_api_shared is clean\n", __func__, getpid());
#endif

  }
  close(w_fd2);
  unlock_spead_api_module_shared(s);
}
Example #9
0
int     smem_close(int driverhandle)
 { int r;

   if (SHARED_OK != (r = shared_unlock(driverhandle))) return(r);
   return(shared_free(driverhandle));
 }