… | |
… | |
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 | |
… | |
… | |
741 | req->result = req->txn->abort (req->txn); |
760 | req->result = req->txn->abort (req->txn); |
742 | break; |
761 | break; |
743 | |
762 | |
744 | case REQ_TXN_FINISH: |
763 | case REQ_TXN_FINISH: |
745 | if (req->txn->flags & TXN_DEADLOCK) |
764 | if (req->txn->flags & TXN_DEADLOCK) |
746 | req->result = req->txn->commit (req->txn, req->uint1); |
|
|
747 | else |
|
|
748 | { |
765 | { |
749 | req->result = req->txn->abort (req->txn); |
766 | req->result = req->txn->abort (req->txn); |
750 | if (!req->result) |
767 | if (!req->result) |
751 | req->result = DB_LOCK_DEADLOCK; |
768 | req->result = DB_LOCK_DEADLOCK; |
752 | } |
769 | } |
|
|
770 | else |
|
|
771 | req->result = req->txn->commit (req->txn, req->uint1); |
753 | break; |
772 | break; |
754 | |
773 | |
755 | case REQ_C_CLOSE: |
774 | case REQ_C_CLOSE: |
756 | req->result = req->dbc->c_close (req->dbc); |
775 | req->result = req->dbc->c_close (req->dbc); |
757 | break; |
776 | break; |
… | |
… | |
867 | idle = 0; |
886 | idle = 0; |
868 | nreqs = 0; |
887 | nreqs = 0; |
869 | nready = 0; |
888 | nready = 0; |
870 | npending = 0; |
889 | npending = 0; |
871 | |
890 | |
872 | respipe_close (respipe [0]); |
|
|
873 | respipe_close (respipe [1]); |
|
|
874 | |
|
|
875 | create_pipe (respipe); |
891 | create_respipe (); |
876 | |
892 | |
877 | atfork_parent (); |
893 | atfork_parent (); |
878 | } |
894 | } |
879 | |
895 | |
880 | #define dREQ(reqtype) \ |
896 | #define dREQ(reqtype) \ |
… | |
… | |
944 | const_iv (INIT_TXN) |
960 | const_iv (INIT_TXN) |
945 | const_iv (RECOVER) |
961 | const_iv (RECOVER) |
946 | const_iv (INIT_TXN) |
962 | const_iv (INIT_TXN) |
947 | const_iv (RECOVER_FATAL) |
963 | const_iv (RECOVER_FATAL) |
948 | const_iv (CREATE) |
964 | const_iv (CREATE) |
|
|
965 | const_iv (RDONLY) |
949 | const_iv (USE_ENVIRON) |
966 | const_iv (USE_ENVIRON) |
950 | const_iv (USE_ENVIRON_ROOT) |
967 | const_iv (USE_ENVIRON_ROOT) |
951 | const_iv (LOCKDOWN) |
968 | const_iv (LOCKDOWN) |
952 | const_iv (PRIVATE) |
969 | const_iv (PRIVATE) |
953 | const_iv (REGISTER) |
970 | const_iv (REGISTER) |
… | |
… | |
966 | const_iv (OVERWRITE) |
983 | const_iv (OVERWRITE) |
967 | const_iv (PANIC_ENVIRONMENT) |
984 | const_iv (PANIC_ENVIRONMENT) |
968 | const_iv (REGION_INIT) |
985 | const_iv (REGION_INIT) |
969 | const_iv (TIME_NOTGRANTED) |
986 | const_iv (TIME_NOTGRANTED) |
970 | const_iv (TXN_NOSYNC) |
987 | const_iv (TXN_NOSYNC) |
|
|
988 | const_iv (TXN_NOT_DURABLE) |
971 | const_iv (TXN_WRITE_NOSYNC) |
989 | const_iv (TXN_WRITE_NOSYNC) |
972 | const_iv (WRITECURSOR) |
990 | const_iv (WRITECURSOR) |
973 | const_iv (YIELDCPU) |
991 | const_iv (YIELDCPU) |
974 | const_iv (ENCRYPT_AES) |
992 | const_iv (ENCRYPT_AES) |
975 | const_iv (XA_CREATE) |
993 | const_iv (XA_CREATE) |
… | |
… | |
983 | const_iv (READ_UNCOMMITTED) |
1001 | const_iv (READ_UNCOMMITTED) |
984 | const_iv (TRUNCATE) |
1002 | const_iv (TRUNCATE) |
985 | const_iv (NOSYNC) |
1003 | const_iv (NOSYNC) |
986 | const_iv (CHKSUM) |
1004 | const_iv (CHKSUM) |
987 | const_iv (ENCRYPT) |
1005 | const_iv (ENCRYPT) |
988 | const_iv (TXN_NOT_DURABLE) |
|
|
989 | const_iv (DUP) |
1006 | const_iv (DUP) |
990 | const_iv (DUPSORT) |
1007 | const_iv (DUPSORT) |
991 | const_iv (RECNUM) |
1008 | const_iv (RECNUM) |
992 | const_iv (RENUMBER) |
1009 | const_iv (RENUMBER) |
993 | const_iv (REVSPLITOFF) |
1010 | const_iv (REVSPLITOFF) |
… | |
… | |
1117 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1134 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1118 | |
1135 | |
1119 | newCONSTSUB (stash, "DB_VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1)); |
1136 | newCONSTSUB (stash, "DB_VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1)); |
1120 | newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1137 | newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1121 | |
1138 | |
1122 | create_pipe (respipe); |
1139 | create_respipe (); |
1123 | |
1140 | |
1124 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1141 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1125 | #ifdef _WIN32 |
1142 | #ifdef _WIN32 |
1126 | X_MUTEX_CHECK (wrklock); |
1143 | X_MUTEX_CHECK (wrklock); |
1127 | X_MUTEX_CHECK (reslock); |
1144 | X_MUTEX_CHECK (reslock); |