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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines