class BDB::Lockid
Public Instance Methods
close()
click to toggle source
static VALUE bdb_env_lockid_close(VALUE obj) { bdb_ENV *envst; bdb_LOCKID *dblockid; Data_Get_Struct(obj, bdb_LOCKID, dblockid); bdb_clean_env(dblockid->env, obj); #if HAVE_ST_DB_ENV_LOCK_ID_FREE GetEnvDB(dblockid->env, envst); RDATA(obj)->dfree = free; if (envst->envp) { bdb_test_error(envst->envp->lock_id_free(envst->envp, dblockid->lock)); } #endif dblockid->env = 0; return Qnil; }
get(p1, p2, p3 = v3)
click to toggle source
static VALUE bdb_lockid_get(int argc, VALUE *argv, VALUE obj) { bdb_LOCKID *lockid; bdb_ENV *envst; DB_LOCK lock; bdb_LOCK *lockst; DBT objet; unsigned int flags; int lock_mode; VALUE a, b, c, res; rb_secure(2); flags = 0; if (rb_scan_args(argc, argv, "21", &a, &b, &c) == 3) { if (c == Qtrue) { flags = DB_LOCK_NOWAIT; } else { flags = NUM2UINT(c); } } SafeStringValue(a); MEMZERO(&objet, DBT, 1); objet.data = StringValuePtr(a); objet.size = RSTRING_LEN(a); lock_mode = NUM2INT(b); GetLockid(obj, lockid, envst); #if HAVE_ST_DB_ENV_LK_INFO if (!envst->envp->lk_info) { rb_raise(bdb_eLock, "lock region not open"); } bdb_test_error(lock_get(envst->envp->lk_info, lockid->lock, flags, &objet, lock_mode, &lock)); #elif HAVE_ST_DB_ENV_LOCK_GET bdb_test_error(envst->envp->lock_get(envst->envp, lockid->lock, flags, &objet, lock_mode, &lock)); #else bdb_test_error(lock_get(envst->envp, lockid->lock, flags, &objet, lock_mode, &lock)); #endif res = Data_Make_Struct(bdb_cLock, bdb_LOCK, lock_mark, lock_free, lockst); #if HAVE_ST_DB_ENV_LK_INFO lockst->lock = lock; #else lockst->lock = ALLOC(DB_LOCK); MEMCPY(lockst->lock, &lock, DB_LOCK, 1); #endif lockst->env = lockid->env; return res; }
lock_get(p1, p2, p3 = v3)
click to toggle source
static VALUE bdb_lockid_get(int argc, VALUE *argv, VALUE obj) { bdb_LOCKID *lockid; bdb_ENV *envst; DB_LOCK lock; bdb_LOCK *lockst; DBT objet; unsigned int flags; int lock_mode; VALUE a, b, c, res; rb_secure(2); flags = 0; if (rb_scan_args(argc, argv, "21", &a, &b, &c) == 3) { if (c == Qtrue) { flags = DB_LOCK_NOWAIT; } else { flags = NUM2UINT(c); } } SafeStringValue(a); MEMZERO(&objet, DBT, 1); objet.data = StringValuePtr(a); objet.size = RSTRING_LEN(a); lock_mode = NUM2INT(b); GetLockid(obj, lockid, envst); #if HAVE_ST_DB_ENV_LK_INFO if (!envst->envp->lk_info) { rb_raise(bdb_eLock, "lock region not open"); } bdb_test_error(lock_get(envst->envp->lk_info, lockid->lock, flags, &objet, lock_mode, &lock)); #elif HAVE_ST_DB_ENV_LOCK_GET bdb_test_error(envst->envp->lock_get(envst->envp, lockid->lock, flags, &objet, lock_mode, &lock)); #else bdb_test_error(lock_get(envst->envp, lockid->lock, flags, &objet, lock_mode, &lock)); #endif res = Data_Make_Struct(bdb_cLock, bdb_LOCK, lock_mark, lock_free, lockst); #if HAVE_ST_DB_ENV_LK_INFO lockst->lock = lock; #else lockst->lock = ALLOC(DB_LOCK); MEMCPY(lockst->lock, &lock, DB_LOCK, 1); #endif lockst->env = lockid->env; return res; }
lock_vec(p1, p2 = v2)
click to toggle source
static VALUE bdb_lockid_vec(int argc, VALUE *argv, VALUE obj) { DB_LOCKREQ *list; bdb_LOCKID *lockid; bdb_LOCK *lockst; bdb_ENV *envst; unsigned int flags; VALUE a, b, c, res; int i, n, err; VALUE listobj; struct lockreq *listst; flags = 0; if (rb_scan_args(argc, argv, "11", &a, &b) == 2) { if (b == Qtrue) { flags = DB_LOCK_NOWAIT; } else { flags = NUM2UINT(b); } } Check_Type(a, T_ARRAY); list = ALLOCA_N(DB_LOCKREQ, RARRAY_LEN(a)); MEMZERO(list, DB_LOCKREQ, RARRAY_LEN(a)); listobj = Data_Make_Struct(obj, struct lockreq, 0, free, listst); for (i = 0; i < RARRAY_LEN(a); i++) { b = RARRAY_PTR(a)[i]; Check_Type(b, T_HASH); listst->list = &list[i]; rb_iterate(rb_each, b, bdb_lockid_each, listobj); } GetLockid(obj, lockid, envst); #if HAVE_ST_DB_ENV_LK_INFO if (!envst->envp->lk_info) { rb_raise(bdb_eLock, "lock region not open"); } err = lock_vec(envst->envp->lk_info, lockid->lock, flags, list, RARRAY_LEN(a), NULL); #elif HAVE_ST_DB_ENV_LOCK_VEC err = envst->envp->lock_vec(envst->envp, lockid->lock, flags, list, RARRAY_LEN(a), NULL); #else err = lock_vec(envst->envp, lockid->lock, flags, list, RARRAY_LEN(a), NULL); #endif if (err != 0) { for (i = 0; i < RARRAY_LEN(a); i++) { if (list[i].obj) free(list[i].obj); } res = (err == DB_LOCK_DEADLOCK)?bdb_eLock:bdb_eFatal; if (bdb_errcall) { bdb_errcall = 0; rb_raise(res, "%s -- %s", StringValuePtr(bdb_errstr), db_strerror(err)); } else rb_raise(res, "%s", db_strerror(err)); } res = rb_ary_new2(RARRAY_LEN(a)); n = 0; for (i = 0; i < RARRAY_LEN(a); i++) { if (list[i].op == DB_LOCK_GET) { c = Data_Make_Struct(bdb_cLock, bdb_LOCK, lock_mark, lock_free, lockst); #if HAVE_ST_DB_ENV_LK_INFO lockst->lock = list[i].lock; #else lockst->lock = ALLOC(DB_LOCK); MEMCPY(lockst->lock, &list[i].lock, DB_LOCK, 1); #endif lockst->env = lockid->env; rb_ary_push(res, c); n++; } else { rb_ary_push(res, Qnil); } } return res; }
vec(p1, p2 = v2)
click to toggle source
static VALUE bdb_lockid_vec(int argc, VALUE *argv, VALUE obj) { DB_LOCKREQ *list; bdb_LOCKID *lockid; bdb_LOCK *lockst; bdb_ENV *envst; unsigned int flags; VALUE a, b, c, res; int i, n, err; VALUE listobj; struct lockreq *listst; flags = 0; if (rb_scan_args(argc, argv, "11", &a, &b) == 2) { if (b == Qtrue) { flags = DB_LOCK_NOWAIT; } else { flags = NUM2UINT(b); } } Check_Type(a, T_ARRAY); list = ALLOCA_N(DB_LOCKREQ, RARRAY_LEN(a)); MEMZERO(list, DB_LOCKREQ, RARRAY_LEN(a)); listobj = Data_Make_Struct(obj, struct lockreq, 0, free, listst); for (i = 0; i < RARRAY_LEN(a); i++) { b = RARRAY_PTR(a)[i]; Check_Type(b, T_HASH); listst->list = &list[i]; rb_iterate(rb_each, b, bdb_lockid_each, listobj); } GetLockid(obj, lockid, envst); #if HAVE_ST_DB_ENV_LK_INFO if (!envst->envp->lk_info) { rb_raise(bdb_eLock, "lock region not open"); } err = lock_vec(envst->envp->lk_info, lockid->lock, flags, list, RARRAY_LEN(a), NULL); #elif HAVE_ST_DB_ENV_LOCK_VEC err = envst->envp->lock_vec(envst->envp, lockid->lock, flags, list, RARRAY_LEN(a), NULL); #else err = lock_vec(envst->envp, lockid->lock, flags, list, RARRAY_LEN(a), NULL); #endif if (err != 0) { for (i = 0; i < RARRAY_LEN(a); i++) { if (list[i].obj) free(list[i].obj); } res = (err == DB_LOCK_DEADLOCK)?bdb_eLock:bdb_eFatal; if (bdb_errcall) { bdb_errcall = 0; rb_raise(res, "%s -- %s", StringValuePtr(bdb_errstr), db_strerror(err)); } else rb_raise(res, "%s", db_strerror(err)); } res = rb_ary_new2(RARRAY_LEN(a)); n = 0; for (i = 0; i < RARRAY_LEN(a); i++) { if (list[i].op == DB_LOCK_GET) { c = Data_Make_Struct(bdb_cLock, bdb_LOCK, lock_mark, lock_free, lockst); #if HAVE_ST_DB_ENV_LK_INFO lockst->lock = list[i].lock; #else lockst->lock = ALLOC(DB_LOCK); MEMCPY(lockst->lock, &list[i].lock, DB_LOCK, 1); #endif lockst->env = lockid->env; rb_ary_push(res, c); n++; } else { rb_ary_push(res, Qnil); } } return res; }