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

Comparing BDB/BDB.xs (file contents):
Revision 1.16 by root, Mon Aug 13 12:01:45 2007 UTC vs.
Revision 1.50 by root, Thu Sep 25 13:22:32 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines