… | |
… | |
104 | REQ_QUIT, |
104 | REQ_QUIT, |
105 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
105 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
106 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, |
106 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, |
107 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, |
107 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, |
108 | REQ_DB_PUT, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
108 | REQ_DB_PUT, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
109 | REQ_TXN_COMMIT, REQ_TXN_ABORT, |
109 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
110 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
110 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
111 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
111 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
112 | }; |
112 | }; |
113 | |
113 | |
114 | typedef struct aio_cb |
114 | typedef struct aio_cb |
… | |
… | |
191 | } |
191 | } |
192 | |
192 | |
193 | static volatile unsigned int nreqs, nready, npending; |
193 | static volatile unsigned int nreqs, nready, npending; |
194 | static volatile unsigned int max_idle = 4; |
194 | static volatile unsigned int max_idle = 4; |
195 | static volatile unsigned int max_outstanding = 0xffffffff; |
195 | static volatile unsigned int max_outstanding = 0xffffffff; |
196 | static int respipe [2], respipe_osf [2]; |
196 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
197 | |
197 | |
198 | static mutex_t reslock = X_MUTEX_INIT; |
198 | static mutex_t reslock = X_MUTEX_INIT; |
199 | static mutex_t reqlock = X_MUTEX_INIT; |
199 | static mutex_t reqlock = X_MUTEX_INIT; |
200 | static cond_t reqwait = X_COND_INIT; |
200 | static cond_t reqwait = X_COND_INIT; |
201 | |
201 | |
… | |
… | |
379 | #else |
379 | #else |
380 | # define TO_SOCKET(x) (x) |
380 | # define TO_SOCKET(x) (x) |
381 | #endif |
381 | #endif |
382 | |
382 | |
383 | static void |
383 | static void |
384 | create_pipe (int fd[2]) |
384 | create_respipe () |
385 | { |
385 | { |
|
|
386 | int old_readfd = respipe [0]; |
|
|
387 | |
|
|
388 | if (respipe [1] >= 0) |
|
|
389 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
390 | |
|
|
391 | #ifdef _WIN32 |
|
|
392 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
|
|
393 | #else |
|
|
394 | if (pipe (respipe)) |
|
|
395 | #endif |
|
|
396 | croak ("unable to initialize result pipe"); |
|
|
397 | |
|
|
398 | if (old_readfd >= 0) |
|
|
399 | { |
|
|
400 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
401 | croak ("unable to initialize result pipe(2)"); |
|
|
402 | |
|
|
403 | respipe_close (respipe [0]); |
|
|
404 | respipe [0] = old_readfd; |
|
|
405 | } |
|
|
406 | |
386 | #ifdef _WIN32 |
407 | #ifdef _WIN32 |
387 | int arg = 1; |
408 | int arg = 1; |
388 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, fd) |
|
|
389 | || ioctlsocket (TO_SOCKET (fd [0]), FIONBIO, &arg) |
409 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
390 | || ioctlsocket (TO_SOCKET (fd [1]), FIONBIO, &arg)) |
410 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
391 | #else |
411 | #else |
392 | if (pipe (fd) |
|
|
393 | || fcntl (fd [0], F_SETFL, O_NONBLOCK) |
412 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
394 | || fcntl (fd [1], F_SETFL, O_NONBLOCK)) |
413 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
395 | #endif |
414 | #endif |
396 | croak ("unable to initialize result pipe"); |
415 | croak ("unable to initialize result pipe(3)"); |
397 | |
416 | |
398 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
417 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
399 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
418 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
400 | } |
419 | } |
401 | |
420 | |
… | |
… | |
668 | X_UNLOCK (reqlock); |
687 | X_UNLOCK (reqlock); |
669 | |
688 | |
670 | switch (req->type) |
689 | switch (req->type) |
671 | { |
690 | { |
672 | case REQ_QUIT: |
691 | case REQ_QUIT: |
|
|
692 | req->result = ENOSYS; |
673 | goto quit; |
693 | goto quit; |
674 | |
694 | |
675 | case REQ_ENV_OPEN: |
695 | case REQ_ENV_OPEN: |
676 | req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1); |
696 | req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1); |
677 | break; |
697 | break; |
… | |
… | |
736 | req->result = req->txn->commit (req->txn, req->uint1); |
756 | req->result = req->txn->commit (req->txn, req->uint1); |
737 | break; |
757 | break; |
738 | |
758 | |
739 | case REQ_TXN_ABORT: |
759 | case REQ_TXN_ABORT: |
740 | req->result = req->txn->abort (req->txn); |
760 | req->result = req->txn->abort (req->txn); |
|
|
761 | break; |
|
|
762 | |
|
|
763 | case REQ_TXN_FINISH: |
|
|
764 | if (req->txn->flags & TXN_DEADLOCK) |
|
|
765 | { |
|
|
766 | req->result = req->txn->abort (req->txn); |
|
|
767 | if (!req->result) |
|
|
768 | req->result = DB_LOCK_DEADLOCK; |
|
|
769 | } |
|
|
770 | else |
|
|
771 | req->result = req->txn->commit (req->txn, req->uint1); |
741 | break; |
772 | break; |
742 | |
773 | |
743 | case REQ_C_CLOSE: |
774 | case REQ_C_CLOSE: |
744 | req->result = req->dbc->c_close (req->dbc); |
775 | req->result = req->dbc->c_close (req->dbc); |
745 | break; |
776 | break; |
… | |
… | |
787 | default: |
818 | default: |
788 | req->result = ENOSYS; |
819 | req->result = ENOSYS; |
789 | break; |
820 | break; |
790 | } |
821 | } |
791 | |
822 | |
|
|
823 | if (req->txn && (req->result > 0 || req->result == DB_LOCK_NOTGRANTED)) |
|
|
824 | req->txn->flags |= TXN_DEADLOCK; |
|
|
825 | |
792 | X_LOCK (reslock); |
826 | X_LOCK (reslock); |
793 | |
827 | |
794 | ++npending; |
828 | ++npending; |
795 | |
829 | |
796 | if (!reqq_push (&res_queue, req)) |
830 | if (!reqq_push (&res_queue, req)) |
… | |
… | |
852 | idle = 0; |
886 | idle = 0; |
853 | nreqs = 0; |
887 | nreqs = 0; |
854 | nready = 0; |
888 | nready = 0; |
855 | npending = 0; |
889 | npending = 0; |
856 | |
890 | |
857 | respipe_close (respipe [0]); |
|
|
858 | respipe_close (respipe [1]); |
|
|
859 | |
|
|
860 | create_pipe (respipe); |
891 | create_respipe (); |
861 | |
892 | |
862 | atfork_parent (); |
893 | atfork_parent (); |
863 | } |
894 | } |
864 | |
895 | |
865 | #define dREQ(reqtype) \ |
896 | #define dREQ(reqtype) \ |
… | |
… | |
1102 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1133 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1103 | |
1134 | |
1104 | newCONSTSUB (stash, "DB_VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1)); |
1135 | newCONSTSUB (stash, "DB_VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1)); |
1105 | newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1136 | newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1106 | |
1137 | |
1107 | create_pipe (respipe); |
1138 | create_respipe (); |
1108 | |
1139 | |
1109 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1140 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1110 | #ifdef _WIN32 |
1141 | #ifdef _WIN32 |
1111 | X_MUTEX_CHECK (wrklock); |
1142 | X_MUTEX_CHECK (wrklock); |
1112 | X_MUTEX_CHECK (reslock); |
1143 | X_MUTEX_CHECK (reslock); |
… | |
… | |
1500 | REQ_SEND; |
1531 | REQ_SEND; |
1501 | ptr_nuke (ST (0)); |
1532 | ptr_nuke (ST (0)); |
1502 | } |
1533 | } |
1503 | |
1534 | |
1504 | void |
1535 | void |
|
|
1536 | db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef) |
|
|
1537 | CODE: |
|
|
1538 | { |
|
|
1539 | dREQ (REQ_TXN_FINISH); |
|
|
1540 | req->txn = txn; |
|
|
1541 | req->uint1 = flags; |
|
|
1542 | REQ_SEND; |
|
|
1543 | ptr_nuke (ST (0)); |
|
|
1544 | } |
|
|
1545 | |
|
|
1546 | void |
1505 | db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) |
1547 | db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) |
1506 | CODE: |
1548 | CODE: |
1507 | { |
1549 | { |
1508 | dREQ (REQ_C_CLOSE); |
1550 | dREQ (REQ_C_CLOSE); |
1509 | req->dbc = dbc; |
1551 | req->dbc = dbc; |
… | |
… | |
1707 | CODE: |
1749 | CODE: |
1708 | RETVAL = env->set_encrypt (env, password, flags); |
1750 | RETVAL = env->set_encrypt (env, password, flags); |
1709 | OUTPUT: |
1751 | OUTPUT: |
1710 | RETVAL |
1752 | RETVAL |
1711 | |
1753 | |
1712 | int set_timeout (DB_ENV *env, NV timeout, U32 flags) |
1754 | int set_timeout (DB_ENV *env, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
1713 | CODE: |
1755 | CODE: |
1714 | RETVAL = env->set_timeout (env, timeout * 1000000, flags); |
1756 | RETVAL = env->set_timeout (env, timeout * 1000000, flags); |
1715 | OUTPUT: |
1757 | OUTPUT: |
1716 | RETVAL |
1758 | RETVAL |
1717 | |
1759 | |
… | |
… | |
1889 | DESTROY (DB_TXN_ornull *txn) |
1931 | DESTROY (DB_TXN_ornull *txn) |
1890 | CODE: |
1932 | CODE: |
1891 | if (txn) |
1933 | if (txn) |
1892 | txn->abort (txn); |
1934 | txn->abort (txn); |
1893 | |
1935 | |
1894 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags) |
1936 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
1895 | CODE: |
1937 | CODE: |
1896 | RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); |
1938 | RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); |
|
|
1939 | OUTPUT: |
|
|
1940 | RETVAL |
|
|
1941 | |
|
|
1942 | int failed (DB_TXN *txn) |
|
|
1943 | CODE: |
|
|
1944 | RETVAL = !!(txn->flags & TXN_DEADLOCK); |
1897 | OUTPUT: |
1945 | OUTPUT: |
1898 | RETVAL |
1946 | RETVAL |
1899 | |
1947 | |
1900 | |
1948 | |
1901 | MODULE = BDB PACKAGE = BDB::Cursor |
1949 | MODULE = BDB PACKAGE = BDB::Cursor |