[elephant-cvs] CVS update: elephant/src/libsleepycat.c

blee at common-lisp.net blee at common-lisp.net
Fri Aug 27 02:54:45 UTC 2004


Update of /project/elephant/cvsroot/elephant/src
In directory common-lisp.net:/tmp/cvs-serv23659/src

Modified Files:
	libsleepycat.c 
Log Message:
beginning of lock and cursor support

Date: Thu Aug 26 19:54:43 2004
Author: blee

Index: elephant/src/libsleepycat.c
diff -u elephant/src/libsleepycat.c:1.1.1.1 elephant/src/libsleepycat.c:1.2
--- elephant/src/libsleepycat.c:1.1.1.1	Thu Aug 19 10:05:15 2004
+++ elephant/src/libsleepycat.c	Thu Aug 26 19:54:43 2004
@@ -1,6 +1,22 @@
 
 /* Pointer arithmetic utility functions */
 
+int read_int(char *buf, int offset) {
+  return *(int*)(buf + offset);
+}
+
+unsigned int read_uint(char *buf, int offset) {
+  return *(unsigned int*)(buf + offset);
+}
+
+float read_float(char *buf, int offset) {
+  return *(float*)(buf + offset);
+}
+
+double read_double(char *buf, int offset) {
+  return *(double*)(buf + offset);
+}
+
 void write_int(char *buf, int num, int offset) {
   *(int*)(buf + offset) = num;
 }
@@ -9,20 +25,16 @@
   *(unsigned int*)(buf + offset) = num;
 }
 
-void write_double(char *buf, double num, int offset) {
-  *(double*)(buf + offset) = num;
+void write_float(char *buf, float num, int offset) {
+  *(float*)(buf + offset) = num;
 }
 
-int read_int(char *buf, int offset) {
-  return *(int*)(buf + offset);
-}
-
-unsigned int read_uint(char *buf, int offset) {
-  return *(unsigned int*)(buf + offset);
+void write_double(char *buf, double num, int offset) {
+  *(double*)(buf + offset) = num;
 }
 
-double read_double(char *buf, int offset) {
-  return *(double*)(buf + offset);
+char *offset_charp(char *p, int offset) {
+  return p + offset;
 }
 
 #include <string.h>
@@ -76,6 +88,13 @@
   return env->remove(env, home, flags);
 }
 
+int db_env_set_flags(DB_ENV *dbenv, u_int32_t flags, int onoff) {
+  return dbenv->set_flags(dbenv, flags, onoff);
+}
+
+int db_env_get_flags(DB_ENV *dbenv, u_int32_t *flagsp) {
+  return dbenv->get_flags(dbenv, flagsp);
+}
 
 /* Database */
 
@@ -111,9 +130,16 @@
   return db->truncate(db, txnid, countp, flags);
 }
 
+int db_set_pagesize(DB *db, u_int32_t pagesize) {
+  return db->set_pagesize(db, pagesize);
+}
+
+int db_get_pagesize(DB *db, u_int32_t *pagesizep) {
+  return db->get_pagesize(db, pagesizep);
+}
 
 /* Accessors */
-/* Should also make versions which support bulk retrieval */
+/* We manage our own buffers (DB_DBT_USERMEM). */
 
 int db_get_raw(DB *db, DB_TXN *txnid, 
 	       char *key, u_int32_t key_length,
@@ -128,7 +154,6 @@
   DBTKey.size = key_length;
   DBTDatum.data = buffer;
   DBTDatum.ulen = buffer_length;
-  /* Need this for threaded applications */
   DBTDatum.flags |= DB_DBT_USERMEM;
   
   ret = db->get(db, txnid, &DBTKey, &DBTDatum, flags);
@@ -165,10 +190,113 @@
 }
 
 
+/* Cursors */
+
+DBC * db_cursor(DB *db, DB_TXN *txnid, u_int32_t flags, int *errno) {
+  DBC *cursor;
+  *errno = db->cursor(db, txnid, &cursor, flags);
+  return cursor;
+}
+
+int db_cursor_close(DBC *cursor) {
+  return cursor->c_close(cursor);
+}
+
+int db_cursor_del(DBC *cursor, u_int32_t flags) {
+  return cursor->c_del(cursor, flags);
+}
+
+DBC * db_cursor_dup(DBC *cursor, u_int32_t flags, int *errno) {
+  DBC *dup;
+  *errno = cursor->c_dup(cursor, &dup, flags);
+  return dup;
+}
+
+int db_cursor_get_raw(DBC *cursor, 
+		      char *keybuf, u_int32_t keybuf_length,
+		      char *buffer, u_int32_t buffer_length,
+		      u_int32_t flags, u_int32_t *key_length,
+		      u_int32_t *result_length) {
+  DBT DBTKey, DBTDatum;
+  int ret;
+  
+  memset(&DBTKey, 0, sizeof(DBT));
+  memset(&DBTDatum, 0, sizeof(DBT));
+  DBTKey.data = keybuf;
+  DBTKey.ulen = keybuf_length;
+  DBTKey.flags |= DB_DBT_USERMEM;
+  DBTDatum.data = buffer;
+  DBTDatum.ulen = buffer_length;
+  DBTDatum.flags |= DB_DBT_USERMEM;
+  
+  ret = cursor->c_get(cursor, &DBTKey, &DBTDatum, flags);
+  *key_length = DBTKey.size;
+  *result_length = DBTDatum.size;
+  
+  return ret;
+}
+
+int db_cursor_put_raw(DBC *cursor,
+		      char *key, u_int32_t key_length,
+		      char *datum, u_int32_t datum_length,
+		      u_int32_t flags) {
+  DBT DBTKey, DBTDatum;
+  
+  memset(&DBTKey, 0, sizeof(DBT));
+  memset(&DBTDatum, 0, sizeof(DBT));
+  DBTKey.data = key;
+  DBTKey.size = key_length;
+  DBTDatum.data = datum;
+  DBTDatum.size = datum_length;
+  
+  return cursor->c_put(cursor, &DBTKey, &DBTDatum, flags);
+}
+
+
+/* Bulk retrieval */
+
+int db_cursor_get_multiple_key(DBC *cursor, 
+			       char *keybuf, u_int32_t keybuf_length,
+			       char *buffer, u_int32_t buffer_length,
+			       u_int32_t flags, u_int32_t *key_length,
+			       u_int32_t *result_length,
+			       void **pointer, DBT **data) {
+  DBT DBTKey, DBTDatum;
+  int ret;
+  
+  memset(&DBTKey, 0, sizeof(DBT));
+  memset(&DBTDatum, 0, sizeof(DBT));
+  DBTKey.data = keybuf;
+  DBTKey.ulen = keybuf_length;
+  DBTKey.flags |= DB_DBT_USERMEM;
+  DBTDatum.data = buffer;
+  DBTDatum.ulen = buffer_length;
+  DBTDatum.flags |= DB_DBT_USERMEM;
+  
+  flags |= DB_MULTIPLE_KEY;
+  ret = cursor->c_get(cursor, &DBTKey, &DBTDatum, flags);
+  *key_length = DBTKey.size;
+  *result_length = DBTDatum.size;
+  if ((DBTKey.size <= DBTKey.ulen) && (DBTDatum.size <= DBTDatum.ulen)) {
+    **data = DBTDatum;
+    DB_MULTIPLE_INIT(*pointer, *data);
+  }
+				    
+  return ret;
+}
+
+void db_multiple_key_next(void *pointer, DBT *data,
+			  char **key, u_int32_t *key_length,
+			  char **result, u_int32_t *result_length) {
+  DB_MULTIPLE_KEY_NEXT(pointer, data, 
+		       *key, *key_length, 
+		       *result, *result_length);
+}
+
 /* Transactions */
 
-DB_TXN * db_env_txn_begin(DB_ENV *env, DB_TXN *parent, 
-			  u_int32_t flags, int *errno) {
+DB_TXN * db_txn_begin(DB_ENV *env, DB_TXN *parent, 
+		      u_int32_t flags, int *errno) {
   DB_TXN * p;
   *errno = env->txn_begin(env, parent, &p, flags);
   return p;
@@ -182,14 +310,45 @@
   return txnid->commit(txnid, flags);
 }
 
-/*
-int db_env_lock_detect(DB_ENV *env, u_int32_t flags, u_int32_t atype,
-		   int *aborted) {
-    return env->lock_detect(env, flags, atype, aborted);
+
+int db_txnp_begin(DB_ENV *env, DB_TXN *parent, DB_TXN **txnp,
+		 u_int32_t flags) {
+  return env->txn_begin(env, parent, txnp, flags);
+}
+
+/* Locks and timeouts */
+
+u_int32_t db_txn_id(DB_TXN *tid) {
+  return tid->id(tid);
+}
+
+int db_env_lock_id(DB_ENV *env, u_int32_t *idp) {
+  return env->lock_id(env, idp);
+}
+
+int db_env_lock_id_free(DB_ENV *env, u_int32_t id) {
+  return env->lock_id_free(env, id);
+}
+
+/* db_timeout_t = u_int32_t */
+int db_env_set_timeout(DB_ENV *env, db_timeout_t timeout, u_int32_t flags) {
+  return env->set_timeout(env, timeout, flags);
+}
+
+int db_env_get_timeout(DB_ENV *env, db_timeout_t *timeoutp, u_int32_t flags) {
+  return env->get_timeout(env, timeoutp, flags);
 }
 
 int db_env_set_lk_detect(DB_ENV *env, u_int32_t detect) {
     return env->set_lk_detect(env, detect);
 }
 
-*/
+int db_env_get_lk_detect(DB_ENV *env, u_int32_t *detectp) {
+    return env->get_lk_detect(env, detectp);
+}
+
+int db_env_lock_detect(DB_ENV *env, u_int32_t flags, u_int32_t atype,
+		   int *aborted) {
+    return env->lock_detect(env, flags, atype, aborted);
+}
+





More information about the Elephant-cvs mailing list