1 | #include <sys/user.h> |
|
|
2 | #include <sys/ptrace.h> |
|
|
3 | |
|
|
4 | #define X_STACKSIZE 1024 * 128 + sizeof (long) * 64 * 1024 / 4 |
1 | #define X_STACKSIZE 1024 * 128 + sizeof (long) * 64 * 1024 / 4 |
5 | |
2 | |
6 | #include "xthread.h" |
3 | #include "xthread.h" |
7 | |
4 | |
8 | #include <errno.h> |
5 | #include <errno.h> |
9 | |
6 | |
10 | #include "EXTERN.h" |
7 | #include "EXTERN.h" |
11 | #include "perl.h" |
8 | #include "perl.h" |
12 | #include "XSUB.h" |
9 | #include "XSUB.h" |
13 | |
10 | |
|
|
11 | #include "schmorp.h" |
|
|
12 | |
14 | // perl stupidly defines these as macros, breaking |
13 | // perl stupidly defines these as argument-less macros, breaking |
15 | // lots and lots of code. |
14 | // lots and lots of code. |
16 | #undef open |
15 | #undef open |
17 | #undef close |
16 | #undef close |
18 | #undef abort |
17 | #undef abort |
19 | #undef malloc |
18 | #undef malloc |
… | |
… | |
39 | #endif |
38 | #endif |
40 | |
39 | |
41 | /* number of seconds after which idle threads exit */ |
40 | /* number of seconds after which idle threads exit */ |
42 | #define IDLE_TIMEOUT 10 |
41 | #define IDLE_TIMEOUT 10 |
43 | |
42 | |
|
|
43 | typedef SV SV_mutable; |
|
|
44 | |
44 | typedef DB_ENV DB_ENV_ornull; |
45 | typedef DB_ENV DB_ENV_ornull; |
45 | typedef DB_TXN DB_TXN_ornull; |
46 | typedef DB_TXN DB_TXN_ornull; |
46 | typedef DBC DBC_ornull; |
47 | typedef DBC DBC_ornull; |
47 | typedef DB DB_ornull; |
48 | typedef DB DB_ornull; |
48 | |
49 | |
… | |
… | |
54 | #if DB_VERSION_MINOR >= 3 |
55 | #if DB_VERSION_MINOR >= 3 |
55 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
56 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
56 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
57 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
57 | #endif |
58 | #endif |
58 | |
59 | |
59 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
|
|
60 | typedef char *bdb_filename; |
60 | typedef char *bdb_filename; |
61 | |
61 | |
62 | static SV *prepare_cb; |
62 | static SV *prepare_cb; |
63 | |
63 | |
64 | #if DB_VERSION_MINOR >= 6 |
64 | #if DB_VERSION_MINOR >= 6 |
… | |
… | |
135 | dbt_to_sv (SV *sv, DBT *dbt) |
135 | dbt_to_sv (SV *sv, DBT *dbt) |
136 | { |
136 | { |
137 | if (sv) |
137 | if (sv) |
138 | { |
138 | { |
139 | SvREADONLY_off (sv); |
139 | SvREADONLY_off (sv); |
140 | sv_setsv_mg (sv, dbt->data ? newSVpvn (dbt->data, dbt->size) : &PL_sv_undef); |
140 | |
|
|
141 | if (dbt->data) |
|
|
142 | sv_setpvn_mg (sv, dbt->data, dbt->size); |
|
|
143 | else |
|
|
144 | sv_setsv_mg (sv, &PL_sv_undef); |
|
|
145 | |
141 | SvREFCNT_dec (sv); |
146 | SvREFCNT_dec (sv); |
142 | } |
147 | } |
143 | |
148 | |
144 | //assert (dbt->flags & DBT_MALLOC || !dbt->data); |
|
|
145 | free (dbt->data); |
149 | free (dbt->data); |
146 | } |
150 | } |
147 | |
151 | |
148 | enum { |
152 | enum { |
149 | REQ_QUIT, |
153 | REQ_QUIT, |
150 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
154 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
151 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
155 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
|
|
156 | REQ_ENV_LOG_ARCHIVE, |
152 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
157 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_VERIFY, REQ_DB_UPGRADE, |
153 | REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
158 | REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
154 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
159 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
155 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
160 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
156 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
161 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
157 | }; |
162 | }; |
… | |
… | |
242 | } |
247 | } |
243 | |
248 | |
244 | static volatile unsigned int nreqs, nready, npending; |
249 | static volatile unsigned int nreqs, nready, npending; |
245 | static volatile unsigned int max_idle = 4; |
250 | static volatile unsigned int max_idle = 4; |
246 | static volatile unsigned int max_outstanding = 0xffffffff; |
251 | static volatile unsigned int max_outstanding = 0xffffffff; |
247 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
252 | static s_epipe respipe; |
248 | |
253 | |
249 | static mutex_t reslock = X_MUTEX_INIT; |
254 | static mutex_t reslock = X_MUTEX_INIT; |
250 | static mutex_t reqlock = X_MUTEX_INIT; |
255 | static mutex_t reqlock = X_MUTEX_INIT; |
251 | static cond_t reqwait = X_COND_INIT; |
256 | static cond_t reqwait = X_COND_INIT; |
252 | |
257 | |
… | |
… | |
347 | abort (); |
352 | abort (); |
348 | } |
353 | } |
349 | |
354 | |
350 | static int poll_cb (void); |
355 | static int poll_cb (void); |
351 | static void req_free (bdb_req req); |
356 | static void req_free (bdb_req req); |
352 | static void req_cancel (bdb_req req); |
|
|
353 | |
357 | |
354 | static int req_invoke (bdb_req req) |
358 | static int req_invoke (bdb_req req) |
355 | { |
359 | { |
356 | dSP; |
360 | switch (req->type) |
|
|
361 | { |
|
|
362 | case REQ_DB_CLOSE: |
|
|
363 | SvREFCNT_dec (req->sv1); |
|
|
364 | break; |
|
|
365 | |
|
|
366 | case REQ_DB_GET: |
|
|
367 | case REQ_DB_PGET: |
|
|
368 | case REQ_C_GET: |
|
|
369 | case REQ_C_PGET: |
|
|
370 | case REQ_DB_PUT: |
|
|
371 | case REQ_C_PUT: |
|
|
372 | dbt_to_sv (req->sv1, &req->dbt1); |
|
|
373 | dbt_to_sv (req->sv2, &req->dbt2); |
|
|
374 | dbt_to_sv (req->sv3, &req->dbt3); |
|
|
375 | break; |
|
|
376 | |
|
|
377 | case REQ_DB_KEY_RANGE: |
|
|
378 | { |
|
|
379 | AV *av = newAV (); |
|
|
380 | |
|
|
381 | av_push (av, newSVnv (req->key_range.less)); |
|
|
382 | av_push (av, newSVnv (req->key_range.equal)); |
|
|
383 | av_push (av, newSVnv (req->key_range.greater)); |
|
|
384 | |
|
|
385 | av = (AV *)newRV_noinc ((SV *)av); |
|
|
386 | |
|
|
387 | SvREADONLY_off (req->sv1); |
|
|
388 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
|
|
389 | SvREFCNT_dec (av); |
|
|
390 | SvREFCNT_dec (req->sv1); |
|
|
391 | } |
|
|
392 | break; |
|
|
393 | |
|
|
394 | #if DB_VERSION_MINOR >= 3 |
|
|
395 | case REQ_SEQ_GET: |
|
|
396 | SvREADONLY_off (req->sv1); |
|
|
397 | |
|
|
398 | if (sizeof (IV) > 4) |
|
|
399 | sv_setiv_mg (req->sv1, (IV)req->seq_t); |
|
|
400 | else |
|
|
401 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
|
|
402 | |
|
|
403 | SvREFCNT_dec (req->sv1); |
|
|
404 | break; |
|
|
405 | #endif |
|
|
406 | |
|
|
407 | case REQ_ENV_LOG_ARCHIVE: |
|
|
408 | { |
|
|
409 | AV *av = newAV (); |
|
|
410 | char **listp = (char **)req->buf1; |
|
|
411 | |
|
|
412 | if (listp) |
|
|
413 | while (*listp) |
|
|
414 | av_push (av, newSVpv (*listp, 0)), ++listp; |
|
|
415 | |
|
|
416 | av = (AV *)newRV_noinc ((SV *)av); |
|
|
417 | |
|
|
418 | SvREADONLY_off (req->sv1); |
|
|
419 | sv_setsv_mg (req->sv1, (SV *)av); |
|
|
420 | SvREFCNT_dec (av); |
|
|
421 | SvREFCNT_dec (req->sv1); |
|
|
422 | } |
|
|
423 | break; |
|
|
424 | } |
|
|
425 | |
|
|
426 | errno = req->result; |
357 | |
427 | |
358 | if (req->callback) |
428 | if (req->callback) |
359 | { |
429 | { |
|
|
430 | dSP; |
|
|
431 | |
360 | ENTER; |
432 | ENTER; |
361 | SAVETMPS; |
433 | SAVETMPS; |
362 | PUSHMARK (SP); |
434 | PUSHMARK (SP); |
363 | |
435 | |
364 | switch (req->type) |
|
|
365 | { |
|
|
366 | case REQ_DB_CLOSE: |
|
|
367 | SvREFCNT_dec (req->sv1); |
|
|
368 | break; |
|
|
369 | |
|
|
370 | case REQ_DB_GET: |
|
|
371 | case REQ_DB_PGET: |
|
|
372 | dbt_to_sv (req->sv3, &req->dbt3); |
|
|
373 | break; |
|
|
374 | |
|
|
375 | case REQ_C_GET: |
|
|
376 | case REQ_C_PGET: |
|
|
377 | dbt_to_sv (req->sv1, &req->dbt1); |
|
|
378 | dbt_to_sv (req->sv2, &req->dbt2); |
|
|
379 | dbt_to_sv (req->sv3, &req->dbt3); |
|
|
380 | break; |
|
|
381 | |
|
|
382 | case REQ_DB_PUT: |
|
|
383 | case REQ_C_PUT: |
|
|
384 | dbt_to_sv (0, &req->dbt1); |
|
|
385 | dbt_to_sv (0, &req->dbt2); |
|
|
386 | break; |
|
|
387 | |
|
|
388 | case REQ_DB_KEY_RANGE: |
|
|
389 | { |
|
|
390 | AV *av = newAV (); |
|
|
391 | |
|
|
392 | av_push (av, newSVnv (req->key_range.less)); |
|
|
393 | av_push (av, newSVnv (req->key_range.equal)); |
|
|
394 | av_push (av, newSVnv (req->key_range.greater)); |
|
|
395 | |
|
|
396 | SvREADONLY_off (req->sv1); |
|
|
397 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
|
|
398 | SvREFCNT_dec (req->sv1); |
|
|
399 | } |
|
|
400 | break; |
|
|
401 | |
|
|
402 | #if DB_VERSION_MINOR >= 3 |
|
|
403 | case REQ_SEQ_GET: |
|
|
404 | SvREADONLY_off (req->sv1); |
|
|
405 | |
|
|
406 | if (sizeof (IV) > 4) |
|
|
407 | sv_setiv_mg (req->sv1, (IV)req->seq_t); |
|
|
408 | else |
|
|
409 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
|
|
410 | |
|
|
411 | SvREFCNT_dec (req->sv1); |
|
|
412 | break; |
|
|
413 | #endif |
|
|
414 | } |
|
|
415 | |
|
|
416 | errno = req->result; |
|
|
417 | |
|
|
418 | PUTBACK; |
436 | PUTBACK; |
419 | call_sv (req->callback, G_VOID | G_EVAL); |
437 | call_sv (req->callback, G_VOID | G_EVAL); |
420 | SPAGAIN; |
438 | SPAGAIN; |
421 | |
439 | |
422 | FREETMPS; |
440 | FREETMPS; |
423 | LEAVE; |
441 | LEAVE; |
|
|
442 | |
|
|
443 | return !SvTRUE (ERRSV); |
424 | } |
444 | } |
425 | |
445 | |
426 | return !SvTRUE (ERRSV); |
446 | return 1; |
427 | } |
447 | } |
428 | |
448 | |
429 | static void req_free (bdb_req req) |
449 | static void req_free (bdb_req req) |
430 | { |
450 | { |
431 | SvREFCNT_dec (req->callback); |
451 | SvREFCNT_dec (req->callback); |
… | |
… | |
438 | free (req->buf3); |
458 | free (req->buf3); |
439 | |
459 | |
440 | Safefree (req); |
460 | Safefree (req); |
441 | } |
461 | } |
442 | |
462 | |
443 | #ifdef USE_SOCKETS_AS_HANDLES |
|
|
444 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
|
|
445 | #else |
|
|
446 | # define TO_SOCKET(x) (x) |
|
|
447 | #endif |
|
|
448 | |
|
|
449 | static void |
463 | static void |
450 | create_respipe (void) |
464 | create_respipe (void) |
451 | { |
465 | { |
452 | #ifdef _WIN32 |
|
|
453 | int arg; /* argg */ |
|
|
454 | #endif |
|
|
455 | int old_readfd = respipe [0]; |
|
|
456 | |
|
|
457 | if (respipe [1] >= 0) |
|
|
458 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
459 | |
|
|
460 | #ifdef _WIN32 |
|
|
461 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
|
|
462 | #else |
|
|
463 | if (pipe (respipe)) |
466 | if (s_epipe_renew (&respipe)) |
464 | #endif |
467 | croak ("BDB: unable to create event pipe"); |
465 | croak ("unable to initialize result pipe"); |
|
|
466 | |
|
|
467 | if (old_readfd >= 0) |
|
|
468 | { |
|
|
469 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
470 | croak ("unable to initialize result pipe(2)"); |
|
|
471 | |
|
|
472 | respipe_close (respipe [0]); |
|
|
473 | respipe [0] = old_readfd; |
|
|
474 | } |
|
|
475 | |
|
|
476 | #ifdef _WIN32 |
|
|
477 | arg = 1; |
|
|
478 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
479 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
480 | #else |
|
|
481 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
482 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
483 | #endif |
|
|
484 | croak ("unable to initialize result pipe(3)"); |
|
|
485 | |
|
|
486 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
|
|
487 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
|
|
488 | } |
468 | } |
489 | |
469 | |
|
|
470 | static void bdb_request (bdb_req req); |
490 | X_THREAD_PROC (bdb_proc); |
471 | X_THREAD_PROC (bdb_proc); |
491 | |
472 | |
492 | static void start_thread (void) |
473 | static void start_thread (void) |
493 | { |
474 | { |
494 | worker *wrk = calloc (1, sizeof (worker)); |
475 | worker *wrk = calloc (1, sizeof (worker)); |
… | |
… | |
541 | } |
522 | } |
542 | |
523 | |
543 | // synthesize callback if none given |
524 | // synthesize callback if none given |
544 | if (!req->callback) |
525 | if (!req->callback) |
545 | { |
526 | { |
|
|
527 | if (SvOK (prepare_cb)) |
|
|
528 | { |
546 | int count; |
529 | int count; |
547 | |
530 | |
548 | dSP; |
531 | dSP; |
549 | PUSHMARK (SP); |
532 | PUSHMARK (SP); |
550 | PUTBACK; |
533 | PUTBACK; |
551 | count = call_sv (prepare_cb, G_ARRAY); |
534 | count = call_sv (prepare_cb, G_ARRAY); |
552 | SPAGAIN; |
535 | SPAGAIN; |
553 | |
536 | |
554 | if (count != 2) |
537 | if (count != 2) |
555 | croak ("prepare callback must return exactly two values\n"); |
538 | croak ("sync prepare callback must return exactly two values\n"); |
556 | |
539 | |
557 | wait_callback = POPs; |
540 | wait_callback = POPs; |
558 | req->callback = SvREFCNT_inc (POPs); |
541 | req->callback = SvREFCNT_inc (POPs); |
|
|
542 | } |
|
|
543 | else |
|
|
544 | { |
|
|
545 | // execute request synchronously |
|
|
546 | bdb_request (req); |
|
|
547 | req_invoke (req); |
|
|
548 | req_free (req); |
|
|
549 | return; |
|
|
550 | } |
559 | } |
551 | } |
560 | |
552 | |
561 | ++nreqs; |
553 | ++nreqs; |
562 | |
554 | |
563 | X_LOCK (reqlock); |
555 | X_LOCK (reqlock); |
… | |
… | |
577 | } |
569 | } |
578 | } |
570 | } |
579 | |
571 | |
580 | static void end_thread (void) |
572 | static void end_thread (void) |
581 | { |
573 | { |
582 | bdb_req req; |
574 | bdb_req req = calloc (1, sizeof (bdb_cb)); |
583 | |
|
|
584 | Newz (0, req, 1, bdb_cb); |
|
|
585 | |
575 | |
586 | req->type = REQ_QUIT; |
576 | req->type = REQ_QUIT; |
587 | req->pri = PRI_MAX + PRI_BIAS; |
577 | req->pri = PRI_MAX + PRI_BIAS; |
588 | |
578 | |
589 | X_LOCK (reqlock); |
579 | X_LOCK (reqlock); |
… | |
… | |
632 | if (size) |
622 | if (size) |
633 | return; |
623 | return; |
634 | |
624 | |
635 | maybe_start_thread (); |
625 | maybe_start_thread (); |
636 | |
626 | |
637 | FD_ZERO (&rfd); |
627 | s_epipe_wait (&respipe); |
638 | FD_SET (respipe [0], &rfd); |
|
|
639 | |
|
|
640 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
641 | } |
628 | } |
642 | } |
629 | } |
643 | |
630 | |
644 | static int poll_cb (void) |
631 | static int poll_cb (void) |
645 | { |
632 | { |
… | |
… | |
665 | if (req) |
652 | if (req) |
666 | { |
653 | { |
667 | --npending; |
654 | --npending; |
668 | |
655 | |
669 | if (!res_queue.size) |
656 | if (!res_queue.size) |
670 | { |
|
|
671 | /* read any signals sent by the worker threads */ |
657 | /* read any signals sent by the worker threads */ |
672 | char buf [4]; |
658 | s_epipe_drain (&respipe); |
673 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
674 | ; |
|
|
675 | } |
|
|
676 | } |
659 | } |
677 | |
660 | |
678 | X_UNLOCK (reslock); |
661 | X_UNLOCK (reslock); |
679 | |
662 | |
680 | if (!req) |
663 | if (!req) |
… | |
… | |
762 | req->result = req->db->close (req->db, req->uint1); |
745 | req->result = req->db->close (req->db, req->uint1); |
763 | break; |
746 | break; |
764 | |
747 | |
765 | #if DB_VERSION_MINOR >= 4 |
748 | #if DB_VERSION_MINOR >= 4 |
766 | case REQ_DB_COMPACT: |
749 | case REQ_DB_COMPACT: |
767 | req->result = req->db->compact (req->db, req->txn, &req->dbt1, &req->dbt2, 0, req->uint1, 0); |
750 | 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); |
768 | break; |
751 | break; |
769 | #endif |
752 | #endif |
770 | |
753 | |
771 | case REQ_DB_SYNC: |
754 | case REQ_DB_SYNC: |
772 | req->result = req->db->sync (req->db, req->uint1); |
755 | req->result = req->db->sync (req->db, req->uint1); |
|
|
756 | break; |
|
|
757 | |
|
|
758 | case REQ_DB_VERIFY: |
|
|
759 | req->result = req->db->verify (req->db, req->buf1, req->buf2, 0, req->uint1); |
773 | break; |
760 | break; |
774 | |
761 | |
775 | case REQ_DB_UPGRADE: |
762 | case REQ_DB_UPGRADE: |
776 | req->result = req->db->upgrade (req->db, req->buf1, req->uint1); |
763 | req->result = req->db->upgrade (req->db, req->buf1, req->uint1); |
777 | break; |
764 | break; |
… | |
… | |
864 | case REQ_SEQ_REMOVE: |
851 | case REQ_SEQ_REMOVE: |
865 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
852 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
866 | break; |
853 | break; |
867 | #endif |
854 | #endif |
868 | |
855 | |
|
|
856 | case REQ_ENV_LOG_ARCHIVE: |
|
|
857 | { |
|
|
858 | char **listp = 0; /* DB_ARCH_REMOVE does not touch listp, contrary to docs */ |
|
|
859 | req->result = req->env->log_archive (req->env, &listp, req->uint1); |
|
|
860 | req->buf1 = (char *)listp; |
|
|
861 | } |
|
|
862 | break; |
|
|
863 | |
869 | default: |
864 | default: |
870 | req->result = ENOSYS; |
865 | req->result = ENOSYS; |
871 | break; |
866 | break; |
872 | } |
867 | } |
873 | |
868 | |
… | |
… | |
884 | /* try to distribute timeouts somewhat evenly */ |
879 | /* try to distribute timeouts somewhat evenly */ |
885 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
880 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
886 | |
881 | |
887 | for (;;) |
882 | for (;;) |
888 | { |
883 | { |
889 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
884 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
890 | |
885 | |
891 | X_LOCK (reqlock); |
886 | X_LOCK (reqlock); |
892 | |
887 | |
893 | for (;;) |
888 | for (;;) |
894 | { |
889 | { |
… | |
… | |
923 | --nready; |
918 | --nready; |
924 | |
919 | |
925 | X_UNLOCK (reqlock); |
920 | X_UNLOCK (reqlock); |
926 | |
921 | |
927 | if (req->type == REQ_QUIT) |
922 | if (req->type == REQ_QUIT) |
|
|
923 | { |
|
|
924 | X_LOCK (reslock); |
|
|
925 | free (req); |
|
|
926 | self->req = 0; |
|
|
927 | X_UNLOCK (reslock); |
|
|
928 | |
928 | goto quit; |
929 | goto quit; |
|
|
930 | } |
929 | |
931 | |
930 | bdb_request (req); |
932 | bdb_request (req); |
931 | |
933 | |
932 | X_LOCK (reslock); |
934 | X_LOCK (reslock); |
933 | |
935 | |
934 | ++npending; |
936 | ++npending; |
935 | |
937 | |
936 | if (!reqq_push (&res_queue, req)) |
938 | if (!reqq_push (&res_queue, req)) |
937 | /* write a dummy byte to the pipe so fh becomes ready */ |
939 | s_epipe_signal (&respipe); |
938 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
|
|
939 | |
940 | |
940 | self->req = 0; |
941 | self->req = 0; |
941 | worker_clear (self); |
942 | worker_clear (self); |
942 | |
943 | |
943 | X_UNLOCK (reslock); |
944 | X_UNLOCK (reslock); |
… | |
… | |
1031 | } \ |
1032 | } \ |
1032 | else if (sv_derived_from ((arg), # class)) \ |
1033 | else if (sv_derived_from ((arg), # class)) \ |
1033 | { \ |
1034 | { \ |
1034 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1035 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1035 | (var) = INT2PTR (type, tmp); \ |
1036 | (var) = INT2PTR (type, tmp); \ |
1036 | if (!var && nullok != 2) \ |
1037 | if (!var && nullok != 2) \ |
1037 | croak (# var " is not a valid " # class " object anymore"); \ |
1038 | croak (# var " is not a valid " # class " object anymore"); \ |
1038 | } \ |
1039 | } \ |
1039 | else \ |
1040 | else \ |
1040 | croak (# var " is not of type " # class); |
1041 | croak (# var " is not of type " # class); |
|
|
1042 | |
|
|
1043 | #define ARG_MUTABLE(name) \ |
|
|
1044 | if (SvREADONLY (name)) \ |
|
|
1045 | croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); |
1041 | |
1046 | |
1042 | static void |
1047 | static void |
1043 | ptr_nuke (SV *sv) |
1048 | ptr_nuke (SV *sv) |
1044 | { |
1049 | { |
1045 | assert (SvROK (sv)); |
1050 | assert (SvROK (sv)); |
… | |
… | |
1116 | } |
1121 | } |
1117 | |
1122 | |
1118 | return 0; |
1123 | return 0; |
1119 | } |
1124 | } |
1120 | |
1125 | |
|
|
1126 | /*****************************************************************************/ |
|
|
1127 | |
|
|
1128 | #if 0 |
|
|
1129 | static int |
|
|
1130 | bt_pfxc_compare (DB *db, const DBT *dbt1, const DBT *dbt2) |
|
|
1131 | { |
|
|
1132 | ssize_t size1 = dbt1->size; |
|
|
1133 | ssize_t size2 = dbt2->size; |
|
|
1134 | int res = memcmp ((void *)dbt1->data, (void *)dbt2->data, |
|
|
1135 | size1 <= size2 ? size1 : size2); |
|
|
1136 | |
|
|
1137 | if (res) |
|
|
1138 | return res; |
|
|
1139 | else if (size1 - size2) |
|
|
1140 | return size1 - size2; |
|
|
1141 | else |
|
|
1142 | return 0; |
|
|
1143 | } |
|
|
1144 | |
|
|
1145 | static size_t |
|
|
1146 | bt_pfxc_prefix_x (DB *db, const DBT *dbt1, const DBT *dbt2) |
|
|
1147 | { |
|
|
1148 | ssize_t size1 = dbt1->size; |
|
|
1149 | ssize_t size2 = dbt2->size; |
|
|
1150 | u_int8_t *p1 = (u_int8_t *)dbt1->data; |
|
|
1151 | u_int8_t *p2 = (u_int8_t *)dbt2->data; |
|
|
1152 | u_int8_t *pe = p1 + (size1 <= size2 ? size1 : size2); |
|
|
1153 | |
|
|
1154 | while (p1 < pe) |
|
|
1155 | if (*p1++ != *p2++) |
|
|
1156 | return p1 - (u_int8_t *)dbt1->data - 1; |
|
|
1157 | |
|
|
1158 | if (size1 < size2) return size1 + 1; |
|
|
1159 | if (size1 > size2) return size2 + 1; |
|
|
1160 | |
|
|
1161 | return size1; |
|
|
1162 | } |
|
|
1163 | #endif |
|
|
1164 | |
|
|
1165 | /*****************************************************************************/ |
|
|
1166 | |
1121 | /* stupid windoes defined CALLBACK as well */ |
1167 | /* stupid windows defines CALLBACK as well */ |
1122 | #undef CALLBACK |
1168 | #undef CALLBACK |
1123 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
1169 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
1124 | |
1170 | |
1125 | MODULE = BDB PACKAGE = BDB |
1171 | MODULE = BDB PACKAGE = BDB |
1126 | |
1172 | |
… | |
… | |
1179 | const_iv (NOSYNC) |
1225 | const_iv (NOSYNC) |
1180 | const_iv (CHKSUM) |
1226 | const_iv (CHKSUM) |
1181 | const_iv (ENCRYPT) |
1227 | const_iv (ENCRYPT) |
1182 | const_iv (DUP) |
1228 | const_iv (DUP) |
1183 | const_iv (DUPSORT) |
1229 | const_iv (DUPSORT) |
1184 | const_iv (RECNUM) |
1230 | //const_iv (RECNUM) |
1185 | const_iv (RENUMBER) |
1231 | const_iv (RENUMBER) |
1186 | const_iv (REVSPLITOFF) |
1232 | const_iv (REVSPLITOFF) |
1187 | const_iv (CONSUME) |
1233 | const_iv (CONSUME) |
1188 | const_iv (CONSUME_WAIT) |
1234 | const_iv (CONSUME_WAIT) |
1189 | const_iv (GET_BOTH) |
1235 | const_iv (GET_BOTH) |
… | |
… | |
1261 | const_iv (REP_UNAVAIL) |
1307 | const_iv (REP_UNAVAIL) |
1262 | const_iv (RUNRECOVERY) |
1308 | const_iv (RUNRECOVERY) |
1263 | const_iv (SECONDARY_BAD) |
1309 | const_iv (SECONDARY_BAD) |
1264 | const_iv (VERIFY_BAD) |
1310 | const_iv (VERIFY_BAD) |
1265 | |
1311 | |
|
|
1312 | const_iv (SALVAGE) |
|
|
1313 | const_iv (AGGRESSIVE) |
|
|
1314 | const_iv (PRINTABLE) |
|
|
1315 | const_iv (NOORDERCHK) |
|
|
1316 | const_iv (ORDERCHKONLY) |
|
|
1317 | |
|
|
1318 | const_iv (ARCH_ABS) |
|
|
1319 | const_iv (ARCH_DATA) |
|
|
1320 | const_iv (ARCH_LOG) |
|
|
1321 | const_iv (ARCH_REMOVE) |
|
|
1322 | |
1266 | const_iv (VERB_DEADLOCK) |
1323 | const_iv (VERB_DEADLOCK) |
1267 | const_iv (VERB_RECOVERY) |
1324 | const_iv (VERB_RECOVERY) |
1268 | const_iv (VERB_REPLICATION) |
1325 | const_iv (VERB_REPLICATION) |
1269 | const_iv (VERB_WAITSFOR) |
1326 | const_iv (VERB_WAITSFOR) |
1270 | |
1327 | |
… | |
… | |
1303 | const_iv (PRIORITY_VERY_LOW) |
1360 | const_iv (PRIORITY_VERY_LOW) |
1304 | const_iv (PRIORITY_LOW) |
1361 | const_iv (PRIORITY_LOW) |
1305 | const_iv (PRIORITY_DEFAULT) |
1362 | const_iv (PRIORITY_DEFAULT) |
1306 | const_iv (PRIORITY_HIGH) |
1363 | const_iv (PRIORITY_HIGH) |
1307 | const_iv (PRIORITY_VERY_HIGH) |
1364 | const_iv (PRIORITY_VERY_HIGH) |
|
|
1365 | const_iv (IGNORE_LEASE) |
1308 | #endif |
1366 | #endif |
1309 | #if DB_VERSION_MINOR >= 7 |
1367 | #if DB_VERSION_MINOR >= 7 |
|
|
1368 | //const_iv (MULTIPLE_KEY) |
1310 | const_iv (LOG_DIRECT) |
1369 | const_iv (LOG_DIRECT) |
1311 | const_iv (LOG_DSYNC) |
1370 | const_iv (LOG_DSYNC) |
1312 | const_iv (LOG_AUTO_REMOVE) |
1371 | const_iv (LOG_AUTO_REMOVE) |
1313 | const_iv (LOG_IN_MEMORY) |
1372 | const_iv (LOG_IN_MEMORY) |
1314 | const_iv (LOG_ZERO) |
1373 | const_iv (LOG_ZERO) |
… | |
… | |
1323 | }; |
1382 | }; |
1324 | |
1383 | |
1325 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1384 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1326 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1385 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1327 | |
1386 | |
|
|
1387 | prepare_cb = &PL_sv_undef; |
|
|
1388 | |
1328 | { |
1389 | { |
1329 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
1390 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
1330 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
1391 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
1331 | |
1392 | |
1332 | newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); |
1393 | newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); |
… | |
… | |
1418 | |
1479 | |
1419 | int |
1480 | int |
1420 | poll_fileno () |
1481 | poll_fileno () |
1421 | PROTOTYPE: |
1482 | PROTOTYPE: |
1422 | CODE: |
1483 | CODE: |
1423 | RETVAL = respipe [0]; |
1484 | RETVAL = s_epipe_fd (&respipe); |
1424 | OUTPUT: |
1485 | OUTPUT: |
1425 | RETVAL |
1486 | RETVAL |
1426 | |
1487 | |
1427 | int |
1488 | int |
1428 | poll_cb (...) |
1489 | poll_cb (...) |
… | |
… | |
1470 | RETVAL = started; |
1531 | RETVAL = started; |
1471 | if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock); |
1532 | if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock); |
1472 | OUTPUT: |
1533 | OUTPUT: |
1473 | RETVAL |
1534 | RETVAL |
1474 | |
1535 | |
1475 | void |
1536 | SV * |
1476 | set_sync_prepare (SV *cb) |
1537 | set_sync_prepare (SV *cb) |
1477 | PROTOTYPE: & |
1538 | PROTOTYPE: & |
1478 | CODE: |
1539 | CODE: |
1479 | SvREFCNT_dec (prepare_cb); |
1540 | RETVAL = prepare_cb; |
1480 | prepare_cb = newSVsv (cb); |
1541 | prepare_cb = newSVsv (cb); |
|
|
1542 | OUTPUT: |
|
|
1543 | RETVAL |
1481 | |
1544 | |
1482 | char * |
1545 | char * |
1483 | strerror (int errorno = errno) |
1546 | strerror (int errorno = errno) |
1484 | PROTOTYPE: ;$ |
1547 | PROTOTYPE: ;$ |
1485 | CODE: |
1548 | CODE: |
… | |
… | |
1527 | db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) |
1590 | db_env_close (DB_ENV *env, U32 flags = 0, SV *callback = 0) |
1528 | PREINIT: |
1591 | PREINIT: |
1529 | CALLBACK |
1592 | CALLBACK |
1530 | CODE: |
1593 | CODE: |
1531 | { |
1594 | { |
1532 | dREQ (REQ_ENV_CLOSE, 1); |
1595 | dREQ (REQ_ENV_CLOSE, 0); |
|
|
1596 | ptr_nuke (ST (0)); |
1533 | req->env = env; |
1597 | req->env = env; |
1534 | req->uint1 = flags; |
1598 | req->uint1 = flags; |
1535 | REQ_SEND; |
1599 | REQ_SEND; |
1536 | ptr_nuke (ST (0)); |
|
|
1537 | } |
1600 | } |
1538 | |
1601 | |
1539 | void |
1602 | void |
1540 | db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = 0) |
1603 | db_env_txn_checkpoint (DB_ENV *env, U32 kbyte = 0, U32 min = 0, U32 flags = 0, SV *callback = 0) |
1541 | PREINIT: |
1604 | PREINIT: |
… | |
… | |
1610 | dREQ (REQ_ENV_DBRENAME, 2); |
1673 | dREQ (REQ_ENV_DBRENAME, 2); |
1611 | req->env = env; |
1674 | req->env = env; |
1612 | req->buf1 = strdup_ornull (file); |
1675 | req->buf1 = strdup_ornull (file); |
1613 | req->buf2 = strdup_ornull (database); |
1676 | req->buf2 = strdup_ornull (database); |
1614 | req->buf3 = strdup_ornull (newname); |
1677 | req->buf3 = strdup_ornull (newname); |
|
|
1678 | req->uint1 = flags; |
|
|
1679 | REQ_SEND; |
|
|
1680 | } |
|
|
1681 | |
|
|
1682 | void |
|
|
1683 | db_env_log_archive (DB_ENV *env, SV_mutable *listp, U32 flags = 0, SV *callback = 0) |
|
|
1684 | PREINIT: |
|
|
1685 | CALLBACK |
|
|
1686 | CODE: |
|
|
1687 | { |
|
|
1688 | dREQ (REQ_ENV_LOG_ARCHIVE, 1); |
|
|
1689 | req->sv1 = SvREFCNT_inc (listp); |
|
|
1690 | req->env = env; |
1615 | req->uint1 = flags; |
1691 | req->uint1 = flags; |
1616 | REQ_SEND; |
1692 | REQ_SEND; |
1617 | } |
1693 | } |
1618 | |
1694 | |
1619 | DB * |
1695 | DB * |
… | |
… | |
1651 | db_close (DB *db, U32 flags = 0, SV *callback = 0) |
1727 | db_close (DB *db, U32 flags = 0, SV *callback = 0) |
1652 | PREINIT: |
1728 | PREINIT: |
1653 | CALLBACK |
1729 | CALLBACK |
1654 | CODE: |
1730 | CODE: |
1655 | { |
1731 | { |
1656 | dREQ (REQ_DB_CLOSE, 1); |
1732 | dREQ (REQ_DB_CLOSE, 0); |
|
|
1733 | ptr_nuke (ST (0)); |
1657 | req->db = db; |
1734 | req->db = db; |
1658 | req->uint1 = flags; |
1735 | req->uint1 = flags; |
1659 | req->sv1 = (SV *)db->app_private; |
1736 | req->sv1 = (SV *)db->app_private; |
1660 | REQ_SEND; |
1737 | REQ_SEND; |
1661 | ptr_nuke (ST (0)); |
|
|
1662 | } |
1738 | } |
1663 | |
1739 | |
1664 | #if DB_VERSION_MINOR >= 4 |
1740 | #if DB_VERSION_MINOR >= 4 |
1665 | |
1741 | |
1666 | void |
1742 | void |
… | |
… | |
1670 | CODE: |
1746 | CODE: |
1671 | { |
1747 | { |
1672 | dREQ (REQ_DB_COMPACT, 2); |
1748 | dREQ (REQ_DB_COMPACT, 2); |
1673 | req->db = db; |
1749 | req->db = db; |
1674 | req->txn = txn; |
1750 | req->txn = txn; |
1675 | sv_to_dbt (&req->dbt1, start); |
1751 | if (start) sv_to_dbt (&req->dbt1, start); |
1676 | sv_to_dbt (&req->dbt2, stop); |
1752 | if (stop ) sv_to_dbt (&req->dbt2, stop ); |
1677 | req->uint1 = flags; |
1753 | req->uint1 = flags; |
1678 | REQ_SEND; |
1754 | REQ_SEND; |
1679 | } |
1755 | } |
1680 | |
1756 | |
1681 | #endif |
1757 | #endif |
… | |
… | |
1691 | req->uint1 = flags; |
1767 | req->uint1 = flags; |
1692 | REQ_SEND; |
1768 | REQ_SEND; |
1693 | } |
1769 | } |
1694 | |
1770 | |
1695 | void |
1771 | void |
|
|
1772 | db_verify (DB *db, bdb_filename file, bdb_filename database = 0, SV *dummy = 0, U32 flags = 0, SV *callback = 0) |
|
|
1773 | PREINIT: |
|
|
1774 | CALLBACK |
|
|
1775 | CODE: |
|
|
1776 | { |
|
|
1777 | dREQ (REQ_DB_VERIFY, 1); |
|
|
1778 | ptr_nuke (ST (0)); /* verify destroys the database handle, hopefully it is freed as well */ |
|
|
1779 | req->db = db; |
|
|
1780 | req->buf1 = strdup (file); |
|
|
1781 | req->buf2 = strdup_ornull (database); |
|
|
1782 | req->uint1 = flags; |
|
|
1783 | REQ_SEND; |
|
|
1784 | } |
|
|
1785 | |
|
|
1786 | void |
1696 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) |
1787 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) |
1697 | PREINIT: |
1788 | PREINIT: |
1698 | CALLBACK |
1789 | CALLBACK |
1699 | CODE: |
1790 | CODE: |
1700 | { |
1791 | { |
1701 | dREQ (REQ_DB_SYNC, 1); |
1792 | dREQ (REQ_DB_UPGRADE, 1); |
1702 | req->db = db; |
1793 | req->db = db; |
1703 | req->buf1 = strdup (file); |
1794 | req->buf1 = strdup (file); |
1704 | req->uint1 = flags; |
1795 | req->uint1 = flags; |
1705 | REQ_SEND; |
1796 | REQ_SEND; |
1706 | } |
1797 | } |
1707 | |
1798 | |
1708 | void |
1799 | void |
1709 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = 0) |
1800 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *key_range, U32 flags = 0, SV *callback = 0) |
1710 | PREINIT: |
1801 | PREINIT: |
1711 | CALLBACK |
1802 | CALLBACK |
1712 | CODE: |
1803 | CODE: |
1713 | { |
1804 | { |
1714 | dREQ (REQ_DB_KEY_RANGE, 2); |
1805 | dREQ (REQ_DB_KEY_RANGE, 2); |
… | |
… | |
1752 | } |
1843 | } |
1753 | |
1844 | |
1754 | #endif |
1845 | #endif |
1755 | |
1846 | |
1756 | void |
1847 | void |
1757 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = 0) |
1848 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
1758 | PREINIT: |
1849 | PREINIT: |
1759 | CALLBACK |
1850 | CALLBACK |
1760 | CODE: |
1851 | CODE: |
1761 | if (SvREADONLY (data)) |
|
|
1762 | croak ("can't modify read-only data scalar in db_get"); |
|
|
1763 | { |
1852 | { |
|
|
1853 | //TODO: key is somtimesmutable |
1764 | dREQ (REQ_DB_GET, 2); |
1854 | dREQ (REQ_DB_GET, 2); |
1765 | req->db = db; |
1855 | req->db = db; |
1766 | req->txn = txn; |
1856 | req->txn = txn; |
1767 | req->uint1 = flags; |
1857 | req->uint1 = flags; |
1768 | sv_to_dbt (&req->dbt1, key); |
1858 | sv_to_dbt (&req->dbt1, key); |
… | |
… | |
1770 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1860 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1771 | REQ_SEND; |
1861 | REQ_SEND; |
1772 | } |
1862 | } |
1773 | |
1863 | |
1774 | void |
1864 | void |
1775 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0) |
1865 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
1776 | PREINIT: |
1866 | PREINIT: |
1777 | CALLBACK |
1867 | CALLBACK |
1778 | CODE: |
1868 | CODE: |
1779 | if (SvREADONLY (data)) |
|
|
1780 | croak ("can't modify read-only data scalar in db_pget"); |
|
|
1781 | { |
1869 | { |
|
|
1870 | //TODO: key is somtimesmutable |
1782 | dREQ (REQ_DB_PGET, 2); |
1871 | dREQ (REQ_DB_PGET, 2); |
1783 | req->db = db; |
1872 | req->db = db; |
1784 | req->txn = txn; |
1873 | req->txn = txn; |
1785 | req->uint1 = flags; |
1874 | req->uint1 = flags; |
|
|
1875 | |
1786 | sv_to_dbt (&req->dbt1, key); |
1876 | sv_to_dbt (&req->dbt1, key); |
1787 | sv_to_dbt (&req->dbt2, pkey); |
1877 | |
|
|
1878 | req->dbt2.flags = DB_DBT_MALLOC; |
|
|
1879 | req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); |
|
|
1880 | |
1788 | req->dbt3.flags = DB_DBT_MALLOC; |
1881 | req->dbt3.flags = DB_DBT_MALLOC; |
1789 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1882 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1790 | REQ_SEND; |
1883 | REQ_SEND; |
1791 | } |
1884 | } |
1792 | |
1885 | |
… | |
… | |
1808 | db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
1901 | db_txn_commit (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
1809 | PREINIT: |
1902 | PREINIT: |
1810 | CALLBACK |
1903 | CALLBACK |
1811 | CODE: |
1904 | CODE: |
1812 | { |
1905 | { |
1813 | dREQ (REQ_TXN_COMMIT, 1); |
1906 | dREQ (REQ_TXN_COMMIT, 0); |
|
|
1907 | ptr_nuke (ST (0)); |
1814 | req->txn = txn; |
1908 | req->txn = txn; |
1815 | req->uint1 = flags; |
1909 | req->uint1 = flags; |
1816 | REQ_SEND; |
1910 | REQ_SEND; |
|
|
1911 | } |
|
|
1912 | |
|
|
1913 | void |
|
|
1914 | db_txn_abort (DB_TXN *txn, SV *callback = 0) |
|
|
1915 | PREINIT: |
|
|
1916 | CALLBACK |
|
|
1917 | CODE: |
|
|
1918 | { |
|
|
1919 | dREQ (REQ_TXN_ABORT, 0); |
1817 | ptr_nuke (ST (0)); |
1920 | ptr_nuke (ST (0)); |
1818 | } |
|
|
1819 | |
|
|
1820 | void |
|
|
1821 | db_txn_abort (DB_TXN *txn, SV *callback = 0) |
|
|
1822 | PREINIT: |
|
|
1823 | CALLBACK |
|
|
1824 | CODE: |
|
|
1825 | { |
|
|
1826 | dREQ (REQ_TXN_ABORT, 1); |
|
|
1827 | req->txn = txn; |
1921 | req->txn = txn; |
1828 | REQ_SEND; |
1922 | REQ_SEND; |
|
|
1923 | } |
|
|
1924 | |
|
|
1925 | void |
|
|
1926 | db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
|
|
1927 | PREINIT: |
|
|
1928 | CALLBACK |
|
|
1929 | CODE: |
|
|
1930 | { |
|
|
1931 | dREQ (REQ_TXN_FINISH, 0); |
1829 | ptr_nuke (ST (0)); |
1932 | ptr_nuke (ST (0)); |
1830 | } |
|
|
1831 | |
|
|
1832 | void |
|
|
1833 | db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = 0) |
|
|
1834 | PREINIT: |
|
|
1835 | CALLBACK |
|
|
1836 | CODE: |
|
|
1837 | { |
|
|
1838 | dREQ (REQ_TXN_FINISH, 1); |
|
|
1839 | req->txn = txn; |
1933 | req->txn = txn; |
1840 | req->uint1 = flags; |
1934 | req->uint1 = flags; |
1841 | REQ_SEND; |
1935 | REQ_SEND; |
|
|
1936 | } |
|
|
1937 | |
|
|
1938 | void |
|
|
1939 | db_c_close (DBC *dbc, SV *callback = 0) |
|
|
1940 | PREINIT: |
|
|
1941 | CALLBACK |
|
|
1942 | CODE: |
|
|
1943 | { |
|
|
1944 | dREQ (REQ_C_CLOSE, 0); |
1842 | ptr_nuke (ST (0)); |
1945 | ptr_nuke (ST (0)); |
1843 | } |
|
|
1844 | |
|
|
1845 | void |
|
|
1846 | db_c_close (DBC *dbc, SV *callback = 0) |
|
|
1847 | PREINIT: |
|
|
1848 | CALLBACK |
|
|
1849 | CODE: |
|
|
1850 | { |
|
|
1851 | dREQ (REQ_C_CLOSE, 1); |
|
|
1852 | req->dbc = dbc; |
1946 | req->dbc = dbc; |
1853 | REQ_SEND; |
1947 | REQ_SEND; |
1854 | ptr_nuke (ST (0)); |
|
|
1855 | } |
1948 | } |
1856 | |
1949 | |
1857 | void |
1950 | void |
1858 | db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = 0) |
1951 | db_c_count (DBC *dbc, SV *count, U32 flags = 0, SV *callback = 0) |
1859 | PREINIT: |
1952 | PREINIT: |
… | |
… | |
1879 | req->uint1 = flags; |
1972 | req->uint1 = flags; |
1880 | REQ_SEND; |
1973 | REQ_SEND; |
1881 | } |
1974 | } |
1882 | |
1975 | |
1883 | void |
1976 | void |
1884 | db_c_get (DBC *dbc, SV *key, SV *data, U32 flags = 0, SV *callback = 0) |
1977 | db_c_get (DBC *dbc, SV *key, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
1885 | PREINIT: |
1978 | PREINIT: |
1886 | CALLBACK |
1979 | CALLBACK |
1887 | CODE: |
1980 | CODE: |
1888 | { |
1981 | { |
|
|
1982 | if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key)) |
|
|
1983 | croak ("db_c_get was passed a read-only/constant 'key' argument but operation is not DB_SET"); |
|
|
1984 | if (SvPOKp (key) && !sv_utf8_downgrade (key, 1)) |
|
|
1985 | croak ("argument \"%s\" must be byte/octet-encoded in %s", |
|
|
1986 | "key", |
|
|
1987 | "BDB::db_c_get"); |
|
|
1988 | |
|
|
1989 | { |
1889 | dREQ (REQ_C_GET, 1); |
1990 | dREQ (REQ_C_GET, 1); |
1890 | req->dbc = dbc; |
1991 | req->dbc = dbc; |
1891 | req->uint1 = flags; |
1992 | req->uint1 = flags; |
1892 | if ((flags & DB_SET) == DB_SET |
1993 | if ((flags & DB_OPFLAGS_MASK) == DB_SET) |
1893 | || (flags & DB_SET_RANGE) == DB_SET_RANGE) |
|
|
1894 | sv_to_dbt (&req->dbt1, key); |
1994 | sv_to_dbt (&req->dbt1, key); |
1895 | else |
1995 | else |
|
|
1996 | { |
|
|
1997 | if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE) |
|
|
1998 | sv_to_dbt (&req->dbt1, key); |
|
|
1999 | else |
1896 | req->dbt1.flags = DB_DBT_MALLOC; |
2000 | req->dbt1.flags = DB_DBT_MALLOC; |
1897 | |
2001 | |
1898 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
2002 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
|
|
2003 | } |
1899 | |
2004 | |
1900 | if ((flags & DB_GET_BOTH) == DB_GET_BOTH |
2005 | if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH |
1901 | || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE) |
2006 | || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE) |
1902 | sv_to_dbt (&req->dbt3, data); |
2007 | sv_to_dbt (&req->dbt3, data); |
1903 | else |
2008 | else |
1904 | req->dbt3.flags = DB_DBT_MALLOC; |
2009 | req->dbt3.flags = DB_DBT_MALLOC; |
1905 | |
2010 | |
1906 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
2011 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1907 | REQ_SEND; |
2012 | REQ_SEND; |
|
|
2013 | } |
1908 | } |
2014 | } |
1909 | |
2015 | |
1910 | void |
2016 | void |
1911 | db_c_pget (DBC *dbc, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = 0) |
2017 | db_c_pget (DBC *dbc, SV *key, SV_mutable *pkey, SV_mutable *data, U32 flags = 0, SV *callback = 0) |
1912 | PREINIT: |
2018 | PREINIT: |
1913 | CALLBACK |
2019 | CALLBACK |
1914 | CODE: |
2020 | CODE: |
1915 | { |
2021 | { |
|
|
2022 | if ((flags & DB_OPFLAGS_MASK) != DB_SET && SvREADONLY (key)) |
|
|
2023 | croak ("db_c_pget was passed a read-only/constant 'key' argument but operation is not DB_SET"); |
|
|
2024 | if (SvPOKp (key) && !sv_utf8_downgrade (key, 1)) |
|
|
2025 | croak ("argument \"%s\" must be byte/octet-encoded in %s", |
|
|
2026 | "key", |
|
|
2027 | "BDB::db_c_pget"); |
|
|
2028 | |
|
|
2029 | { |
1916 | dREQ (REQ_C_PGET, 1); |
2030 | dREQ (REQ_C_PGET, 1); |
1917 | req->dbc = dbc; |
2031 | req->dbc = dbc; |
1918 | req->uint1 = flags; |
2032 | req->uint1 = flags; |
1919 | if ((flags & DB_SET) == DB_SET |
2033 | if ((flags & DB_OPFLAGS_MASK) == DB_SET) |
1920 | || (flags & DB_SET_RANGE) == DB_SET_RANGE) |
|
|
1921 | sv_to_dbt (&req->dbt1, key); |
2034 | sv_to_dbt (&req->dbt1, key); |
1922 | else |
2035 | else |
|
|
2036 | { |
|
|
2037 | if ((flags & DB_OPFLAGS_MASK) == DB_SET_RANGE) |
|
|
2038 | sv_to_dbt (&req->dbt1, key); |
|
|
2039 | else |
|
|
2040 | req->dbt1.flags = DB_DBT_MALLOC; |
|
|
2041 | |
|
|
2042 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
|
|
2043 | } |
|
|
2044 | |
1923 | req->dbt1.flags = DB_DBT_MALLOC; |
2045 | req->dbt2.flags = DB_DBT_MALLOC; |
1924 | |
|
|
1925 | req->sv1 = SvREFCNT_inc (key); SvREADONLY_on (key); |
|
|
1926 | |
|
|
1927 | req->dbt2.flags = DB_DBT_MALLOC; |
|
|
1928 | req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); |
2046 | req->sv2 = SvREFCNT_inc (pkey); SvREADONLY_on (pkey); |
1929 | |
2047 | |
1930 | if ((flags & DB_GET_BOTH) == DB_GET_BOTH |
2048 | if ((flags & DB_OPFLAGS_MASK) == DB_GET_BOTH |
1931 | || (flags & DB_GET_BOTH_RANGE) == DB_GET_BOTH_RANGE) |
2049 | || (flags & DB_OPFLAGS_MASK) == DB_GET_BOTH_RANGE) |
1932 | sv_to_dbt (&req->dbt3, data); |
2050 | sv_to_dbt (&req->dbt3, data); |
1933 | else |
2051 | else |
1934 | req->dbt3.flags = DB_DBT_MALLOC; |
2052 | req->dbt3.flags = DB_DBT_MALLOC; |
1935 | |
2053 | |
1936 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
2054 | req->sv3 = SvREFCNT_inc (data); SvREADONLY_on (data); |
1937 | REQ_SEND; |
2055 | REQ_SEND; |
|
|
2056 | } |
1938 | } |
2057 | } |
1939 | |
2058 | |
1940 | void |
2059 | void |
1941 | db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) |
2060 | db_c_del (DBC *dbc, U32 flags = 0, SV *callback = 0) |
1942 | PREINIT: |
2061 | PREINIT: |
… | |
… | |
1970 | db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) |
2089 | db_sequence_close (DB_SEQUENCE *seq, U32 flags = 0, SV *callback = 0) |
1971 | PREINIT: |
2090 | PREINIT: |
1972 | CALLBACK |
2091 | CALLBACK |
1973 | CODE: |
2092 | CODE: |
1974 | { |
2093 | { |
1975 | dREQ (REQ_SEQ_CLOSE, 1); |
2094 | dREQ (REQ_SEQ_CLOSE, 0); |
|
|
2095 | ptr_nuke (ST (0)); |
1976 | req->seq = seq; |
2096 | req->seq = seq; |
1977 | req->uint1 = flags; |
2097 | req->uint1 = flags; |
1978 | REQ_SEND; |
2098 | REQ_SEND; |
1979 | ptr_nuke (ST (0)); |
|
|
1980 | } |
2099 | } |
1981 | |
2100 | |
1982 | void |
2101 | void |
1983 | db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = 0) |
2102 | db_sequence_get (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, int delta, SV_mutable *seq_value, U32 flags = DB_TXN_NOSYNC, SV *callback = 0) |
1984 | PREINIT: |
2103 | PREINIT: |
1985 | CALLBACK |
2104 | CALLBACK |
1986 | CODE: |
2105 | CODE: |
1987 | { |
2106 | { |
1988 | dREQ (REQ_SEQ_GET, 2); |
2107 | dREQ (REQ_SEQ_GET, 2); |
… | |
… | |
2217 | CODE: |
2336 | CODE: |
2218 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
2337 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
2219 | OUTPUT: |
2338 | OUTPUT: |
2220 | RETVAL |
2339 | RETVAL |
2221 | |
2340 | |
|
|
2341 | int set_pagesize (DB *db, U32 pagesize) |
|
|
2342 | CODE: |
|
|
2343 | RETVAL = db->set_pagesize (db, pagesize); |
|
|
2344 | OUTPUT: |
|
|
2345 | RETVAL |
|
|
2346 | |
2222 | int set_flags (DB *db, U32 flags) |
2347 | int set_flags (DB *db, U32 flags) |
2223 | CODE: |
2348 | CODE: |
2224 | RETVAL = db->set_flags (db, flags); |
2349 | RETVAL = db->set_flags (db, flags); |
2225 | OUTPUT: |
2350 | OUTPUT: |
2226 | RETVAL |
2351 | RETVAL |