--- BDB/BDB.xs 2007/02/05 18:40:55 1.1 +++ BDB/BDB.xs 2007/02/05 20:21:38 1.2 @@ -20,14 +20,12 @@ #include #include #include -#include #include -#include #include #include #include -#include -#include + +#include /* number of seconds after which idle threads exit */ #define IDLE_TIMEOUT 10 @@ -46,18 +44,26 @@ typedef SV SV8; /* byte-sv, used for argument-checking */ -enum { +enum +{ REQ_QUIT, + REQ_ENV_OPEN, REQ_ENV_CLOSE, + REQ_DB_OPEN, REQ_DB_CLOSE, }; -#define AIO_CB \ - struct aio_cb *volatile next; \ - SV *callback; \ - int type, pri - typedef struct aio_cb { - AIO_CB; + struct aio_cb *volatile next; + SV *callback; + int type, pri, errorno; + + DB_ENV *env; + DB *db; + DB_TXN *txn; + DBC *cursor; + int int1, int2; + U32 uint1, uint2; + char *buf1, *buf2; } aio_cb; typedef aio_cb *aio_req; @@ -232,7 +238,6 @@ } static int poll_cb (); -static int req_invoke (aio_req req); static void req_free (aio_req req); static void req_cancel (aio_req req); @@ -264,6 +269,8 @@ static void req_free (aio_req req) { + free (req->buf1); + free (req->buf2); Safefree (req); } @@ -618,7 +625,7 @@ atfork_parent (); } -#define dREQ \ +#define dREQ(reqtype) \ aio_req req; \ int req_pri = next_pri; \ next_pri = DEFAULT_PRI + PRI_BIAS; \ @@ -626,26 +633,113 @@ if (SvOK (callback) && !SvROK (callback)) \ croak ("callback must be undef or of reference type"); \ \ - Newz (0, req, 1, aio_cb); \ + Newz (0, req, 1, aio_cb); \ if (!req) \ croak ("out of memory during aio_req allocation"); \ \ req->callback = newSVsv (callback); \ + req->type = (reqtype); \ req->pri = req_pri #define REQ_SEND \ - req_send (req); \ - \ - if (GIMME_V != G_VOID) \ - XPUSHs (req_sv (req, AIO_REQ_KLASS)); + req_send (req) + +#define SvPTR(var, arg, type, class) \ + if (!SvOK (arg)) \ + (var) = 0; \ + else if (sv_derived_from ((arg), # class)) \ + { \ + IV tmp = SvIV ((SV*) SvRV (arg)); \ + (var) = INT2PTR (type, tmp); \ + } \ + else \ + Perl_croak (# var " is not of type " # type) -MODULE = BDB::AIO PACKAGE = BDB::AIO +MODULE = BDB PACKAGE = BDB PROTOTYPES: ENABLE BOOT: { - HV *stash = gv_stashpv ("BDB::AIO", 1); + HV *stash = gv_stashpv ("BDB", 1); + + static const struct { + const char *name; + IV iv; + } *civ, const_iv[] = { +#define const_iv(name) { # name, (IV)DB_ ## name }, + const_iv (RPCCLIENT) + const_iv (INIT_CDB) + const_iv (INIT_LOCK) + const_iv (INIT_LOG) + const_iv (INIT_MPOOL) + const_iv (INIT_REP) + const_iv (INIT_TXN) + const_iv (RECOVER) + const_iv (INIT_TXN) + const_iv (RECOVER_FATAL) + const_iv (CREATE) + const_iv (USE_ENVIRON) + const_iv (USE_ENVIRON_ROOT) + const_iv (LOCKDOWN) + const_iv (PRIVATE) + const_iv (REGISTER) + const_iv (SYSTEM_MEM) + const_iv (AUTO_COMMIT) + const_iv (CDB_ALLDB) + const_iv (DIRECT_DB) + const_iv (DIRECT_LOG) + const_iv (DSYNC_DB) + const_iv (DSYNC_LOG) + const_iv (LOG_AUTOREMOVE) + const_iv (LOG_INMEMORY) + const_iv (NOLOCKING) + const_iv (MULTIVERSION) + const_iv (NOMMAP) + const_iv (NOPANIC) + const_iv (OVERWRITE) + const_iv (PANIC_ENVIRONMENT) + const_iv (REGION_INIT) + const_iv (TIME_NOTGRANTED) + const_iv (TXN_NOSYNC) + const_iv (TXN_SNAPSHOT) + const_iv (TXN_WRITE_NOSYNC) + const_iv (YIELDCPU) + const_iv (ENCRYPT_AES) + const_iv (XA_CREATE) + const_iv (BTREE) + const_iv (HASH) + const_iv (QUEUE) + const_iv (RECNO) + const_iv (UNKNOWN) + const_iv (EXCL) + const_iv (READ_UNCOMMITTED) + const_iv (TRUNCATE) + const_iv (NOSYNC) + const_iv (CHKSUM) + const_iv (ENCRYPT) + const_iv (TXN_NOT_DURABLE) + const_iv (DUP) + const_iv (DUPSORT) + const_iv (RECNUM) + const_iv (RENUMBER) + const_iv (REVSPLITOFF) + const_iv (INORDER) + const_iv (CONSUME) + const_iv (CONSUME_WAIT) + const_iv (SNAPSHOT) + const_iv (JOIN_ITEM) + const_iv (RMW) + + const_iv (NOTFOUND) + const_iv (KEYEMPTY) + const_iv (LOCK_DEADLOCK) + const_iv (LOCK_NOTGRANTED) + const_iv (RUNRECOVERY) + }; + + for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) + newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); create_pipe (); pthread_atfork (atfork_prepare, atfork_parent, atfork_child); @@ -783,4 +877,105 @@ OUTPUT: RETVAL +DB_ENV * +bdb_env_create (U32 env_flags = 0) + CODE: +{ + int err = db_env_create (&RETVAL, env_flags); + if (err) + croak ("db_env_create: %s", db_strerror (err)); +} + +void +bdb_env_open (DB_ENV *env, char *db_home, U32 open_flags, int mode, SV *callback = 0) + CODE: +{ + dREQ (REQ_ENV_OPEN); + req->env = env; + req->uint1 = open_flags; + req->int1 = mode; + req->buf1 = strdup (db_home); + REQ_SEND; +} + +void +bdb_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) + CODE: +{ + dREQ (REQ_ENV_CLOSE); + req->env = env; + req->uint1 = flags; + REQ_SEND; +} + +DB * +bdb_db_create (DB_ENV *env = 0, U32 flags = 0) + CODE: +{ + int err = db_create (&RETVAL, env, flags); + if (err) + croak ("db_env_create: %s", db_strerror (err)); +} + +void +bdb_db_open (DB *db, DB_TXN *txnid, const char *file, const char *database, int type, U32 flags, int mode, SV *callback = 0) + CODE: +{ + dREQ (REQ_DB_OPEN); + req->db = db; + req->txn = txnid; + req->buf1 = strdup (file); + req->buf2 = strdup (database); + req->int1 = type; + req->uint1 = flags; + req->int2 = mode; + REQ_SEND; +} + +void +bdb_db_close (DB *db, U32 flags = 0, SV *callback = 0) + CODE: +{ + dREQ (REQ_DB_CLOSE); + req->db = db; + req->uint1 = flags; + REQ_SEND; +} + + +MODULE = BDB PACKAGE = BDB::Env + +int set_cachesize (DB_ENV *env, U32 gbytes, U32 bytes, int ncache = 0) + +int set_flags (DB_ENV *env, U32 flags, int onoff) + +int set_encrypt (DB_ENV *env, const char *password, U32 flags) + +MODULE = BDB PACKAGE = BDB::Db + +int set_cachesize (DB *db, U32 gbytes, U32 bytes, int ncache = 0) + +int set_flags (DB *env, U32 flags, int onoff) + +int set_encrypt (DB *db, const char *password, U32 flags) + +int set_lorder (DB *db, int lorder) + + +int set_bt_minkey (DB *db, U32 minkey) + +int set_re_delim(DB *db, int delim); + +int set_re_pad (DB *db, int re_pad) + +int set_re_source (DB *db, char *source) + +int set_re_len (DB *db, U32 re_len) + +int set_h_ffactor (DB *db, U32 h_ffactor) + +int set_h_nelem (DB *db, U32 h_nelem) + +int set_q_extentsize (DB *db, U32 extentsize) +