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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines