ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/BDB/BDB.xs
(Generate patch)

Comparing BDB/BDB.xs (file contents):
Revision 1.15 by root, Mon Aug 13 11:16:22 2007 UTC vs.
Revision 1.20 by root, Tue Dec 4 10:13:50 2007 UTC

45typedef SV SV8; /* byte-sv, used for argument-checking */ 45typedef SV SV8; /* byte-sv, used for argument-checking */
46typedef char *octetstring; 46typedef char *octetstring;
47 47
48static SV *prepare_cb; 48static SV *prepare_cb;
49 49
50#if DB_VERSION_MINOR >= 6
51# define c_close close
52# define c_count count
53# define c_del del
54# define c_dup dup
55# define c_get get
56# define c_pget pget
57# define c_put put
58#endif
59
50static void 60static void
51debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) 61debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg)
52{ 62{
53 printf ("err[%s]\n", msg); 63 printf ("err[%s]\n", msg);
54} 64}
94 REQ_QUIT, 104 REQ_QUIT,
95 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,
96 REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, 106 REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE,
97 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,
98 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,
99 REQ_TXN_COMMIT, REQ_TXN_ABORT, 109 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH,
100 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,
101 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,
102}; 112};
103 113
104typedef struct aio_cb 114typedef struct aio_cb
181} 191}
182 192
183static volatile unsigned int nreqs, nready, npending; 193static volatile unsigned int nreqs, nready, npending;
184static volatile unsigned int max_idle = 4; 194static volatile unsigned int max_idle = 4;
185static volatile unsigned int max_outstanding = 0xffffffff; 195static volatile unsigned int max_outstanding = 0xffffffff;
186static int respipe [2], respipe_osf [2]; 196static int respipe_osf [2], respipe [2] = { -1, -1 };
187 197
188static mutex_t reslock = X_MUTEX_INIT; 198static mutex_t reslock = X_MUTEX_INIT;
189static mutex_t reqlock = X_MUTEX_INIT; 199static mutex_t reqlock = X_MUTEX_INIT;
190static cond_t reqwait = X_COND_INIT; 200static cond_t reqwait = X_COND_INIT;
191 201
369#else 379#else
370# define TO_SOCKET(x) (x) 380# define TO_SOCKET(x) (x)
371#endif 381#endif
372 382
373static void 383static void
374create_pipe (int fd[2]) 384create_respipe ()
375{ 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
376#ifdef _WIN32 407#ifdef _WIN32
377 int arg = 1; 408 int arg = 1;
378 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, fd)
379 || ioctlsocket (TO_SOCKET (fd [0]), FIONBIO, &arg) 409 if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg)
380 || ioctlsocket (TO_SOCKET (fd [1]), FIONBIO, &arg)) 410 || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg))
381#else 411#else
382 if (pipe (fd)
383 || fcntl (fd [0], F_SETFL, O_NONBLOCK) 412 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
384 || fcntl (fd [1], F_SETFL, O_NONBLOCK)) 413 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
385#endif 414#endif
386 croak ("unable to initialize result pipe"); 415 croak ("unable to initialize result pipe(3)");
387 416
388 respipe_osf [0] = TO_SOCKET (respipe [0]); 417 respipe_osf [0] = TO_SOCKET (respipe [0]);
389 respipe_osf [1] = TO_SOCKET (respipe [1]); 418 respipe_osf [1] = TO_SOCKET (respipe [1]);
390} 419}
391 420
658 X_UNLOCK (reqlock); 687 X_UNLOCK (reqlock);
659 688
660 switch (req->type) 689 switch (req->type)
661 { 690 {
662 case REQ_QUIT: 691 case REQ_QUIT:
692 req->result = ENOSYS;
663 goto quit; 693 goto quit;
664 694
665 case REQ_ENV_OPEN: 695 case REQ_ENV_OPEN:
666 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);
667 break; 697 break;
726 req->result = req->txn->commit (req->txn, req->uint1); 756 req->result = req->txn->commit (req->txn, req->uint1);
727 break; 757 break;
728 758
729 case REQ_TXN_ABORT: 759 case REQ_TXN_ABORT:
730 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);
731 break; 772 break;
732 773
733 case REQ_C_CLOSE: 774 case REQ_C_CLOSE:
734 req->result = req->dbc->c_close (req->dbc); 775 req->result = req->dbc->c_close (req->dbc);
735 break; 776 break;
777 default: 818 default:
778 req->result = ENOSYS; 819 req->result = ENOSYS;
779 break; 820 break;
780 } 821 }
781 822
823 if (req->txn && (req->result > 0 || req->result == DB_LOCK_NOTGRANTED))
824 req->txn->flags |= TXN_DEADLOCK;
825
782 X_LOCK (reslock); 826 X_LOCK (reslock);
783 827
784 ++npending; 828 ++npending;
785 829
786 if (!reqq_push (&res_queue, req)) 830 if (!reqq_push (&res_queue, req))
842 idle = 0; 886 idle = 0;
843 nreqs = 0; 887 nreqs = 0;
844 nready = 0; 888 nready = 0;
845 npending = 0; 889 npending = 0;
846 890
847 respipe_close (respipe [0]);
848 respipe_close (respipe [1]);
849
850 create_pipe (respipe); 891 create_respipe ();
851 892
852 atfork_parent (); 893 atfork_parent ();
853} 894}
854 895
855#define dREQ(reqtype) \ 896#define dREQ(reqtype) \
919 const_iv (INIT_TXN) 960 const_iv (INIT_TXN)
920 const_iv (RECOVER) 961 const_iv (RECOVER)
921 const_iv (INIT_TXN) 962 const_iv (INIT_TXN)
922 const_iv (RECOVER_FATAL) 963 const_iv (RECOVER_FATAL)
923 const_iv (CREATE) 964 const_iv (CREATE)
965 const_iv (RDONLY)
924 const_iv (USE_ENVIRON) 966 const_iv (USE_ENVIRON)
925 const_iv (USE_ENVIRON_ROOT) 967 const_iv (USE_ENVIRON_ROOT)
926 const_iv (LOCKDOWN) 968 const_iv (LOCKDOWN)
927 const_iv (PRIVATE) 969 const_iv (PRIVATE)
928 const_iv (REGISTER) 970 const_iv (REGISTER)
941 const_iv (OVERWRITE) 983 const_iv (OVERWRITE)
942 const_iv (PANIC_ENVIRONMENT) 984 const_iv (PANIC_ENVIRONMENT)
943 const_iv (REGION_INIT) 985 const_iv (REGION_INIT)
944 const_iv (TIME_NOTGRANTED) 986 const_iv (TIME_NOTGRANTED)
945 const_iv (TXN_NOSYNC) 987 const_iv (TXN_NOSYNC)
988 const_iv (TXN_NOT_DURABLE)
946 const_iv (TXN_WRITE_NOSYNC) 989 const_iv (TXN_WRITE_NOSYNC)
947 const_iv (WRITECURSOR) 990 const_iv (WRITECURSOR)
948 const_iv (YIELDCPU) 991 const_iv (YIELDCPU)
949 const_iv (ENCRYPT_AES) 992 const_iv (ENCRYPT_AES)
950 const_iv (XA_CREATE) 993 const_iv (XA_CREATE)
958 const_iv (READ_UNCOMMITTED) 1001 const_iv (READ_UNCOMMITTED)
959 const_iv (TRUNCATE) 1002 const_iv (TRUNCATE)
960 const_iv (NOSYNC) 1003 const_iv (NOSYNC)
961 const_iv (CHKSUM) 1004 const_iv (CHKSUM)
962 const_iv (ENCRYPT) 1005 const_iv (ENCRYPT)
963 const_iv (TXN_NOT_DURABLE)
964 const_iv (DUP) 1006 const_iv (DUP)
965 const_iv (DUPSORT) 1007 const_iv (DUPSORT)
966 const_iv (RECNUM) 1008 const_iv (RECNUM)
967 const_iv (RENUMBER) 1009 const_iv (RENUMBER)
968 const_iv (REVSPLITOFF) 1010 const_iv (REVSPLITOFF)
1074#if DB_VERSION_MINOR >= 5 1116#if DB_VERSION_MINOR >= 5
1075 const_iv (MULTIVERSION) 1117 const_iv (MULTIVERSION)
1076 const_iv (TXN_SNAPSHOT) 1118 const_iv (TXN_SNAPSHOT)
1077#endif 1119#endif
1078#if DB_VERSION_MINOR >= 6 1120#if DB_VERSION_MINOR >= 6
1079 const_iv (DB_PREV_DUP) 1121 const_iv (PREV_DUP)
1122# if 0
1123 const_iv (PRIORITY_UNCHANGED)
1124 const_iv (PRIORITY_VERY_LOW)
1125 const_iv (PRIORITY_LOW)
1126 const_iv (PRIORITY_DEFAULT)
1127 const_iv (PRIORITY_HIGH)
1128 const_iv (PRIORITY_VERY_HIGH)
1129# endif
1080#endif 1130#endif
1081 }; 1131 };
1082 1132
1083 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1133 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1084 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1134 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1085 1135
1086 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));
1087 newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); 1137 newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1088 1138
1089 create_pipe (respipe); 1139 create_respipe ();
1090 1140
1091 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1141 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1092#ifdef _WIN32 1142#ifdef _WIN32
1093 X_MUTEX_CHECK (wrklock); 1143 X_MUTEX_CHECK (wrklock);
1094 X_MUTEX_CHECK (reslock); 1144 X_MUTEX_CHECK (reslock);
1482 REQ_SEND; 1532 REQ_SEND;
1483 ptr_nuke (ST (0)); 1533 ptr_nuke (ST (0));
1484} 1534}
1485 1535
1486void 1536void
1537db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef)
1538 CODE:
1539{
1540 dREQ (REQ_TXN_FINISH);
1541 req->txn = txn;
1542 req->uint1 = flags;
1543 REQ_SEND;
1544 ptr_nuke (ST (0));
1545}
1546
1547void
1487db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) 1548db_c_close (DBC *dbc, SV *callback = &PL_sv_undef)
1488 CODE: 1549 CODE:
1489{ 1550{
1490 dREQ (REQ_C_CLOSE); 1551 dREQ (REQ_C_CLOSE);
1491 req->dbc = dbc; 1552 req->dbc = dbc;
1669 CODE: 1730 CODE:
1670 RETVAL = env->set_flags (env, flags, onoff); 1731 RETVAL = env->set_flags (env, flags, onoff);
1671 OUTPUT: 1732 OUTPUT:
1672 RETVAL 1733 RETVAL
1673 1734
1674void set_errfile (DB_ENV *env, FILE *errfile) 1735void set_errfile (DB_ENV *env, FILE *errfile = 0)
1675 CODE: 1736 CODE:
1676 env->set_errfile (env, errfile); 1737 env->set_errfile (env, errfile);
1677 1738
1678void set_msgfile (DB_ENV *env, FILE *msgfile) 1739void set_msgfile (DB_ENV *env, FILE *msgfile = 0)
1679 CODE: 1740 CODE:
1680 env->set_msgfile (env, msgfile); 1741 env->set_msgfile (env, msgfile);
1681 1742
1682int set_verbose (DB_ENV *env, U32 which, int onoff = 1) 1743int set_verbose (DB_ENV *env, U32 which, int onoff = 1)
1683 CODE: 1744 CODE:
1689 CODE: 1750 CODE:
1690 RETVAL = env->set_encrypt (env, password, flags); 1751 RETVAL = env->set_encrypt (env, password, flags);
1691 OUTPUT: 1752 OUTPUT:
1692 RETVAL 1753 RETVAL
1693 1754
1694int set_timeout (DB_ENV *env, NV timeout, U32 flags) 1755int set_timeout (DB_ENV *env, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT)
1695 CODE: 1756 CODE:
1696 RETVAL = env->set_timeout (env, timeout * 1000000, flags); 1757 RETVAL = env->set_timeout (env, timeout * 1000000, flags);
1697 OUTPUT: 1758 OUTPUT:
1698 RETVAL 1759 RETVAL
1699 1760
1776 CODE: 1837 CODE:
1777 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); 1838 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache);
1778 OUTPUT: 1839 OUTPUT:
1779 RETVAL 1840 RETVAL
1780 1841
1781int set_flags (DB *db, U32 flags); 1842int set_flags (DB *db, U32 flags)
1782 CODE: 1843 CODE:
1783 RETVAL = db->set_flags (db, flags); 1844 RETVAL = db->set_flags (db, flags);
1784 OUTPUT: 1845 OUTPUT:
1785 RETVAL 1846 RETVAL
1786 1847
1800 CODE: 1861 CODE:
1801 RETVAL = db->set_bt_minkey (db, minkey); 1862 RETVAL = db->set_bt_minkey (db, minkey);
1802 OUTPUT: 1863 OUTPUT:
1803 RETVAL 1864 RETVAL
1804 1865
1805int set_re_delim(DB *db, int delim); 1866int set_re_delim (DB *db, int delim)
1806 CODE: 1867 CODE:
1807 RETVAL = db->set_re_delim (db, delim); 1868 RETVAL = db->set_re_delim (db, delim);
1808 OUTPUT: 1869 OUTPUT:
1809 RETVAL 1870 RETVAL
1810 1871
1871DESTROY (DB_TXN_ornull *txn) 1932DESTROY (DB_TXN_ornull *txn)
1872 CODE: 1933 CODE:
1873 if (txn) 1934 if (txn)
1874 txn->abort (txn); 1935 txn->abort (txn);
1875 1936
1876int set_timeout (DB_TXN *txn, NV timeout, U32 flags) 1937int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT)
1877 CODE: 1938 CODE:
1878 RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); 1939 RETVAL = txn->set_timeout (txn, timeout * 1000000, flags);
1940 OUTPUT:
1941 RETVAL
1942
1943int failed (DB_TXN *txn)
1944 CODE:
1945 RETVAL = !!(txn->flags & TXN_DEADLOCK);
1879 OUTPUT: 1946 OUTPUT:
1880 RETVAL 1947 RETVAL
1881 1948
1882 1949
1883MODULE = BDB PACKAGE = BDB::Cursor 1950MODULE = BDB PACKAGE = BDB::Cursor

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines