ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/BDB/BDB.xs
(Generate patch)

Comparing BDB/BDB.xs (file contents):
Revision 1.12 by root, Sun Jul 8 09:16:19 2007 UTC vs.
Revision 1.58 by root, Tue Sep 30 17:03:07 2008 UTC

1#define X_STACKSIZE 1024 * 128 + sizeof (long) * 64 * 1024 / 4
2
1#include "xthread.h" 3#include "xthread.h"
2 4
3#include <errno.h> 5#include <errno.h>
4 6
5#include "EXTERN.h" 7#include "EXTERN.h"
6#include "perl.h" 8#include "perl.h"
7#include "XSUB.h" 9#include "XSUB.h"
8 10
11// perl stupidly defines these as macros, breaking
12// lots and lots of code.
13#undef open
14#undef close
15#undef abort
16#undef malloc
17#undef free
18#undef send
19
9#include <stddef.h> 20#include <stddef.h>
10#include <stdlib.h> 21#include <stdlib.h>
11#include <errno.h> 22#include <errno.h>
12#include <sys/time.h>
13#include <sys/types.h> 23#include <sys/types.h>
14#include <limits.h> 24#include <limits.h>
15#include <unistd.h>
16#include <fcntl.h> 25#include <fcntl.h>
17 26
27#ifndef _WIN32
28# include <sys/time.h>
29# include <unistd.h>
30#endif
31
18#include <db.h> 32#include <db.h>
19 33
20#if DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 5) 34#if DB_VERSION_MAJOR != 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 3)
21# error you need Berkeley DB 4.5 or newer installed 35# error you need Berkeley DB 4.3 or a newer 4.x version installed
22#endif 36#endif
23 37
24/* number of seconds after which idle threads exit */ 38/* number of seconds after which idle threads exit */
25#define IDLE_TIMEOUT 10 39#define IDLE_TIMEOUT 10
40
41typedef SV SV_mutable;
26 42
27typedef DB_ENV DB_ENV_ornull; 43typedef DB_ENV DB_ENV_ornull;
28typedef DB_TXN DB_TXN_ornull; 44typedef DB_TXN DB_TXN_ornull;
29typedef DBC DBC_ornull; 45typedef DBC DBC_ornull;
30typedef DB DB_ornull; 46typedef DB DB_ornull;
47
48typedef DB_ENV DB_ENV_ornuked;
49typedef DB_TXN DB_TXN_ornuked;
50typedef DBC DBC_ornuked;
51typedef DB DB_ornuked;
52
53#if DB_VERSION_MINOR >= 3
31typedef DB_SEQUENCE DB_SEQUENCE_ornull; 54typedef DB_SEQUENCE DB_SEQUENCE_ornull;
55typedef DB_SEQUENCE DB_SEQUENCE_ornuked;
56#endif
32 57
33typedef SV SV8; /* byte-sv, used for argument-checking */ 58typedef SV SV8; /* byte-sv, used for argument-checking */
34typedef char *octetstring; 59typedef char *bdb_filename;
35 60
36static SV *prepare_cb; 61static SV *prepare_cb;
37 62
63#if DB_VERSION_MINOR >= 6
64# define c_close close
65# define c_count count
66# define c_del del
67# define c_dup dup
68# define c_get get
69# define c_pget pget
70# define c_put put
71#endif
72
38static inline char * 73static char *
74get_bdb_filename (SV *sv)
75{
76 if (!SvOK (sv))
77 return 0;
78
79#if _WIN32
80 /* win32 madness + win32 perl absolutely brokenness make for horrible hacks */
81 {
82 STRLEN len;
83 char *src = SvPVbyte (sv, len);
84 SV *t1 = sv_newmortal ();
85 SV *t2 = sv_newmortal ();
86
87 sv_upgrade (t1, SVt_PV); SvPOK_only (t1); SvGROW (t1, len * 16 + 1);
88 sv_upgrade (t2, SVt_PV); SvPOK_only (t2); SvGROW (t2, len * 16 + 1);
89
90 len = MultiByteToWideChar (CP_ACP, 0, src, len, (WCHAR *)SvPVX (t1), SvLEN (t1) / sizeof (WCHAR));
91 len = WideCharToMultiByte (CP_UTF8, 0, (WCHAR *)SvPVX (t1), len, SvPVX (t2), SvLEN (t2), 0, 0);
92 SvPOK_only (t2);
93 SvPVX (t2)[len] = 0;
94 SvCUR_set (t2, len);
95
96 return SvPVX (t2);
97 }
98#else
99 return SvPVbyte_nolen (sv);
100#endif
101}
102
103static void
104debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg)
105{
106 printf ("err[%s]\n", msg);
107}
108
109static void
110debug_msgcall (const DB_ENV *dbenv, const char *msg)
111{
112 printf ("msg[%s]\n", msg);
113}
114
115static char *
39strdup_ornull (const char *s) 116strdup_ornull (const char *s)
40{ 117{
41 return s ? strdup (s) : 0; 118 return s ? strdup (s) : 0;
42} 119}
43 120
44static inline void 121static void
45sv_to_dbt (DBT *dbt, SV *sv) 122sv_to_dbt (DBT *dbt, SV *sv)
46{ 123{
47 STRLEN len; 124 STRLEN len;
48 char *data = SvPVbyte (sv, len); 125 char *data = SvPVbyte (sv, len);
49 126
51 memcpy (dbt->data, data, len); 128 memcpy (dbt->data, data, len);
52 dbt->size = len; 129 dbt->size = len;
53 dbt->flags = DB_DBT_REALLOC; 130 dbt->flags = DB_DBT_REALLOC;
54} 131}
55 132
56static inline void 133static void
57dbt_to_sv (SV *sv, DBT *dbt) 134dbt_to_sv (SV *sv, DBT *dbt)
58{ 135{
59 if (sv) 136 if (sv)
60 { 137 {
61 SvREADONLY_off (sv); 138 SvREADONLY_off (sv);
139
140 if (dbt->data)
62 sv_setpvn_mg (sv, dbt->data, dbt->size); 141 sv_setpvn_mg (sv, dbt->data, dbt->size);
142 else
143 sv_setsv_mg (sv, &PL_sv_undef);
144
63 SvREFCNT_dec (sv); 145 SvREFCNT_dec (sv);
64 } 146 }
65 147
66 free (dbt->data); 148 free (dbt->data);
67} 149}
68 150
69enum { 151enum {
70 REQ_QUIT, 152 REQ_QUIT,
71 REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, 153 REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT,
72 REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, 154 REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME,
73 REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, 155 REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE,
74 REQ_DB_PUT, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, 156 REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE,
75 REQ_TXN_COMMIT, REQ_TXN_ABORT, 157 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH,
76 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, 158 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL,
77 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, 159 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE,
78}; 160};
79 161
80typedef struct aio_cb 162typedef struct bdb_cb
81{ 163{
82 struct aio_cb *volatile next; 164 struct bdb_cb *volatile next;
83 SV *callback; 165 SV *callback;
84 int type, pri, result; 166 int type, pri, result;
85 167
86 DB_ENV *env; 168 DB_ENV *env;
87 DB *db; 169 DB *db;
89 DBC *dbc; 171 DBC *dbc;
90 172
91 UV uv1; 173 UV uv1;
92 int int1, int2; 174 int int1, int2;
93 U32 uint1, uint2; 175 U32 uint1, uint2;
94 char *buf1, *buf2; 176 char *buf1, *buf2, *buf3;
95 SV *sv1, *sv2, *sv3; 177 SV *sv1, *sv2, *sv3;
96 178
97 DBT dbt1, dbt2, dbt3; 179 DBT dbt1, dbt2, dbt3;
98 DB_KEY_RANGE key_range; 180 DB_KEY_RANGE key_range;
181#if DB_VERSION_MINOR >= 3
99 DB_SEQUENCE *seq; 182 DB_SEQUENCE *seq;
100 db_seq_t seq_t; 183 db_seq_t seq_t;
101} aio_cb; 184#endif
102 185
186 SV *rsv1, *rsv2; // keep some request objects alive
187} bdb_cb;
188
103typedef aio_cb *aio_req; 189typedef bdb_cb *bdb_req;
104 190
105enum { 191enum {
106 PRI_MIN = -4, 192 PRI_MIN = -4,
107 PRI_MAX = 4, 193 PRI_MAX = 4,
108 194
111 NUM_PRI = PRI_MAX + PRI_BIAS + 1, 197 NUM_PRI = PRI_MAX + PRI_BIAS + 1,
112}; 198};
113 199
114#define AIO_TICKS ((1000000 + 1023) >> 10) 200#define AIO_TICKS ((1000000 + 1023) >> 10)
115 201
202static SV *on_next_submit;
203
116static unsigned int max_poll_time = 0; 204static unsigned int max_poll_time = 0;
117static unsigned int max_poll_reqs = 0; 205static unsigned int max_poll_reqs = 0;
118 206
119/* calculcate time difference in ~1/AIO_TICKS of a second */ 207/* calculcate time difference in ~1/AIO_TICKS of a second */
120static int tvdiff (struct timeval *tv1, struct timeval *tv2) 208static int tvdiff (struct timeval *tv1, struct timeval *tv2)
135 struct worker *prev, *next; 223 struct worker *prev, *next;
136 224
137 thread_t tid; 225 thread_t tid;
138 226
139 /* locked by reslock, reqlock or wrklock */ 227 /* locked by reslock, reqlock or wrklock */
140 aio_req req; /* currently processed request */ 228 bdb_req req; /* currently processed request */
141 void *dbuf; 229 void *dbuf;
142 DIR *dirp; 230 DIR *dirp;
143} worker; 231} worker;
144 232
145static worker wrk_first = { &wrk_first, &wrk_first, 0 }; 233static worker wrk_first = { &wrk_first, &wrk_first, 0 };
157} 245}
158 246
159static volatile unsigned int nreqs, nready, npending; 247static volatile unsigned int nreqs, nready, npending;
160static volatile unsigned int max_idle = 4; 248static volatile unsigned int max_idle = 4;
161static volatile unsigned int max_outstanding = 0xffffffff; 249static volatile unsigned int max_outstanding = 0xffffffff;
162static int respipe [2]; 250static int respipe_osf [2], respipe [2] = { -1, -1 };
163 251
164static mutex_t reslock = X_MUTEX_INIT; 252static mutex_t reslock = X_MUTEX_INIT;
165static mutex_t reqlock = X_MUTEX_INIT; 253static mutex_t reqlock = X_MUTEX_INIT;
166static cond_t reqwait = X_COND_INIT; 254static cond_t reqwait = X_COND_INIT;
167 255
168#if WORDACCESS_UNSAFE 256#if WORDACCESS_UNSAFE
169 257
170static unsigned int get_nready () 258static unsigned int get_nready (void)
171{ 259{
172 unsigned int retval; 260 unsigned int retval;
173 261
174 X_LOCK (reqlock); 262 X_LOCK (reqlock);
175 retval = nready; 263 retval = nready;
176 X_UNLOCK (reqlock); 264 X_UNLOCK (reqlock);
177 265
178 return retval; 266 return retval;
179} 267}
180 268
181static unsigned int get_npending () 269static unsigned int get_npending (void)
182{ 270{
183 unsigned int retval; 271 unsigned int retval;
184 272
185 X_LOCK (reslock); 273 X_LOCK (reslock);
186 retval = npending; 274 retval = npending;
187 X_UNLOCK (reslock); 275 X_UNLOCK (reslock);
188 276
189 return retval; 277 return retval;
190} 278}
191 279
192static unsigned int get_nthreads () 280static unsigned int get_nthreads (void)
193{ 281{
194 unsigned int retval; 282 unsigned int retval;
195 283
196 X_LOCK (wrklock); 284 X_LOCK (wrklock);
197 retval = started; 285 retval = started;
212 * a somewhat faster data structure might be nice, but 300 * a somewhat faster data structure might be nice, but
213 * with 8 priorities this actually needs <20 insns 301 * with 8 priorities this actually needs <20 insns
214 * per shift, the most expensive operation. 302 * per shift, the most expensive operation.
215 */ 303 */
216typedef struct { 304typedef struct {
217 aio_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */ 305 bdb_req qs[NUM_PRI], qe[NUM_PRI]; /* qstart, qend */
218 int size; 306 int size;
219} reqq; 307} reqq;
220 308
221static reqq req_queue; 309static reqq req_queue;
222static reqq res_queue; 310static reqq res_queue;
223 311
224int reqq_push (reqq *q, aio_req req) 312int reqq_push (reqq *q, bdb_req req)
225{ 313{
226 int pri = req->pri; 314 int pri = req->pri;
227 req->next = 0; 315 req->next = 0;
228 316
229 if (q->qe[pri]) 317 if (q->qe[pri])
235 q->qe[pri] = q->qs[pri] = req; 323 q->qe[pri] = q->qs[pri] = req;
236 324
237 return q->size++; 325 return q->size++;
238} 326}
239 327
240aio_req reqq_shift (reqq *q) 328bdb_req reqq_shift (reqq *q)
241{ 329{
242 int pri; 330 int pri;
243 331
244 if (!q->size) 332 if (!q->size)
245 return 0; 333 return 0;
246 334
247 --q->size; 335 --q->size;
248 336
249 for (pri = NUM_PRI; pri--; ) 337 for (pri = NUM_PRI; pri--; )
250 { 338 {
251 aio_req req = q->qs[pri]; 339 bdb_req req = q->qs[pri];
252 340
253 if (req) 341 if (req)
254 { 342 {
255 if (!(q->qs[pri] = req->next)) 343 if (!(q->qs[pri] = req->next))
256 q->qe[pri] = 0; 344 q->qe[pri] = 0;
260 } 348 }
261 349
262 abort (); 350 abort ();
263} 351}
264 352
265static int poll_cb (); 353static int poll_cb (void);
266static void req_free (aio_req req); 354static void req_free (bdb_req req);
267static void req_cancel (aio_req req);
268 355
269static int req_invoke (aio_req req) 356static int req_invoke (bdb_req req)
270{ 357{
271 dSP; 358 switch (req->type)
272
273 if (SvOK (req->callback))
274 { 359 {
360 case REQ_DB_CLOSE:
361 SvREFCNT_dec (req->sv1);
362 break;
363
364 case REQ_DB_GET:
365 case REQ_DB_PGET:
366 case REQ_C_GET:
367 case REQ_C_PGET:
368 case REQ_DB_PUT:
369 case REQ_C_PUT:
370 dbt_to_sv (req->sv1, &req->dbt1);
371 dbt_to_sv (req->sv2, &req->dbt2);
372 dbt_to_sv (req->sv3, &req->dbt3);
373 break;
374
375 case REQ_DB_KEY_RANGE:
376 {
377 AV *av = newAV ();
378
379 av_push (av, newSVnv (req->key_range.less));
380 av_push (av, newSVnv (req->key_range.equal));
381 av_push (av, newSVnv (req->key_range.greater));
382
383 SvREADONLY_off (req->sv1);
384 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av));
385 SvREFCNT_dec (req->sv1);
386 }
387 break;
388
389#if DB_VERSION_MINOR >= 3
390 case REQ_SEQ_GET:
391 SvREADONLY_off (req->sv1);
392
393 if (sizeof (IV) > 4)
394 sv_setiv_mg (req->sv1, (IV)req->seq_t);
395 else
396 sv_setnv_mg (req->sv1, (NV)req->seq_t);
397
398 SvREFCNT_dec (req->sv1);
399 break;
400#endif
401 }
402
403 errno = req->result;
404
405 if (req->callback)
406 {
407 dSP;
408
275 ENTER; 409 ENTER;
276 SAVETMPS; 410 SAVETMPS;
277 PUSHMARK (SP); 411 PUSHMARK (SP);
278 412
279 switch (req->type)
280 {
281 case REQ_DB_CLOSE:
282 SvREFCNT_dec (req->sv1);
283 break;
284
285 case REQ_DB_GET:
286 case REQ_DB_PGET:
287 dbt_to_sv (req->sv3, &req->dbt3);
288 break;
289
290 case REQ_C_GET:
291 case REQ_C_PGET:
292 dbt_to_sv (req->sv1, &req->dbt1);
293 dbt_to_sv (req->sv2, &req->dbt2);
294 dbt_to_sv (req->sv3, &req->dbt3);
295 break;
296
297 case REQ_DB_KEY_RANGE:
298 {
299 AV *av = newAV ();
300
301 av_push (av, newSVnv (req->key_range.less));
302 av_push (av, newSVnv (req->key_range.equal));
303 av_push (av, newSVnv (req->key_range.greater));
304
305 SvREADONLY_off (req->sv1);
306 sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av));
307 SvREFCNT_dec (req->sv1);
308 }
309 break;
310
311 case REQ_SEQ_GET:
312 SvREADONLY_off (req->sv1);
313
314 if (sizeof (IV) > 4)
315 sv_setiv_mg (req->sv1, req->seq_t);
316 else
317 sv_setnv_mg (req->sv1, req->seq_t);
318
319 SvREFCNT_dec (req->sv1);
320 break;
321 }
322
323 errno = req->result;
324
325 PUTBACK; 413 PUTBACK;
326 call_sv (req->callback, G_VOID | G_EVAL); 414 call_sv (req->callback, G_VOID | G_EVAL);
327 SPAGAIN; 415 SPAGAIN;
328 416
329 FREETMPS; 417 FREETMPS;
330 LEAVE; 418 LEAVE;
419
420 return !SvTRUE (ERRSV);
331 } 421 }
332 422
333 return !SvTRUE (ERRSV); 423 return 1;
334} 424}
335 425
336static void req_free (aio_req req) 426static void req_free (bdb_req req)
337{ 427{
428 SvREFCNT_dec (req->callback);
429
430 SvREFCNT_dec (req->rsv1);
431 SvREFCNT_dec (req->rsv2);
432
338 free (req->buf1); 433 free (req->buf1);
339 free (req->buf2); 434 free (req->buf2);
435 free (req->buf3);
436
340 Safefree (req); 437 Safefree (req);
341} 438}
342 439
343static void *aio_proc (void *arg); 440#ifdef USE_SOCKETS_AS_HANDLES
441# define TO_SOCKET(x) (win32_get_osfhandle (x))
442#else
443# define TO_SOCKET(x) (x)
444#endif
445
446static void
447create_respipe (void)
448{
449#ifdef _WIN32
450 int arg; /* argg */
451#endif
452 int old_readfd = respipe [0];
453
454 if (respipe [1] >= 0)
455 respipe_close (TO_SOCKET (respipe [1]));
456
457#ifdef _WIN32
458 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe))
459#else
460 if (pipe (respipe))
461#endif
462 croak ("unable to initialize result pipe");
463
464 if (old_readfd >= 0)
465 {
466 if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0)
467 croak ("unable to initialize result pipe(2)");
468
469 respipe_close (respipe [0]);
470 respipe [0] = old_readfd;
471 }
472
473#ifdef _WIN32
474 arg = 1;
475 if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg)
476 || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg))
477#else
478 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
479 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
480#endif
481 croak ("unable to initialize result pipe(3)");
482
483 respipe_osf [0] = TO_SOCKET (respipe [0]);
484 respipe_osf [1] = TO_SOCKET (respipe [1]);
485}
486
487static void bdb_request (bdb_req req);
488X_THREAD_PROC (bdb_proc);
344 489
345static void start_thread (void) 490static void start_thread (void)
346{ 491{
347 worker *wrk = calloc (1, sizeof (worker)); 492 worker *wrk = calloc (1, sizeof (worker));
348 493
349 if (!wrk) 494 if (!wrk)
350 croak ("unable to allocate worker thread data"); 495 croak ("unable to allocate worker thread data");
351 496
352 X_LOCK (wrklock); 497 X_LOCK (wrklock);
353 if (thread_create (&wrk->tid, aio_proc, (void *)wrk)) 498 if (thread_create (&wrk->tid, bdb_proc, (void *)wrk))
354 { 499 {
355 wrk->prev = &wrk_first; 500 wrk->prev = &wrk_first;
356 wrk->next = wrk_first.next; 501 wrk->next = wrk_first.next;
357 wrk_first.next->prev = wrk; 502 wrk_first.next->prev = wrk;
358 wrk_first.next = wrk; 503 wrk_first.next = wrk;
362 free (wrk); 507 free (wrk);
363 508
364 X_UNLOCK (wrklock); 509 X_UNLOCK (wrklock);
365} 510}
366 511
367static void maybe_start_thread () 512static void maybe_start_thread (void)
368{ 513{
369 if (get_nthreads () >= wanted) 514 if (get_nthreads () >= wanted)
370 return; 515 return;
371 516
372 /* todo: maybe use idle here, but might be less exact */ 517 /* todo: maybe use idle here, but might be less exact */
374 return; 519 return;
375 520
376 start_thread (); 521 start_thread ();
377} 522}
378 523
379static void req_send (aio_req req) 524static void req_send (bdb_req req)
380{ 525{
381 SV *wait_callback = 0; 526 SV *wait_callback = 0;
382 527
383 // synthesize callback if none given 528 if (on_next_submit)
384 if (!SvOK (req->callback))
385 { 529 {
386 dSP; 530 dSP;
531 SV *cb = sv_2mortal (on_next_submit);
532
533 on_next_submit = 0;
534
387 PUSHMARK (SP); 535 PUSHMARK (SP);
388 PUTBACK; 536 PUTBACK;
389 int count = call_sv (prepare_cb, G_ARRAY); 537 call_sv (cb, G_DISCARD | G_EVAL);
390 SPAGAIN; 538 SPAGAIN;
539 }
391 540
541 // synthesize callback if none given
542 if (!req->callback)
543 {
544 if (SvOK (prepare_cb))
545 {
546 int count;
547
548 dSP;
549 PUSHMARK (SP);
550 PUTBACK;
551 count = call_sv (prepare_cb, G_ARRAY);
552 SPAGAIN;
553
392 if (count != 2) 554 if (count != 2)
393 croak ("prepare callback must return exactly two values\n"); 555 croak ("sync prepare callback must return exactly two values\n");
394 556
395 wait_callback = SvREFCNT_inc (POPs); 557 wait_callback = POPs;
396 SvREFCNT_dec (req->callback);
397 req->callback = SvREFCNT_inc (POPs); 558 req->callback = SvREFCNT_inc (POPs);
559 }
560 else
561 {
562 // execute request synchronously
563 bdb_request (req);
564 req_invoke (req);
565 req_free (req);
566 return;
567 }
398 } 568 }
399 569
400 ++nreqs; 570 ++nreqs;
401 571
402 X_LOCK (reqlock); 572 X_LOCK (reqlock);
411 { 581 {
412 dSP; 582 dSP;
413 PUSHMARK (SP); 583 PUSHMARK (SP);
414 PUTBACK; 584 PUTBACK;
415 call_sv (wait_callback, G_DISCARD); 585 call_sv (wait_callback, G_DISCARD);
416 SvREFCNT_dec (wait_callback);
417 } 586 }
418} 587}
419 588
420static void end_thread (void) 589static void end_thread (void)
421{ 590{
422 aio_req req; 591 bdb_req req = calloc (1, sizeof (bdb_cb));
423
424 Newz (0, req, 1, aio_cb);
425 592
426 req->type = REQ_QUIT; 593 req->type = REQ_QUIT;
427 req->pri = PRI_MAX + PRI_BIAS; 594 req->pri = PRI_MAX + PRI_BIAS;
428 595
429 X_LOCK (reqlock); 596 X_LOCK (reqlock);
456 623
457 while (started > wanted) 624 while (started > wanted)
458 end_thread (); 625 end_thread ();
459} 626}
460 627
461static void poll_wait () 628static void poll_wait (void)
462{ 629{
463 fd_set rfd; 630 fd_set rfd;
464 631
465 while (nreqs) 632 while (nreqs)
466 { 633 {
472 if (size) 639 if (size)
473 return; 640 return;
474 641
475 maybe_start_thread (); 642 maybe_start_thread ();
476 643
477 FD_ZERO(&rfd); 644 FD_ZERO (&rfd);
478 FD_SET(respipe [0], &rfd); 645 FD_SET (respipe [0], &rfd);
479 646
480 select (respipe [0] + 1, &rfd, 0, 0, 0); 647 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
481 } 648 }
482} 649}
483 650
484static int poll_cb () 651static int poll_cb (void)
485{ 652{
486 dSP; 653 dSP;
487 int count = 0; 654 int count = 0;
488 int maxreqs = max_poll_reqs; 655 int maxreqs = max_poll_reqs;
489 int do_croak = 0; 656 int do_croak = 0;
490 struct timeval tv_start, tv_now; 657 struct timeval tv_start, tv_now;
491 aio_req req; 658 bdb_req req;
492 659
493 if (max_poll_time) 660 if (max_poll_time)
494 gettimeofday (&tv_start, 0); 661 gettimeofday (&tv_start, 0);
495 662
496 for (;;) 663 for (;;)
508 675
509 if (!res_queue.size) 676 if (!res_queue.size)
510 { 677 {
511 /* read any signals sent by the worker threads */ 678 /* read any signals sent by the worker threads */
512 char buf [4]; 679 char buf [4];
513 while (read (respipe [0], buf, 4) == 4) 680 while (respipe_read (respipe [0], buf, 4) == 4)
514 ; 681 ;
515 } 682 }
516 } 683 }
517 684
518 X_UNLOCK (reslock); 685 X_UNLOCK (reslock);
555 return count; 722 return count;
556} 723}
557 724
558/*****************************************************************************/ 725/*****************************************************************************/
559 726
560static void *aio_proc (void *thr_arg) 727static void
728bdb_request (bdb_req req)
561{ 729{
730 switch (req->type)
731 {
732 case REQ_ENV_OPEN:
733 req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1);
734 break;
735
736 case REQ_ENV_CLOSE:
737 req->result = req->env->close (req->env, req->uint1);
738 break;
739
740 case REQ_ENV_TXN_CHECKPOINT:
741 req->result = req->env->txn_checkpoint (req->env, req->uint1, req->int1, req->uint2);
742 break;
743
744 case REQ_ENV_LOCK_DETECT:
745 req->result = req->env->lock_detect (req->env, req->uint1, req->uint2, &req->int1);
746 break;
747
748 case REQ_ENV_MEMP_SYNC:
749 req->result = req->env->memp_sync (req->env, 0);
750 break;
751
752 case REQ_ENV_MEMP_TRICKLE:
753 req->result = req->env->memp_trickle (req->env, req->int1, &req->int2);
754 break;
755
756 case REQ_ENV_DBREMOVE:
757 req->result = req->env->dbremove (req->env, req->txn, req->buf1, req->buf2, req->uint1);
758 break;
759
760 case REQ_ENV_DBRENAME:
761 req->result = req->env->dbrename (req->env, req->txn, req->buf1, req->buf2, req->buf3, req->uint1);
762 break;
763
764 case REQ_DB_OPEN:
765 req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2);
766 break;
767
768 case REQ_DB_CLOSE:
769 req->result = req->db->close (req->db, req->uint1);
770 break;
771
772#if DB_VERSION_MINOR >= 4
773 case REQ_DB_COMPACT:
774 req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0);
775 break;
776#endif
777
778 case REQ_DB_SYNC:
779 req->result = req->db->sync (req->db, req->uint1);
780 break;
781
782 case REQ_DB_UPGRADE:
783 req->result = req->db->upgrade (req->db, req->buf1, req->uint1);
784 break;
785
786 case REQ_DB_PUT:
787 req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1);
788 break;
789
790#if DB_VERSION_MINOR >= 6
791 case REQ_DB_EXISTS:
792 req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1);
793 break;
794#endif
795 case REQ_DB_GET:
796 req->result = req->db->get (req->db, req->txn, &req->dbt1, &req->dbt3, req->uint1);
797 break;
798
799 case REQ_DB_PGET:
800 req->result = req->db->pget (req->db, req->txn, &req->dbt1, &req->dbt2, &req->dbt3, req->uint1);
801 break;
802
803 case REQ_DB_DEL:
804 req->result = req->db->del (req->db, req->txn, &req->dbt1, req->uint1);
805 break;
806
807 case REQ_DB_KEY_RANGE:
808 req->result = req->db->key_range (req->db, req->txn, &req->dbt1, &req->key_range, req->uint1);
809 break;
810
811 case REQ_TXN_COMMIT:
812 req->result = req->txn->commit (req->txn, req->uint1);
813 break;
814
815 case REQ_TXN_ABORT:
816 req->result = req->txn->abort (req->txn);
817 break;
818
819 case REQ_TXN_FINISH:
820 if (req->txn->flags & TXN_DEADLOCK)
821 {
822 req->result = req->txn->abort (req->txn);
823 if (!req->result)
824 req->result = DB_LOCK_DEADLOCK;
825 }
826 else
827 req->result = req->txn->commit (req->txn, req->uint1);
828 break;
829
830 case REQ_C_CLOSE:
831 req->result = req->dbc->c_close (req->dbc);
832 break;
833
834 case REQ_C_COUNT:
835 {
836 db_recno_t recno;
837 req->result = req->dbc->c_count (req->dbc, &recno, req->uint1);
838 req->uv1 = recno;
839 }
840 break;
841
842 case REQ_C_PUT:
843 req->result = req->dbc->c_put (req->dbc, &req->dbt1, &req->dbt2, req->uint1);
844 break;
845
846 case REQ_C_GET:
847 req->result = req->dbc->c_get (req->dbc, &req->dbt1, &req->dbt3, req->uint1);
848 break;
849
850 case REQ_C_PGET:
851 req->result = req->dbc->c_pget (req->dbc, &req->dbt1, &req->dbt2, &req->dbt3, req->uint1);
852 break;
853
854 case REQ_C_DEL:
855 req->result = req->dbc->c_del (req->dbc, req->uint1);
856 break;
857
858#if DB_VERSION_MINOR >= 3
859 case REQ_SEQ_OPEN:
860 req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1);
861 break;
862
863 case REQ_SEQ_CLOSE:
864 req->result = req->seq->close (req->seq, req->uint1);
865 break;
866
867 case REQ_SEQ_GET:
868 req->result = req->seq->get (req->seq, req->txn, req->int1, &req->seq_t, req->uint1);
869 break;
870
871 case REQ_SEQ_REMOVE:
872 req->result = req->seq->remove (req->seq, req->txn, req->uint1);
873 break;
874#endif
875
876 default:
877 req->result = ENOSYS;
878 break;
879 }
880
881 if (req->txn && (req->result > 0 || req->result == DB_LOCK_NOTGRANTED))
882 req->txn->flags |= TXN_DEADLOCK;
883}
884
885X_THREAD_PROC (bdb_proc)
886{
562 aio_req req; 887 bdb_req req;
563 struct timespec ts; 888 struct timespec ts;
564 worker *self = (worker *)thr_arg; 889 worker *self = (worker *)thr_arg;
565 890
566 /* try to distribute timeouts somewhat evenly */ 891 /* try to distribute timeouts somewhat evenly */
567 ts.tv_nsec = (((unsigned long)self + (unsigned long)ts.tv_sec) & 1023UL) 892 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
568 * (1000000000UL / 1024UL);
569 893
570 for (;;) 894 for (;;)
571 { 895 {
572 ts.tv_sec = time (0) + IDLE_TIMEOUT; 896 ts.tv_sec = time (0) + IDLE_TIMEOUT;
573 897
604 } 928 }
605 929
606 --nready; 930 --nready;
607 931
608 X_UNLOCK (reqlock); 932 X_UNLOCK (reqlock);
609 933
610 switch (req->type) 934 if (req->type == REQ_QUIT)
611 { 935 {
612 case REQ_QUIT: 936 X_LOCK (reslock);
937 free (req);
938 self->req = 0;
939 X_UNLOCK (reslock);
940
613 goto quit; 941 goto quit;
614
615 case REQ_ENV_OPEN:
616 req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1);
617 break;
618
619 case REQ_ENV_CLOSE:
620 req->result = req->env->close (req->env, req->uint1);
621 break;
622
623 case REQ_ENV_TXN_CHECKPOINT:
624 req->result = req->env->txn_checkpoint (req->env, req->uint1, req->int1, req->uint2);
625 break;
626
627 case REQ_ENV_LOCK_DETECT:
628 req->result = req->env->lock_detect (req->env, req->uint1, req->uint2, &req->int1);
629 break;
630
631 case REQ_ENV_MEMP_SYNC:
632 req->result = req->env->memp_sync (req->env, 0);
633 break;
634
635 case REQ_ENV_MEMP_TRICKLE:
636 req->result = req->env->memp_trickle (req->env, req->int1, &req->int2);
637 break;
638
639 case REQ_DB_OPEN:
640 req->result = req->db->open (req->db, req->txn, req->buf1, req->buf2, req->int1, req->uint1, req->int2);
641 break;
642
643 case REQ_DB_CLOSE:
644 req->result = req->db->close (req->db, req->uint1);
645 break;
646
647 case REQ_DB_COMPACT:
648 req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0);
649 break;
650
651 case REQ_DB_SYNC:
652 req->result = req->db->sync (req->db, req->uint1);
653 break;
654
655 case REQ_DB_PUT:
656 req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1);
657 break;
658
659 case REQ_DB_GET:
660 req->result = req->db->get (req->db, req->txn, &req->dbt1, &req->dbt3, req->uint1);
661 break;
662
663 case REQ_DB_PGET:
664 req->result = req->db->pget (req->db, req->txn, &req->dbt1, &req->dbt2, &req->dbt3, req->uint1);
665 break;
666
667 case REQ_DB_DEL:
668 req->result = req->db->del (req->db, req->txn, &req->dbt1, req->uint1);
669 break;
670
671 case REQ_DB_KEY_RANGE:
672 req->result = req->db->key_range (req->db, req->txn, &req->dbt1, &req->key_range, req->uint1);
673 break;
674
675 case REQ_TXN_COMMIT:
676 req->result = req->txn->commit (req->txn, req->uint1);
677 break;
678
679 case REQ_TXN_ABORT:
680 req->result = req->txn->abort (req->txn);
681 break;
682
683 case REQ_C_CLOSE:
684 req->result = req->dbc->c_close (req->dbc);
685 break;
686
687 case REQ_C_COUNT:
688 {
689 db_recno_t recno;
690 req->result = req->dbc->c_count (req->dbc, &recno, req->uint1);
691 req->uv1 = recno;
692 }
693 break;
694
695 case REQ_C_PUT:
696 req->result = req->dbc->c_put (req->dbc, &req->dbt1, &req->dbt2, req->uint1);
697 break;
698
699 case REQ_C_GET:
700 req->result = req->dbc->c_get (req->dbc, &req->dbt1, &req->dbt3, req->uint1);
701 break;
702
703 case REQ_C_PGET:
704 req->result = req->dbc->c_pget (req->dbc, &req->dbt1, &req->dbt2, &req->dbt3, req->uint1);
705 break;
706
707 case REQ_C_DEL:
708 req->result = req->dbc->c_del (req->dbc, req->uint1);
709 break;
710
711 case REQ_SEQ_OPEN:
712 req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1);
713 break;
714
715 case REQ_SEQ_CLOSE:
716 req->result = req->seq->close (req->seq, req->uint1);
717 break;
718
719 case REQ_SEQ_GET:
720 req->result = req->seq->get (req->seq, req->txn, req->int1, &req->seq_t, req->uint1);
721 break;
722
723 case REQ_SEQ_REMOVE:
724 req->result = req->seq->remove (req->seq, req->txn, req->uint1);
725 break;
726
727 default:
728 req->result = ENOSYS;
729 break;
730 } 942 }
943
944 bdb_request (req);
731 945
732 X_LOCK (reslock); 946 X_LOCK (reslock);
733 947
734 ++npending; 948 ++npending;
735 949
736 if (!reqq_push (&res_queue, req)) 950 if (!reqq_push (&res_queue, req))
737 /* write a dummy byte to the pipe so fh becomes ready */ 951 /* write a dummy byte to the pipe so fh becomes ready */
738 write (respipe [1], &respipe, 1); 952 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1);
739 953
740 self->req = 0; 954 self->req = 0;
741 worker_clear (self); 955 worker_clear (self);
742 956
743 X_UNLOCK (reslock); 957 X_UNLOCK (reslock);
767 X_UNLOCK (wrklock); 981 X_UNLOCK (wrklock);
768} 982}
769 983
770static void atfork_child (void) 984static void atfork_child (void)
771{ 985{
772 aio_req prv; 986 bdb_req prv;
773 987
774 while (prv = reqq_shift (&req_queue)) 988 while (prv = reqq_shift (&req_queue))
775 req_free (prv); 989 req_free (prv);
776 990
777 while (prv = reqq_shift (&res_queue)) 991 while (prv = reqq_shift (&res_queue))
792 idle = 0; 1006 idle = 0;
793 nreqs = 0; 1007 nreqs = 0;
794 nready = 0; 1008 nready = 0;
795 npending = 0; 1009 npending = 0;
796 1010
797 close (respipe [0]); 1011 create_respipe ();
798 close (respipe [1]);
799
800 if (!create_pipe (respipe))
801 croak ("unable to initialize result pipe");
802 1012
803 atfork_parent (); 1013 atfork_parent ();
804} 1014}
805 1015
806#define dREQ(reqtype) \ 1016#define dREQ(reqtype,rsvcnt) \
807 aio_req req; \ 1017 bdb_req req; \
808 int req_pri = next_pri; \ 1018 int req_pri = next_pri; \
809 next_pri = DEFAULT_PRI + PRI_BIAS; \ 1019 next_pri = DEFAULT_PRI + PRI_BIAS; \
810 \ 1020 \
811 if (SvOK (callback) && !SvROK (callback)) \ 1021 if (callback && SvOK (callback)) \
812 croak ("callback must be undef or of reference type"); \ 1022 croak ("callback has illegal type or extra arguments"); \
813 \ 1023 \
814 Newz (0, req, 1, aio_cb); \ 1024 Newz (0, req, 1, bdb_cb); \
815 if (!req) \ 1025 if (!req) \
816 croak ("out of memory during aio_req allocation"); \ 1026 croak ("out of memory during bdb_req allocation"); \
817 \ 1027 \
818 req->callback = newSVsv (callback); \ 1028 req->callback = SvREFCNT_inc (cb); \
819 req->type = (reqtype); \ 1029 req->type = (reqtype); \
820 req->pri = req_pri 1030 req->pri = req_pri; \
1031 if (rsvcnt >= 1) req->rsv1 = SvREFCNT_inc (ST (0)); \
1032 if (rsvcnt >= 2) req->rsv2 = SvREFCNT_inc (ST (1)); \
1033 (void)0;
821 1034
822#define REQ_SEND \ 1035#define REQ_SEND \
823 req_send (req) 1036 req_send (req)
824 1037
825#define SvPTR(var, arg, type, class, nullok) \ 1038#define SvPTR(var, arg, type, class, nullok) \
826 if (!SvOK (arg)) \ 1039 if (!SvOK (arg)) \
827 { \ 1040 { \
828 if (!nullok) \ 1041 if (nullok != 1) \
829 croak (# var " must be a " # class " object, not undef"); \ 1042 croak (# var " must be a " # class " object, not undef"); \
830 \ 1043 \
831 (var) = 0; \ 1044 (var) = 0; \
832 } \ 1045 } \
833 else if (sv_derived_from ((arg), # class)) \ 1046 else if (sv_derived_from ((arg), # class)) \
834 { \ 1047 { \
835 IV tmp = SvIV ((SV*) SvRV (arg)); \ 1048 IV tmp = SvIV ((SV*) SvRV (arg)); \
836 (var) = INT2PTR (type, tmp); \ 1049 (var) = INT2PTR (type, tmp); \
837 if (!var) \ 1050 if (!var && nullok != 2) \
838 croak (# var " is not a valid " # class " object anymore"); \ 1051 croak (# var " is not a valid " # class " object anymore"); \
839 } \ 1052 } \
840 else \ 1053 else \
841 croak (# var " is not of type " # class); \ 1054 croak (# var " is not of type " # class);
842 \ 1055
1056#define ARG_MUTABLE(name) \
1057 if (SvREADONLY (name)) \
1058 croak ("argument " #name " is read-only/constant, but the request requires it to be mutable");
843 1059
844static void 1060static void
845ptr_nuke (SV *sv) 1061ptr_nuke (SV *sv)
846{ 1062{
847 assert (SvROK (sv)); 1063 assert (SvROK (sv));
848 sv_setiv (SvRV (sv), 0); 1064 sv_setiv (SvRV (sv), 0);
849} 1065}
1066
1067static int
1068errno_get (pTHX_ SV *sv, MAGIC *mg)
1069{
1070 if (*mg->mg_ptr == '!') // should always be the case
1071 if (-30999 <= errno && errno <= -30800)
1072 {
1073 sv_setnv (sv, (NV)errno);
1074 sv_setpv (sv, db_strerror (errno));
1075 SvNOK_on (sv); /* what a wonderful hack! */
1076 // ^^^ copied from perl sources
1077 return 0;
1078 }
1079
1080 return PL_vtbl_sv.svt_get (aTHX_ sv, mg);
1081}
1082
1083static MGVTBL vtbl_errno;
1084
1085// this wonderful hack :( patches perl's $! variable to support our errno values
1086static void
1087patch_errno (void)
1088{
1089 SV *sv;
1090 MAGIC *mg;
1091
1092 if (!(sv = get_sv ("!", 1)))
1093 return;
1094
1095 if (!(mg = mg_find (sv, PERL_MAGIC_sv)))
1096 return;
1097
1098 if (mg->mg_virtual != &PL_vtbl_sv)
1099 return;
1100
1101 vtbl_errno = PL_vtbl_sv;
1102 vtbl_errno.svt_get = errno_get;
1103 mg->mg_virtual = &vtbl_errno;
1104}
1105
1106#if __GNUC__ >= 4
1107# define noinline __attribute__ ((noinline))
1108#else
1109# define noinline
1110#endif
1111
1112static noinline SV *
1113pop_callback (I32 *ritems, SV *sv)
1114{
1115 if (SvROK (sv))
1116 {
1117 HV *st;
1118 GV *gvp;
1119 CV *cv;
1120 const char *name;
1121
1122 /* forgive me */
1123 if (SvTYPE (SvRV (sv)) == SVt_PVMG
1124 && (st = SvSTASH (SvRV (sv)))
1125 && (name = HvNAME_get (st))
1126 && (name [0] == 'B' && name [1] == 'D' && name [2] == 'B' && name [3] == ':'))
1127 return 0;
1128
1129 if ((cv = sv_2cv (sv, &st, &gvp, 0)))
1130 {
1131 --*ritems;
1132 return (SV *)cv;
1133 }
1134 }
1135
1136 return 0;
1137}
1138
1139/* stupid windows defines CALLBACK as well */
1140#undef CALLBACK
1141#define CALLBACK SV *cb = pop_callback (&items, ST (items - 1));
850 1142
851MODULE = BDB PACKAGE = BDB 1143MODULE = BDB PACKAGE = BDB
852 1144
853PROTOTYPES: ENABLE 1145PROTOTYPES: ENABLE
854 1146
870 const_iv (INIT_TXN) 1162 const_iv (INIT_TXN)
871 const_iv (RECOVER) 1163 const_iv (RECOVER)
872 const_iv (INIT_TXN) 1164 const_iv (INIT_TXN)
873 const_iv (RECOVER_FATAL) 1165 const_iv (RECOVER_FATAL)
874 const_iv (CREATE) 1166 const_iv (CREATE)
1167 const_iv (RDONLY)
875 const_iv (USE_ENVIRON) 1168 const_iv (USE_ENVIRON)
876 const_iv (USE_ENVIRON_ROOT) 1169 const_iv (USE_ENVIRON_ROOT)
877 const_iv (LOCKDOWN) 1170 const_iv (LOCKDOWN)
878 const_iv (PRIVATE) 1171 const_iv (PRIVATE)
879 const_iv (REGISTER)
880 const_iv (SYSTEM_MEM) 1172 const_iv (SYSTEM_MEM)
881 const_iv (AUTO_COMMIT) 1173 const_iv (AUTO_COMMIT)
882 const_iv (CDB_ALLDB) 1174 const_iv (CDB_ALLDB)
883 const_iv (DIRECT_DB) 1175 const_iv (DIRECT_DB)
884 const_iv (DIRECT_LOG)
885 const_iv (DSYNC_DB)
886 const_iv (DSYNC_LOG)
887 const_iv (LOG_AUTOREMOVE)
888 const_iv (LOG_INMEMORY)
889 const_iv (NOLOCKING) 1176 const_iv (NOLOCKING)
890 const_iv (MULTIVERSION)
891 const_iv (NOMMAP) 1177 const_iv (NOMMAP)
892 const_iv (NOPANIC) 1178 const_iv (NOPANIC)
893 const_iv (OVERWRITE) 1179 const_iv (OVERWRITE)
894 const_iv (PANIC_ENVIRONMENT) 1180 const_iv (PANIC_ENVIRONMENT)
895 const_iv (REGION_INIT) 1181 const_iv (REGION_INIT)
896 const_iv (TIME_NOTGRANTED) 1182 const_iv (TIME_NOTGRANTED)
897 const_iv (TXN_NOSYNC) 1183 const_iv (TXN_NOSYNC)
898 const_iv (TXN_SNAPSHOT) 1184 const_iv (TXN_NOT_DURABLE)
899 const_iv (TXN_WRITE_NOSYNC) 1185 const_iv (TXN_WRITE_NOSYNC)
900 const_iv (WRITECURSOR) 1186 const_iv (WRITECURSOR)
901 const_iv (YIELDCPU) 1187 const_iv (YIELDCPU)
902 const_iv (ENCRYPT_AES) 1188 const_iv (ENCRYPT_AES)
903 const_iv (XA_CREATE) 1189 const_iv (XA_CREATE)
905 const_iv (HASH) 1191 const_iv (HASH)
906 const_iv (QUEUE) 1192 const_iv (QUEUE)
907 const_iv (RECNO) 1193 const_iv (RECNO)
908 const_iv (UNKNOWN) 1194 const_iv (UNKNOWN)
909 const_iv (EXCL) 1195 const_iv (EXCL)
910 const_iv (READ_COMMITTED)
911 const_iv (READ_UNCOMMITTED)
912 const_iv (TRUNCATE) 1196 const_iv (TRUNCATE)
913 const_iv (NOSYNC) 1197 const_iv (NOSYNC)
914 const_iv (CHKSUM) 1198 const_iv (CHKSUM)
915 const_iv (ENCRYPT) 1199 const_iv (ENCRYPT)
916 const_iv (TXN_NOT_DURABLE)
917 const_iv (DUP) 1200 const_iv (DUP)
918 const_iv (DUPSORT) 1201 const_iv (DUPSORT)
919 const_iv (RECNUM) 1202 const_iv (RECNUM)
920 const_iv (RENUMBER) 1203 const_iv (RENUMBER)
921 const_iv (REVSPLITOFF) 1204 const_iv (REVSPLITOFF)
922 const_iv (INORDER)
923 const_iv (CONSUME) 1205 const_iv (CONSUME)
924 const_iv (CONSUME_WAIT) 1206 const_iv (CONSUME_WAIT)
925 const_iv (GET_BOTH) 1207 const_iv (GET_BOTH)
926 const_iv (GET_BOTH_RANGE) 1208 const_iv (GET_BOTH_RANGE)
927 //const_iv (SET_RECNO) 1209 //const_iv (SET_RECNO)
928 //const_iv (MULTIPLE) 1210 //const_iv (MULTIPLE)
929 const_iv (SNAPSHOT) 1211 const_iv (SNAPSHOT)
930 const_iv (JOIN_ITEM) 1212 const_iv (JOIN_ITEM)
1213 const_iv (JOIN_NOSORT)
931 const_iv (RMW) 1214 const_iv (RMW)
932 1215
933 const_iv (NOTFOUND) 1216 const_iv (NOTFOUND)
934 const_iv (KEYEMPTY) 1217 const_iv (KEYEMPTY)
935 const_iv (LOCK_DEADLOCK) 1218 const_iv (LOCK_DEADLOCK)
936 const_iv (LOCK_NOTGRANTED) 1219 const_iv (LOCK_NOTGRANTED)
937 const_iv (RUNRECOVERY) 1220 const_iv (RUNRECOVERY)
938 const_iv (OLD_VERSION) 1221 const_iv (OLD_VERSION)
939 const_iv (REP_HANDLE_DEAD) 1222 const_iv (REP_HANDLE_DEAD)
940 const_iv (REP_LOCKOUT)
941 const_iv (SECONDARY_BAD) 1223 const_iv (SECONDARY_BAD)
942
943 const_iv (FREE_SPACE)
944 const_iv (FREELIST_ONLY)
945 1224
946 const_iv (APPEND) 1225 const_iv (APPEND)
947 const_iv (NODUPDATA) 1226 const_iv (NODUPDATA)
948 const_iv (NOOVERWRITE) 1227 const_iv (NOOVERWRITE)
949 1228
950 const_iv (TXN_NOWAIT) 1229 const_iv (TXN_NOWAIT)
951 const_iv (TXN_SNAPSHOT)
952 const_iv (TXN_SYNC) 1230 const_iv (TXN_SYNC)
953 1231
954 const_iv (SET_LOCK_TIMEOUT) 1232 const_iv (SET_LOCK_TIMEOUT)
955 const_iv (SET_TXN_TIMEOUT) 1233 const_iv (SET_TXN_TIMEOUT)
956 1234
957 const_iv (JOIN_ITEM)
958 const_iv (FIRST) 1235 const_iv (FIRST)
959 const_iv (NEXT) 1236 const_iv (NEXT)
960 const_iv (NEXT_DUP) 1237 const_iv (NEXT_DUP)
961 const_iv (NEXT_NODUP) 1238 const_iv (NEXT_NODUP)
962 const_iv (PREV) 1239 const_iv (PREV)
974 const_iv (FORCE) 1251 const_iv (FORCE)
975 1252
976 const_iv (LOCK_DEFAULT) 1253 const_iv (LOCK_DEFAULT)
977 const_iv (LOCK_EXPIRE) 1254 const_iv (LOCK_EXPIRE)
978 const_iv (LOCK_MAXLOCKS) 1255 const_iv (LOCK_MAXLOCKS)
979 const_iv (LOCK_MAXWRITE)
980 const_iv (LOCK_MINLOCKS) 1256 const_iv (LOCK_MINLOCKS)
981 const_iv (LOCK_MINWRITE) 1257 const_iv (LOCK_MINWRITE)
982 const_iv (LOCK_OLDEST) 1258 const_iv (LOCK_OLDEST)
983 const_iv (LOCK_RANDOM) 1259 const_iv (LOCK_RANDOM)
984 const_iv (LOCK_YOUNGEST) 1260 const_iv (LOCK_YOUNGEST)
985 1261
1262 const_iv (DONOTINDEX)
1263 const_iv (KEYEMPTY )
1264 const_iv (KEYEXIST )
1265 const_iv (LOCK_DEADLOCK)
1266 const_iv (LOCK_NOTGRANTED)
1267 const_iv (NOSERVER)
1268 const_iv (NOSERVER_HOME)
1269 const_iv (NOSERVER_ID)
1270 const_iv (NOTFOUND)
1271 const_iv (PAGE_NOTFOUND)
1272 const_iv (REP_DUPMASTER)
1273 const_iv (REP_HANDLE_DEAD)
1274 const_iv (REP_HOLDELECTION)
1275 const_iv (REP_ISPERM)
1276 const_iv (REP_NEWMASTER)
1277 const_iv (REP_NEWSITE)
1278 const_iv (REP_NOTPERM)
1279 const_iv (REP_UNAVAIL)
1280 const_iv (RUNRECOVERY)
1281 const_iv (SECONDARY_BAD)
1282 const_iv (VERIFY_BAD)
1283
1284 const_iv (VERB_DEADLOCK)
1285 const_iv (VERB_RECOVERY)
1286 const_iv (VERB_REPLICATION)
1287 const_iv (VERB_WAITSFOR)
1288
1289 const_iv (VERSION_MAJOR)
1290 const_iv (VERSION_MINOR)
1291 const_iv (VERSION_PATCH)
1292#if DB_VERSION_MINOR >= 3
1293 const_iv (INORDER)
1294 const_iv (LOCK_MAXWRITE)
986 const_iv (SEQ_DEC) 1295 const_iv (SEQ_DEC)
987 const_iv (SEQ_INC) 1296 const_iv (SEQ_INC)
988 const_iv (SEQ_WRAP) 1297 const_iv (SEQ_WRAP)
1298 const_iv (BUFFER_SMALL)
1299 const_iv (LOG_BUFFER_FULL)
1300 const_iv (VERSION_MISMATCH)
1301#endif
1302#if DB_VERSION_MINOR >= 4
1303 const_iv (REGISTER)
1304 const_iv (DSYNC_DB)
1305 const_iv (READ_COMMITTED)
1306 const_iv (READ_UNCOMMITTED)
1307 const_iv (REP_IGNORE)
1308 const_iv (REP_LOCKOUT)
1309 const_iv (REP_JOIN_FAILURE)
1310 const_iv (FREE_SPACE)
1311 const_iv (FREELIST_ONLY)
1312 const_iv (VERB_REGISTER)
1313#endif
1314#if DB_VERSION_MINOR >= 5
1315 const_iv (MULTIVERSION)
1316 const_iv (TXN_SNAPSHOT)
1317#endif
1318#if DB_VERSION_MINOR >= 6
1319 const_iv (PREV_DUP)
1320 const_iv (PRIORITY_UNCHANGED)
1321 const_iv (PRIORITY_VERY_LOW)
1322 const_iv (PRIORITY_LOW)
1323 const_iv (PRIORITY_DEFAULT)
1324 const_iv (PRIORITY_HIGH)
1325 const_iv (PRIORITY_VERY_HIGH)
1326#endif
1327#if DB_VERSION_MINOR >= 7
1328 const_iv (LOG_DIRECT)
1329 const_iv (LOG_DSYNC)
1330 const_iv (LOG_AUTO_REMOVE)
1331 const_iv (LOG_IN_MEMORY)
1332 const_iv (LOG_ZERO)
1333#else
1334 const_iv (DIRECT_LOG)
1335 const_iv (LOG_AUTOREMOVE)
1336# if DB_VERSION_MINOR >= 3
1337 const_iv (DSYNC_LOG)
1338 const_iv (LOG_INMEMORY)
1339# endif
1340#endif
989 }; 1341 };
990 1342
991 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1343 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
992 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1344 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
993 1345
1346 prepare_cb = &PL_sv_undef;
1347
1348 {
1349 /* we currently only allow version, minor-version and patchlevel to go up to 255 */
1350 char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH };
1351
1352 newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3));
1353 }
1354
1355 newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1356
994 if (!create_pipe (respipe)) 1357 create_respipe ();
995 croak ("unable to initialize result pipe");
996 1358
997 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1359 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
998#ifdef _WIN32 1360 patch_errno ();
999 X_MUTEX_CHECK (wrklock);
1000 X_MUTEX_CHECK (reslock);
1001 X_MUTEX_CHECK (reqlock);
1002
1003 X_COND_CHECK (reqwait);
1004#endif
1005} 1361}
1006 1362
1007void 1363void
1008max_poll_reqs (int nreqs) 1364max_poll_reqs (int nreqs)
1009 PROTOTYPE: $ 1365 PROTOTYPE: $
1134 RETVAL = started; 1490 RETVAL = started;
1135 if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock); 1491 if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock);
1136 OUTPUT: 1492 OUTPUT:
1137 RETVAL 1493 RETVAL
1138 1494
1139void 1495SV *
1140set_sync_prepare (SV *cb) 1496set_sync_prepare (SV *cb)
1141 PROTOTYPE: & 1497 PROTOTYPE: &
1142 CODE: 1498 CODE:
1143 SvREFCNT_dec (prepare_cb); 1499 RETVAL = prepare_cb;
1144 prepare_cb = newSVsv (cb); 1500 prepare_cb = newSVsv (cb);
1501 OUTPUT:
1502 RETVAL
1145 1503
1504char *
1505strerror (int errorno = errno)
1506 PROTOTYPE: ;$
1507 CODE:
1508 RETVAL = db_strerror (errorno);
1509 OUTPUT:
1510 RETVAL
1511
1512void _on_next_submit (SV *cb)
1513 CODE:
1514 SvREFCNT_dec (on_next_submit);
1515 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1146 1516
1147DB_ENV * 1517DB_ENV *
1148db_env_create (U32 env_flags = 0) 1518db_env_create (U32 env_flags = 0)
1149 CODE: 1519 CODE:
1150{ 1520{
1151 errno = db_env_create (&RETVAL, env_flags); 1521 errno = db_env_create (&RETVAL, env_flags);
1152 if (errno) 1522 if (errno)
1153 croak ("db_env_create: %s", db_strerror (errno)); 1523 croak ("db_env_create: %s", db_strerror (errno));
1524
1525 if (0)
1526 {
1527 RETVAL->set_errcall (RETVAL, debug_errcall);
1528 RETVAL->set_msgcall (RETVAL, debug_msgcall);
1529 }
1154} 1530}
1155 OUTPUT: 1531 OUTPUT:
1156 RETVAL 1532 RETVAL
1157 1533
1158void 1534void
1159db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) 1535db_env_open (DB_ENV *env, bdb_filename db_home, U32 open_flags, int mode, SV *callback = 0)
1536 PREINIT:
1537 CALLBACK
1160 CODE: 1538 CODE:
1161{ 1539{
1162 env->set_thread_count (env, get_nthreads ());
1163
1164 dREQ (REQ_ENV_OPEN); 1540 dREQ (REQ_ENV_OPEN, 1);
1165 req->env = env; 1541 req->env = env;
1166 req->uint1 = open_flags | DB_THREAD; 1542 req->uint1 = open_flags | DB_THREAD;
1167 req->int1 = mode; 1543 req->int1 = mode;
1168 req->buf1 = strdup_ornull (db_home); 1544 req->buf1 = strdup_ornull (db_home);
1169 REQ_SEND; 1545 REQ_SEND;
1170} 1546}
1171 1547
1172void 1548void
1173db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = &PL_sv_undef) 1549db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0)
1550 PREINIT:
1551 CALLBACK
1174 CODE: 1552 CODE:
1175{ 1553{
1176 dREQ (REQ_ENV_CLOSE); 1554 dREQ (REQ_ENV_CLOSE, 0);
1555 ptr_nuke (ST (0));
1177 req->env = env; 1556 req->env = env;
1178 req->uint1 = flags; 1557 req->uint1 = flags;
1179 REQ_SEND; 1558 REQ_SEND;
1180 ptr_nuke (ST (0));
1181} 1559}
1182 1560
1183void 1561void
1184db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = &PL_sv_undef) 1562db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = 0)
1563 PREINIT:
1564 CALLBACK
1185 CODE: 1565 CODE:
1186{ 1566{
1187 dREQ (REQ_ENV_TXN_CHECKPOINT); 1567 dREQ (REQ_ENV_TXN_CHECKPOINT, 1);
1188 req->env = env; 1568 req->env = env;
1189 req->uint1 = kbyte; 1569 req->uint1 = kbyte;
1190 req->int1 = min; 1570 req->int1 = min;
1191 req->uint2 = flags; 1571 req->uint2 = flags;
1192 REQ_SEND; 1572 REQ_SEND;
1193} 1573}
1194 1574
1195void 1575void
1196db_env_lock_detect (DB_ENV *env, U32 flags = 0, U32 atype = DB_LOCK_DEFAULT, SV *dummy = 0, SV *callback = &PL_sv_undef) 1576db_env_lock_detect (DB_ENV *env, U32 flags = 0, U32 atype = DB_LOCK_DEFAULT, SV *dummy = 0, SV *callback = 0)
1577 PREINIT:
1578 CALLBACK
1197 CODE: 1579 CODE:
1198{ 1580{
1199 dREQ (REQ_ENV_LOCK_DETECT); 1581 dREQ (REQ_ENV_LOCK_DETECT, 1);
1200 req->env = env; 1582 req->env = env;
1201 req->uint1 = flags; 1583 req->uint1 = flags;
1202 req->uint2 = atype; 1584 req->uint2 = atype;
1585 /* req->int2 = 0; dummy */
1203 REQ_SEND; 1586 REQ_SEND;
1204} 1587}
1205 1588
1206void 1589void
1207db_env_memp_sync (DB_ENV *env, SV *dummy = 0, SV *callback = &PL_sv_undef) 1590db_env_memp_sync (DB_ENV *env, SV *dummy = 0, SV *callback = 0)
1591 PREINIT:
1592 CALLBACK
1208 CODE: 1593 CODE:
1209{ 1594{
1210 dREQ (REQ_ENV_MEMP_SYNC); 1595 dREQ (REQ_ENV_MEMP_SYNC, 1);
1211 req->env = env; 1596 req->env = env;
1212 REQ_SEND; 1597 REQ_SEND;
1213} 1598}
1214 1599
1215void 1600void
1216db_env_memp_trickle (DB_ENV *env, int percent, SV *dummy = 0, SV *callback = &PL_sv_undef) 1601db_env_memp_trickle (DB_ENV *env, int percent, SV *dummy = 0, SV *callback = 0)
1602 PREINIT:
1603 CALLBACK
1217 CODE: 1604 CODE:
1218{ 1605{
1219 dREQ (REQ_ENV_MEMP_TRICKLE); 1606 dREQ (REQ_ENV_MEMP_TRICKLE, 1);
1220 req->env = env; 1607 req->env = env;
1221 req->int1 = percent; 1608 req->int1 = percent;
1222 REQ_SEND; 1609 REQ_SEND;
1223} 1610}
1224 1611
1612void
1613db_env_dbremove (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, U32 flags = 0, SV *callback = 0)
1614 PREINIT:
1615 CALLBACK
1616 CODE:
1617{
1618 dREQ (REQ_ENV_DBREMOVE, 2);
1619 req->env = env;
1620 req->buf1 = strdup_ornull (file);
1621 req->buf2 = strdup_ornull (database);
1622 req->uint1 = flags;
1623 REQ_SEND;
1624}
1625
1626void
1627db_env_dbrename (DB_ENV *env, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, bdb_filename newname, U32 flags = 0, SV *callback = 0)
1628 PREINIT:
1629 CALLBACK
1630 CODE:
1631{
1632 dREQ (REQ_ENV_DBRENAME, 2);
1633 req->env = env;
1634 req->buf1 = strdup_ornull (file);
1635 req->buf2 = strdup_ornull (database);
1636 req->buf3 = strdup_ornull (newname);
1637 req->uint1 = flags;
1638 REQ_SEND;
1639}
1225 1640
1226DB * 1641DB *
1227db_create (DB_ENV *env = 0, U32 flags = 0) 1642db_create (DB_ENV *env = 0, U32 flags = 0)
1228 CODE: 1643 CODE:
1229{ 1644{
1236} 1651}
1237 OUTPUT: 1652 OUTPUT:
1238 RETVAL 1653 RETVAL
1239 1654
1240void 1655void
1241db_open (DB *db, DB_TXN_ornull *txnid, octetstring file, octetstring database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef) 1656db_open (DB *db, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, int type, U32 flags, int mode, SV *callback = 0)
1657 PREINIT:
1658 CALLBACK
1242 CODE: 1659 CODE:
1243{ 1660{
1244 dREQ (REQ_DB_OPEN); 1661 dREQ (REQ_DB_OPEN, 2);
1245 req->db = db; 1662 req->db = db;
1246 req->txn = txnid; 1663 req->txn = txnid;
1247 req->buf1 = strdup_ornull (file); 1664 req->buf1 = strdup_ornull (file);
1248 req->buf2 = strdup_ornull (database); 1665 req->buf2 = strdup_ornull (database);
1249 req->int1 = type; 1666 req->int1 = type;
1251 req->int2 = mode; 1668 req->int2 = mode;
1252 REQ_SEND; 1669 REQ_SEND;
1253} 1670}
1254 1671
1255void 1672void
1256db_close (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) 1673db_close (DB *db, U32 flags = 0, SV *callback = 0)
1674 PREINIT:
1675 CALLBACK
1257 CODE: 1676 CODE:
1258{ 1677{
1259 dREQ (REQ_DB_CLOSE); 1678 dREQ (REQ_DB_CLOSE, 0);
1679 ptr_nuke (ST (0));
1260 req->db = db; 1680 req->db = db;
1261 req->uint1 = flags; 1681 req->uint1 = flags;
1262 req->sv1 = (SV *)db->app_private; 1682 req->sv1 = (SV *)db->app_private;
1263 REQ_SEND; 1683 REQ_SEND;
1264 ptr_nuke (ST (0));
1265} 1684}
1266 1685
1686#if DB_VERSION_MINOR >= 4
1687
1267void 1688void
1268db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = &PL_sv_undef) 1689db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = 0)
1690 PREINIT:
1691 CALLBACK
1269 CODE: 1692 CODE:
1270{ 1693{
1271 dREQ (REQ_DB_COMPACT); 1694 dREQ (REQ_DB_COMPACT, 2);
1272 req->db = db; 1695 req->db = db;
1273 req->txn = txn; 1696 req->txn = txn;
1274 sv_to_dbt (&req->dbt1, start); 1697 sv_to_dbt (&req->dbt1, start);
1275 sv_to_dbt (&req->dbt2, stop); 1698 sv_to_dbt (&req->dbt2, stop);
1276 req->uint1 = flags; 1699 req->uint1 = flags;
1277 REQ_SEND; 1700 REQ_SEND;
1278} 1701}
1279 1702
1703#endif
1704
1280void 1705void
1281db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) 1706db_sync (DB *db, U32 flags = 0, SV *callback = 0)
1707 PREINIT:
1708 CALLBACK
1282 CODE: 1709 CODE:
1283{ 1710{
1284 dREQ (REQ_DB_SYNC); 1711 dREQ (REQ_DB_SYNC, 1);
1285 req->db = db; 1712 req->db = db;
1286 req->uint1 = flags; 1713 req->uint1 = flags;
1287 REQ_SEND; 1714 REQ_SEND;
1288} 1715}
1289 1716
1290void 1717void
1718db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0)
1719 PREINIT:
1720 CALLBACK
1721 CODE:
1722{
1723 dREQ (REQ_DB_SYNC, 1);
1724 req->db = db;
1725 req->buf1 = strdup (file);
1726 req->uint1 = flags;
1727 REQ_SEND;
1728}
1729
1730void
1291db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) 1731db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *key_range, U32 flags = 0, SV *callback = 0)
1732 PREINIT:
1733 CALLBACK
1292 CODE: 1734 CODE:
1293{ 1735{
1294 dREQ (REQ_DB_KEY_RANGE); 1736 dREQ (REQ_DB_KEY_RANGE, 2);
1295 req->db = db; 1737 req->db = db;
1296 req->txn = txn; 1738 req->txn = txn;
1297 sv_to_dbt (&req->dbt1, key); 1739 sv_to_dbt (&req->dbt1, key);
1298 req->uint1 = flags; 1740 req->uint1 = flags;
1299 req->sv1 = SvREFCNT_inc (key_range); SvREADONLY_on (key_range); 1741 req->sv1 = SvREFCNT_inc (key_range); SvREADONLY_on (key_range);
1300 REQ_SEND; 1742 REQ_SEND;
1301} 1743}
1302 1744
1303void 1745void
1304db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 1746db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0)
1747 PREINIT:
1748 CALLBACK
1305 CODE: 1749 CODE:
1306{ 1750{
1307 dREQ (REQ_DB_PUT); 1751 dREQ (REQ_DB_PUT, 2);
1308 req->db = db; 1752 req->db = db;
1309 req->txn = txn; 1753 req->txn = txn;
1310 sv_to_dbt (&req->dbt1, key); 1754 sv_to_dbt (&req->dbt1, key);
1311 sv_to_dbt (&req->dbt2, data); 1755 sv_to_dbt (&req->dbt2, data);
1312 req->uint1 = flags; 1756 req->uint1 = flags;
1313 REQ_SEND; 1757 REQ_SEND;
1314} 1758}
1315 1759
1760#if DB_VERSION_MINOR >= 6
1761
1316void 1762void
1763db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0)
1764 PREINIT:
1765 CALLBACK
1766 CODE:
1767{
1768 dREQ (REQ_DB_EXISTS, 2);
1769 req->db = db;
1770 req->txn = txn;
1771 req->uint1 = flags;
1772 sv_to_dbt (&req->dbt1, key);
1773 REQ_SEND;
1774}
1775
1776#endif
1777
1778void
1317db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 1779db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1780 PREINIT:
1781 CALLBACK
1318 CODE: 1782 CODE:
1319{ 1783{
1784 //TODO: key is somtimesmutable
1320 dREQ (REQ_DB_GET); 1785 dREQ (REQ_DB_GET, 2);
1321 req->db = db; 1786 req->db = db;
1322 req->txn = txn; 1787 req->txn = txn;
1323 req->uint1 = flags; 1788 req->uint1 = flags;
1324 sv_to_dbt (&req->dbt1, key); 1789 sv_to_dbt (&req->dbt1, key);
1325 req->dbt3.flags = DB_DBT_MALLOC; 1790 req->dbt3.flags = DB_DBT_MALLOC;
1326 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); 1791 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1327 REQ_SEND; 1792 REQ_SEND;
1328} 1793}
1329 1794
1330void 1795void
1331db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 1796db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1797 PREINIT:
1798 CALLBACK
1332 CODE: 1799 CODE:
1333{ 1800{
1801 //TODO: key is somtimesmutable
1334 dREQ (REQ_DB_PGET); 1802 dREQ (REQ_DB_PGET, 2);
1803 req->db = db;
1804 req->txn = txn;
1805 req->uint1 = flags;
1806
1807 sv_to_dbt (&req->dbt1, key);
1808
1809 req->dbt2.flags = DB_DBT_MALLOC;
1810 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
1811
1812 req->dbt3.flags = DB_DBT_MALLOC;
1813 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1814 REQ_SEND;
1815}
1816
1817void
1818db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0)
1819 PREINIT:
1820 CALLBACK
1821 CODE:
1822{
1823 dREQ (REQ_DB_DEL, 2);
1335 req->db = db; 1824 req->db = db;
1336 req->txn = txn; 1825 req->txn = txn;
1337 req->uint1 = flags; 1826 req->uint1 = flags;
1338 sv_to_dbt (&req->dbt1, key); 1827 sv_to_dbt (&req->dbt1, key);
1339 sv_to_dbt (&req->dbt2, pkey);
1340 req->dbt3.flags = DB_DBT_MALLOC;
1341 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1342 REQ_SEND; 1828 REQ_SEND;
1343} 1829}
1344 1830
1345void 1831void
1346db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef) 1832db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1833 PREINIT:
1834 CALLBACK
1347 CODE: 1835 CODE:
1348{ 1836{
1349 dREQ (REQ_DB_DEL); 1837 dREQ (REQ_TXN_COMMIT, 0);
1350 req->db = db; 1838 ptr_nuke (ST (0));
1351 req->txn = txn; 1839 req->txn = txn;
1352 req->uint1 = flags; 1840 req->uint1 = flags;
1353 sv_to_dbt (&req->dbt1, key);
1354 REQ_SEND; 1841 REQ_SEND;
1355} 1842}
1356 1843
1357void 1844void
1358db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef) 1845db_txn_abort (DB_TXN *txn, SV *callback = 0)
1846 PREINIT:
1847 CALLBACK
1359 CODE: 1848 CODE:
1360{ 1849{
1361 dREQ (REQ_TXN_COMMIT); 1850 dREQ (REQ_TXN_ABORT, 0);
1851 ptr_nuke (ST (0));
1852 req->txn = txn;
1853 REQ_SEND;
1854}
1855
1856void
1857db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0)
1858 PREINIT:
1859 CALLBACK
1860 CODE:
1861{
1862 dREQ (REQ_TXN_FINISH, 0);
1863 ptr_nuke (ST (0));
1362 req->txn = txn; 1864 req->txn = txn;
1363 req->uint1 = flags; 1865 req->uint1 = flags;
1364 REQ_SEND; 1866 REQ_SEND;
1867}
1868
1869void
1870db_c_close (DBC *dbc, SV *callback = 0)
1871 PREINIT:
1872 CALLBACK
1873 CODE:
1874{
1875 dREQ (REQ_C_CLOSE, 0);
1365 ptr_nuke (ST (0)); 1876 ptr_nuke (ST (0));
1366}
1367
1368void
1369db_txn_abort (DB_TXN *txn, SV *callback = &PL_sv_undef)
1370 CODE:
1371{
1372 dREQ (REQ_TXN_ABORT);
1373 req->txn = txn;
1374 REQ_SEND;
1375 ptr_nuke (ST (0));
1376}
1377
1378void
1379db_c_close (DBC *dbc, SV *callback = &PL_sv_undef)
1380 CODE:
1381{
1382 dREQ (REQ_C_CLOSE);
1383 req->dbc = dbc; 1877 req->dbc = dbc;
1384 REQ_SEND; 1878 REQ_SEND;
1385 ptr_nuke (ST (0));
1386} 1879}
1387 1880
1388void 1881void
1389db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = &PL_sv_undef) 1882db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = 0)
1883 PREINIT:
1884 CALLBACK
1390 CODE: 1885 CODE:
1391{ 1886{
1392 dREQ (REQ_C_COUNT); 1887 dREQ (REQ_C_COUNT, 1);
1393 req->dbc = dbc; 1888 req->dbc = dbc;
1394 req->sv1 = SvREFCNT_inc (count); 1889 req->sv1 = SvREFCNT_inc (count);
1395 REQ_SEND; 1890 REQ_SEND;
1396} 1891}
1397 1892
1398void 1893void
1399db_c_put (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 1894db_c_put (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0)
1895 PREINIT:
1896 CALLBACK
1400 CODE: 1897 CODE:
1401{ 1898{
1402 dREQ (REQ_C_PUT); 1899 dREQ (REQ_C_PUT, 1);
1403 req->dbc = dbc; 1900 req->dbc = dbc;
1404 sv_to_dbt (&req->dbt1, key); 1901 sv_to_dbt (&req->dbt1, key);
1405 sv_to_dbt (&req->dbt2, data); 1902 sv_to_dbt (&req->dbt2, data);
1406 req->uint1 = flags; 1903 req->uint1 = flags;
1407 REQ_SEND; 1904 REQ_SEND;
1408} 1905}
1409 1906
1410void 1907void
1411db_c_get (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 1908db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1909 PREINIT:
1910 CALLBACK
1412 CODE: 1911 CODE:
1413{ 1912{
1913 if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key))
1914 croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET");
1915
1916 {
1414 dREQ (REQ_C_GET); 1917 dREQ (REQ_C_GET, 1);
1918 req->dbc = dbc;
1919 req->uint1 = flags;
1920 if (flags & DB_OPFLAGS_MASK == DB_SET)
1921 sv_to_dbt (&req->dbt1, key);
1922 else
1923 {
1924 if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE)
1925 sv_to_dbt (&req->dbt1, key);
1926 else
1927 req->dbt1.flags = DB_DBT_MALLOC;
1928
1929 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1930 }
1931
1932 if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH
1933 || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE)
1934 sv_to_dbt (&req->dbt3, data);
1935 else
1936 req->dbt3.flags = DB_DBT_MALLOC;
1937
1938 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1939 REQ_SEND;
1940 }
1941}
1942
1943void
1944db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0)
1945 PREINIT:
1946 CALLBACK
1947 CODE:
1948{
1949 if (flags & DB_OPFLAGS_MASK != DB_SET && SvREADONLY (key))
1950 croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET");
1951
1952 {
1953 dREQ (REQ_C_PGET, 1);
1954 req->dbc = dbc;
1955 req->uint1 = flags;
1956 if (flags & DB_OPFLAGS_MASK == DB_SET)
1957 sv_to_dbt (&req->dbt1, key);
1958 else
1959 {
1960 if (flags & DB_OPFLAGS_MASK == DB_SET_RANGE)
1961 sv_to_dbt (&req->dbt1, key);
1962 else
1963 req->dbt1.flags = DB_DBT_MALLOC;
1964
1965 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1966 }
1967
1968 req->dbt2.flags = DB_DBT_MALLOC;
1969 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
1970
1971 if (flags & DB_OPFLAGS_MASK == DB_GET_BOTH
1972 || flags & DB_OPFLAGS_MASK == DB_GET_BOTH_RANGE)
1973 sv_to_dbt (&req->dbt3, data);
1974 else
1975 req->dbt3.flags = DB_DBT_MALLOC;
1976
1977 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1978 REQ_SEND;
1979 }
1980}
1981
1982void
1983db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0)
1984 PREINIT:
1985 CALLBACK
1986 CODE:
1987{
1988 dREQ (REQ_C_DEL, 1);
1415 req->dbc = dbc; 1989 req->dbc = dbc;
1416 req->uint1 = flags; 1990 req->uint1 = flags;
1417 if ((flags & DB_SET) == DB_SET
1418 || (flags & DB_SET_RANGE) == DB_SET_RANGE)
1419 sv_to_dbt (&req->dbt1, key);
1420 else
1421 req->dbt1.flags = DB_DBT_MALLOC;
1422
1423 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key);
1424
1425 if ((flags & DB_GET_BOTH) == DB_GET_BOTH
1426 || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE)
1427 sv_to_dbt (&req->dbt3, data);
1428 else
1429 req->dbt3.flags = DB_DBT_MALLOC;
1430
1431 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1432 REQ_SEND; 1991 REQ_SEND;
1433} 1992}
1434 1993
1435void
1436db_c_pget (DBC *dbc, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef)
1437 CODE:
1438{
1439 dREQ (REQ_C_PGET);
1440 req->dbc = dbc;
1441 req->uint1 = flags;
1442 if ((flags & DB_SET) == DB_SET
1443 || (flags & DB_SET_RANGE) == DB_SET_RANGE)
1444 sv_to_dbt (&req->dbt1, key);
1445 else
1446 req->dbt1.flags = DB_DBT_MALLOC;
1447 1994
1448 req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); 1995#if DB_VERSION_MINOR >= 3
1449 1996
1450 req->dbt2.flags = DB_DBT_MALLOC;
1451 req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey);
1452
1453 if ((flags & DB_GET_BOTH) == DB_GET_BOTH
1454 || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE)
1455 sv_to_dbt (&req->dbt3, data);
1456 else
1457 req->dbt3.flags = DB_DBT_MALLOC;
1458
1459 req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data);
1460 REQ_SEND;
1461}
1462
1463void 1997void
1464db_c_del (DBC *dbc, U32 flags = 0, SV *callback = &PL_sv_undef)
1465 CODE:
1466{
1467 dREQ (REQ_C_DEL);
1468 req->dbc = dbc;
1469 req->uint1 = flags;
1470 REQ_SEND;
1471}
1472
1473
1474void
1475db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef) 1998db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0)
1999 PREINIT:
2000 CALLBACK
1476 CODE: 2001 CODE:
1477{ 2002{
1478 dREQ (REQ_SEQ_OPEN); 2003 dREQ (REQ_SEQ_OPEN, 2);
1479 req->seq = seq; 2004 req->seq = seq;
1480 req->txn = txnid; 2005 req->txn = txnid;
1481 req->uint1 = flags | DB_THREAD; 2006 req->uint1 = flags | DB_THREAD;
1482 sv_to_dbt (&req->dbt1, key); 2007 sv_to_dbt (&req->dbt1, key);
1483 REQ_SEND; 2008 REQ_SEND;
1484} 2009}
1485 2010
1486void 2011void
1487db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = &PL_sv_undef) 2012db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0)
2013 PREINIT:
2014 CALLBACK
1488 CODE: 2015 CODE:
1489{ 2016{
1490 dREQ (REQ_SEQ_CLOSE); 2017 dREQ (REQ_SEQ_CLOSE, 0);
2018 ptr_nuke (ST (0));
1491 req->seq = seq; 2019 req->seq = seq;
1492 req->uint1 = flags; 2020 req->uint1 = flags;
1493 REQ_SEND; 2021 REQ_SEND;
1494 ptr_nuke (ST (0));
1495} 2022}
1496 2023
1497void 2024void
1498db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = &PL_sv_undef) 2025db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV_mutable *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = 0)
2026 PREINIT:
2027 CALLBACK
1499 CODE: 2028 CODE:
1500{ 2029{
1501 dREQ (REQ_SEQ_GET); 2030 dREQ (REQ_SEQ_GET, 2);
1502 req->seq = seq; 2031 req->seq = seq;
1503 req->txn = txnid; 2032 req->txn = txnid;
1504 req->int1 = delta; 2033 req->int1 = delta;
1505 req->uint1 = flags; 2034 req->uint1 = flags;
1506 req->sv1 = SvREFCNT_inc (seq_value); SvREADONLY_on (seq_value); 2035 req->sv1 = SvREFCNT_inc (seq_value); SvREADONLY_on (seq_value);
1507 REQ_SEND; 2036 REQ_SEND;
1508} 2037}
1509 2038
1510void 2039void
1511db_sequence_remove (DB_SEQUENCE *seq, DB_TXN_ornull *txnid = 0, U32 flags = 0, SV *callback = &PL_sv_undef) 2040db_sequence_remove (DB_SEQUENCE *seq, DB_TXN_ornull *txnid = 0, U32 flags = 0, SV *callback = 0)
2041 PREINIT:
2042 CALLBACK
1512 CODE: 2043 CODE:
1513{ 2044{
1514 dREQ (REQ_SEQ_REMOVE); 2045 dREQ (REQ_SEQ_REMOVE, 2);
1515 req->seq = seq; 2046 req->seq = seq;
1516 req->txn = txnid; 2047 req->txn = txnid;
1517 req->uint1 = flags; 2048 req->uint1 = flags;
1518 REQ_SEND; 2049 REQ_SEND;
1519} 2050}
1520 2051
2052#endif
2053
1521 2054
1522MODULE = BDB PACKAGE = BDB::Env 2055MODULE = BDB PACKAGE = BDB::Env
1523 2056
1524void 2057void
1525DESTROY (DB_ENV_ornull *env) 2058DESTROY (DB_ENV_ornuked *env)
1526 CODE: 2059 CODE:
1527 if (env) 2060 if (env)
1528 env->close (env, 0); 2061 env->close (env, 0);
1529 2062
1530int set_data_dir (DB_ENV *env, const char *dir) 2063int set_data_dir (DB_ENV *env, const char *dir)
1555 CODE: 2088 CODE:
1556 RETVAL = env->set_cachesize (env, gbytes, bytes, ncache); 2089 RETVAL = env->set_cachesize (env, gbytes, bytes, ncache);
1557 OUTPUT: 2090 OUTPUT:
1558 RETVAL 2091 RETVAL
1559 2092
1560int set_flags (DB_ENV *env, U32 flags, int onoff) 2093int set_flags (DB_ENV *env, U32 flags, int onoff = 1)
1561 CODE: 2094 CODE:
1562 RETVAL = env->set_flags (env, flags, onoff); 2095 RETVAL = env->set_flags (env, flags, onoff);
1563 OUTPUT: 2096 OUTPUT:
1564 RETVAL 2097 RETVAL
1565 2098
2099#if DB_VERSION_MINOR >= 7
2100
2101int set_intermediate_dir_mode (DB_ENV *env, const char *mode)
2102 CODE:
2103 RETVAL = env->set_intermediate_dir_mode (env, mode);
2104 OUTPUT:
2105 RETVAL
2106
2107int log_set_config (DB_ENV *env, U32 flags, int onoff = 1)
2108 CODE:
2109 RETVAL = env->log_set_config (env, flags, onoff);
2110 OUTPUT:
2111 RETVAL
2112
2113#endif
2114
2115
2116void set_errfile (DB_ENV *env, FILE *errfile = 0)
2117 CODE:
2118 env->set_errfile (env, errfile);
2119
2120void set_msgfile (DB_ENV *env, FILE *msgfile = 0)
2121 CODE:
2122 env->set_msgfile (env, msgfile);
2123
2124int set_verbose (DB_ENV *env, U32 which = -1, int onoff = 1)
2125 CODE:
2126 RETVAL = env->set_verbose (env, which, onoff);
2127 OUTPUT:
2128 RETVAL
2129
1566int set_encrypt (DB_ENV *env, const char *password, U32 flags = 0) 2130int set_encrypt (DB_ENV *env, const char *password, U32 flags = 0)
1567 CODE: 2131 CODE:
1568 RETVAL = env->set_encrypt (env, password, flags); 2132 RETVAL = env->set_encrypt (env, password, flags);
1569 OUTPUT: 2133 OUTPUT:
1570 RETVAL 2134 RETVAL
1571 2135
1572int set_timeout (DB_ENV *env, NV timeout, U32 flags) 2136int set_timeout (DB_ENV *env, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT)
1573 CODE: 2137 CODE:
1574 RETVAL = env->set_timeout (env, timeout * 1000000, flags); 2138 RETVAL = env->set_timeout (env, timeout * 1000000, flags);
1575 OUTPUT: 2139 OUTPUT:
1576 RETVAL 2140 RETVAL
1577 2141
1626int set_lg_max (DB_ENV *env, U32 max) 2190int set_lg_max (DB_ENV *env, U32 max)
1627 CODE: 2191 CODE:
1628 RETVAL = env->set_lg_max (env, max); 2192 RETVAL = env->set_lg_max (env, max);
1629 OUTPUT: 2193 OUTPUT:
1630 RETVAL 2194 RETVAL
2195
2196#if DB_VERSION_MINOR >= 4
2197
2198int mutex_set_max (DB_ENV *env, U32 max)
2199 CODE:
2200 RETVAL = env->mutex_set_max (env, max);
2201 OUTPUT:
2202 RETVAL
2203
2204int mutex_set_increment (DB_ENV *env, U32 increment)
2205 CODE:
2206 RETVAL = env->mutex_set_increment (env, increment);
2207 OUTPUT:
2208 RETVAL
2209
2210int mutex_set_tas_spins (DB_ENV *env, U32 tas_spins)
2211 CODE:
2212 RETVAL = env->mutex_set_tas_spins (env, tas_spins);
2213 OUTPUT:
2214 RETVAL
2215
2216int mutex_set_align (DB_ENV *env, U32 align)
2217 CODE:
2218 RETVAL = env->mutex_set_align (env, align);
2219 OUTPUT:
2220 RETVAL
2221
2222#endif
1631 2223
1632DB_TXN * 2224DB_TXN *
1633txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0) 2225txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0)
1634 CODE: 2226 CODE:
1635 errno = env->txn_begin (env, parent, &RETVAL, flags); 2227 errno = env->txn_begin (env, parent, &RETVAL, flags);
1636 if (errno) 2228 if (errno)
1637 croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); 2229 croak ("DB_ENV->txn_begin: %s", db_strerror (errno));
1638 OUTPUT: 2230 OUTPUT:
1639 RETVAL 2231 RETVAL
1640 2232
2233#if DB_VERSION_MINOR >= 5
2234
2235DB_TXN *
2236cdsgroup_begin (DB_ENV *env)
2237 CODE:
2238 errno = env->cdsgroup_begin (env, &RETVAL);
2239 if (errno)
2240 croak ("DB_ENV->cdsgroup_begin: %s", db_strerror (errno));
2241 OUTPUT:
2242 RETVAL
2243
2244#endif
2245
1641MODULE = BDB PACKAGE = BDB::Db 2246MODULE = BDB PACKAGE = BDB::Db
1642 2247
1643void 2248void
1644DESTROY (DB_ornull *db) 2249DESTROY (DB_ornuked *db)
1645 CODE: 2250 CODE:
1646 if (db) 2251 if (db)
1647 { 2252 {
1648 SV *env = (SV *)db->app_private; 2253 SV *env = (SV *)db->app_private;
1649 db->close (db, 0); 2254 db->close (db, 0);
1654 CODE: 2259 CODE:
1655 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); 2260 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache);
1656 OUTPUT: 2261 OUTPUT:
1657 RETVAL 2262 RETVAL
1658 2263
1659int set_flags (DB *db, U32 flags); 2264int set_flags (DB *db, U32 flags)
1660 CODE: 2265 CODE:
1661 RETVAL = db->set_flags (db, flags); 2266 RETVAL = db->set_flags (db, flags);
1662 OUTPUT: 2267 OUTPUT:
1663 RETVAL 2268 RETVAL
1664 2269
1678 CODE: 2283 CODE:
1679 RETVAL = db->set_bt_minkey (db, minkey); 2284 RETVAL = db->set_bt_minkey (db, minkey);
1680 OUTPUT: 2285 OUTPUT:
1681 RETVAL 2286 RETVAL
1682 2287
1683int set_re_delim(DB *db, int delim); 2288int set_re_delim (DB *db, int delim)
1684 CODE: 2289 CODE:
1685 RETVAL = db->set_re_delim (db, delim); 2290 RETVAL = db->set_re_delim (db, delim);
1686 OUTPUT: 2291 OUTPUT:
1687 RETVAL 2292 RETVAL
1688 2293
1729 if (errno) 2334 if (errno)
1730 croak ("DB->cursor: %s", db_strerror (errno)); 2335 croak ("DB->cursor: %s", db_strerror (errno));
1731 OUTPUT: 2336 OUTPUT:
1732 RETVAL 2337 RETVAL
1733 2338
2339#if DB_VERSION_MINOR >= 3
2340
1734DB_SEQUENCE * 2341DB_SEQUENCE *
1735sequence (DB *db, U32 flags = 0) 2342sequence (DB *db, U32 flags = 0)
1736 CODE: 2343 CODE:
1737{ 2344{
1738 errno = db_sequence_create (&RETVAL, db, flags); 2345 errno = db_sequence_create (&RETVAL, db, flags);
1740 croak ("db_sequence_create: %s", db_strerror (errno)); 2347 croak ("db_sequence_create: %s", db_strerror (errno));
1741} 2348}
1742 OUTPUT: 2349 OUTPUT:
1743 RETVAL 2350 RETVAL
1744 2351
2352#endif
2353
1745 2354
1746MODULE = BDB PACKAGE = BDB::Txn 2355MODULE = BDB PACKAGE = BDB::Txn
1747 2356
1748void 2357void
1749DESTROY (DB_TXN_ornull *txn) 2358DESTROY (DB_TXN_ornuked *txn)
1750 CODE: 2359 CODE:
1751 if (txn) 2360 if (txn)
1752 txn->abort (txn); 2361 txn->abort (txn);
1753 2362
1754int set_timeout (DB_TXN *txn, NV timeout, U32 flags) 2363int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT)
1755 CODE: 2364 CODE:
1756 RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); 2365 RETVAL = txn->set_timeout (txn, timeout * 1000000, flags);
1757 OUTPUT: 2366 OUTPUT:
1758 RETVAL 2367 RETVAL
1759 2368
2369int failed (DB_TXN *txn)
2370 CODE:
2371 RETVAL = !!(txn->flags & TXN_DEADLOCK);
2372 OUTPUT:
2373 RETVAL
2374
1760 2375
1761MODULE = BDB PACKAGE = BDB::Cursor 2376MODULE = BDB PACKAGE = BDB::Cursor
1762 2377
1763void 2378void
1764DESTROY (DBC_ornull *dbc) 2379DESTROY (DBC_ornuked *dbc)
1765 CODE: 2380 CODE:
1766 if (dbc) 2381 if (dbc)
1767 dbc->c_close (dbc); 2382 dbc->c_close (dbc);
1768 2383
2384#if DB_VERSION_MINOR >= 6
2385
2386int set_priority (DBC *dbc, int priority)
2387 CODE:
2388 dbc->set_priority (dbc, priority);
2389
2390#endif
2391
2392#if DB_VERSION_MINOR >= 3
2393
1769MODULE = BDB PACKAGE = BDB::Sequence 2394MODULE = BDB PACKAGE = BDB::Sequence
1770 2395
1771void 2396void
1772DESTROY (DB_SEQUENCE_ornull *seq) 2397DESTROY (DB_SEQUENCE_ornuked *seq)
1773 CODE: 2398 CODE:
1774 if (seq) 2399 if (seq)
1775 seq->close (seq, 0); 2400 seq->close (seq, 0);
1776 2401
1777int initial_value (DB_SEQUENCE *seq, db_seq_t value) 2402int initial_value (DB_SEQUENCE *seq, db_seq_t value)
1796 CODE: 2421 CODE:
1797 RETVAL = seq->set_range (seq, min, max); 2422 RETVAL = seq->set_range (seq, min, max);
1798 OUTPUT: 2423 OUTPUT:
1799 RETVAL 2424 RETVAL
1800 2425
2426#endif
2427
2428

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines