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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines