/* :nodoc: */
static mrb_value Cache_init(mrb_state *mrb, mrb_value self)
{
  mrb_value o;
  mrb_get_args(mrb, "o", &o);
  lmc_check_dict(mrb, o);
  lmc_error_t e;
  rb_lmc_handle_t *h;

  local_memcache_t *l = local_memcache_create(rstring_ptr_null(mrb_hash_get(mrb, o, lmc_rb_sym_namespace(mrb))),
                                              rstring_ptr_null(mrb_hash_get(mrb, o, lmc_rb_sym_filename(mrb))),
                                              double_value(mrb, mrb_hash_get(mrb, o, lmc_rb_sym_size_mb(mrb))),
                                              size_t_value(mrb_hash_get(mrb, o, lmc_rb_sym_min_alloc_size(mrb))), &e);

  if (!l)
    rb_lmc_raise_exception(mrb, &e);

  h = (rb_lmc_handle_t *)DATA_PTR(self);
  if (h) {
    mrb_free(mrb, h);
  }
  DATA_TYPE(self) = &lmc_cache_type;
  DATA_PTR(self) = NULL;

  h = (rb_lmc_handle_t *)mrb_malloc(mrb, sizeof(rb_lmc_handle_t));
  if (!h) {
    mrb_raise(mrb, E_RUNTIME_ERROR, "memory allocation error");
  }

  h->lmc = l;
  h->open = 1;

  DATA_PTR(self) = h;

  return self;
}
Example #2
0
/*
 * call-seq: LocalMemCache.check(*args)
 *
 * Tries to repair a corrupt namespace.  Usually one doesn't call this method
 * directly, it's invoked automatically when operations time out.
 *
 * valid options are 
 * [:namespace] 
 * [:filename] 
 *
 * The memory pool must be specified by either setting the :filename or
 * :namespace option. 
 */
static VALUE LocalMemCache__check(VALUE klass, VALUE o) {
  lmc_check_dict(o);
  lmc_error_t e;
  if (!local_memcache_check_namespace(
      rstring_ptr_null(rb_hash_aref(o, lmc_rb_sym_namespace)), 
      rstring_ptr_null(rb_hash_aref(o, lmc_rb_sym_filename)),
      &e)) {
    rb_lmc_raise_exception(&e); 
  }
  return Qnil;
}
/*
 * call-seq: Cache.drop(*args)
 *
 * Deletes a memory pool.  If the :force option is set, locked semaphores are
 * removed as well.
 *
 * WARNING: Do only call this method with the :force option if you are sure
 * that you really want to remove this memory pool and no more processes are
 * still using it.
 *
 * If you delete a pool and other processes still have handles open on it, the
 * status of these handles becomes undefined.  There's no way for a process to
 * know when a handle is not valid anymore, so only delete a memory pool if
 * you are sure that all handles are closed.
 *
 * valid options for drop are
 * [:namespace]
 * [:filename]
 * [:force]
 *
 * The memory pool must be specified by either setting the :filename or
 * :namespace option.  The default for :force is false.
 */
static mrb_value Cache__drop(mrb_state *mrb, mrb_value self)
{
  mrb_value o;
  mrb_get_args(mrb, "o", &o);
  lmc_check_dict(mrb, o);
  lmc_error_t e;
  if (!local_memcache_drop_namespace(rstring_ptr_null(mrb_hash_get(mrb, o, lmc_rb_sym_namespace(mrb))),
                                     rstring_ptr_null(mrb_hash_get(mrb, o, lmc_rb_sym_filename(mrb))),
                                     bool_value(mrb_hash_get(mrb, o, lmc_rb_sym_force(mrb))), &e)) {
    rb_lmc_raise_exception(mrb, &e);
  }
  return mrb_nil_value();
}
Example #4
0
/* :nodoc: */
static VALUE LocalMemCache__new2(VALUE klass, VALUE o) {
  lmc_check_dict(o);
  lmc_error_t e;
  local_memcache_t *l = local_memcache_create(
      rstring_ptr_null(rb_hash_aref(o, lmc_rb_sym_namespace)),
      rstring_ptr_null(rb_hash_aref(o, lmc_rb_sym_filename)), 
      double_value(rb_hash_aref(o, lmc_rb_sym_size_mb)),
      long_value(rb_hash_aref(o, lmc_rb_sym_min_alloc_size)), &e);
  if (!l)  rb_lmc_raise_exception(&e);
  rb_lmc_handle_t *h = calloc(1, sizeof(rb_lmc_handle_t));
  if (!h) rb_raise(rb_eRuntimeError, "memory allocation error");
  h->lmc = l;
  h->open = 1;
  return Data_Wrap_Struct(klass, NULL, rb_lmc_free_handle, h);
}