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.23 by root, Fri Dec 7 13:38:54 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
316 dbt_to_sv (req->sv1, &req->dbt1); 326 dbt_to_sv (req->sv1, &req->dbt1);
317 dbt_to_sv (req->sv2, &req->dbt2); 327 dbt_to_sv (req->sv2, &req->dbt2);
318 dbt_to_sv (req->sv3, &req->dbt3); 328 dbt_to_sv (req->sv3, &req->dbt3);
319 break; 329 break;
320 330
331 case REQ_DB_PUT:
332 case REQ_C_PUT:
333 dbt_to_sv (0, &req->dbt1);
334 dbt_to_sv (0, &req->dbt2);
335 break;
336
321 case REQ_DB_KEY_RANGE: 337 case REQ_DB_KEY_RANGE:
322 { 338 {
323 AV *av = newAV (); 339 AV *av = newAV ();
324 340
325 av_push (av, newSVnv (req->key_range.less)); 341 av_push (av, newSVnv (req->key_range.less));
334 350
335 case REQ_SEQ_GET: 351 case REQ_SEQ_GET:
336 SvREADONLY_off (req->sv1); 352 SvREADONLY_off (req->sv1);
337 353
338 if (sizeof (IV) > 4) 354 if (sizeof (IV) > 4)
339 sv_setiv_mg (req->sv1, req->seq_t); 355 sv_setiv_mg (req->sv1, (IV)req->seq_t);
340 else 356 else
341 sv_setnv_mg (req->sv1, req->seq_t); 357 sv_setnv_mg (req->sv1, (NV)req->seq_t);
342 358
343 SvREFCNT_dec (req->sv1); 359 SvREFCNT_dec (req->sv1);
344 break; 360 break;
345 } 361 }
346 362
369#else 385#else
370# define TO_SOCKET(x) (x) 386# define TO_SOCKET(x) (x)
371#endif 387#endif
372 388
373static void 389static void
374create_pipe (int fd[2]) 390create_respipe ()
375{ 391{
376#ifdef _WIN32 392#ifdef _WIN32
377 int arg = 1; 393 int arg; /* argg */
394#endif
395 int old_readfd = respipe [0];
396
397 if (respipe [1] >= 0)
398 respipe_close (TO_SOCKET (respipe [1]));
399
400#ifdef _WIN32
378 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, fd) 401 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe))
379 || ioctlsocket (TO_SOCKET (fd [0]), FIONBIO, &arg)
380 || ioctlsocket (TO_SOCKET (fd [1]), FIONBIO, &arg))
381#else 402#else
382 if (pipe (fd) 403 if (pipe (respipe))
383 || fcntl (fd [0], F_SETFL, O_NONBLOCK)
384 || fcntl (fd [1], F_SETFL, O_NONBLOCK))
385#endif 404#endif
386 croak ("unable to initialize result pipe"); 405 croak ("unable to initialize result pipe");
406
407 if (old_readfd >= 0)
408 {
409 if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0)
410 croak ("unable to initialize result pipe(2)");
411
412 respipe_close (respipe [0]);
413 respipe [0] = old_readfd;
414 }
415
416#ifdef _WIN32
417 arg = 1;
418 if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg)
419 || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg))
420#else
421 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)
422 || fcntl (respipe [1], F_SETFL, O_NONBLOCK))
423#endif
424 croak ("unable to initialize result pipe(3)");
387 425
388 respipe_osf [0] = TO_SOCKET (respipe [0]); 426 respipe_osf [0] = TO_SOCKET (respipe [0]);
389 respipe_osf [1] = TO_SOCKET (respipe [1]); 427 respipe_osf [1] = TO_SOCKET (respipe [1]);
390} 428}
391 429
658 X_UNLOCK (reqlock); 696 X_UNLOCK (reqlock);
659 697
660 switch (req->type) 698 switch (req->type)
661 { 699 {
662 case REQ_QUIT: 700 case REQ_QUIT:
701 req->result = ENOSYS;
663 goto quit; 702 goto quit;
664 703
665 case REQ_ENV_OPEN: 704 case REQ_ENV_OPEN:
666 req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1); 705 req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1);
667 break; 706 break;
726 req->result = req->txn->commit (req->txn, req->uint1); 765 req->result = req->txn->commit (req->txn, req->uint1);
727 break; 766 break;
728 767
729 case REQ_TXN_ABORT: 768 case REQ_TXN_ABORT:
730 req->result = req->txn->abort (req->txn); 769 req->result = req->txn->abort (req->txn);
770 break;
771
772 case REQ_TXN_FINISH:
773 if (req->txn->flags & TXN_DEADLOCK)
774 {
775 req->result = req->txn->abort (req->txn);
776 if (!req->result)
777 req->result = DB_LOCK_DEADLOCK;
778 }
779 else
780 req->result = req->txn->commit (req->txn, req->uint1);
731 break; 781 break;
732 782
733 case REQ_C_CLOSE: 783 case REQ_C_CLOSE:
734 req->result = req->dbc->c_close (req->dbc); 784 req->result = req->dbc->c_close (req->dbc);
735 break; 785 break;
777 default: 827 default:
778 req->result = ENOSYS; 828 req->result = ENOSYS;
779 break; 829 break;
780 } 830 }
781 831
832 if (req->txn && (req->result > 0 || req->result == DB_LOCK_NOTGRANTED))
833 req->txn->flags |= TXN_DEADLOCK;
834
782 X_LOCK (reslock); 835 X_LOCK (reslock);
783 836
784 ++npending; 837 ++npending;
785 838
786 if (!reqq_push (&res_queue, req)) 839 if (!reqq_push (&res_queue, req))
842 idle = 0; 895 idle = 0;
843 nreqs = 0; 896 nreqs = 0;
844 nready = 0; 897 nready = 0;
845 npending = 0; 898 npending = 0;
846 899
847 respipe_close (respipe [0]);
848 respipe_close (respipe [1]);
849
850 create_pipe (respipe); 900 create_respipe ();
851 901
852 atfork_parent (); 902 atfork_parent ();
853} 903}
854 904
855#define dREQ(reqtype) \ 905#define dREQ(reqtype) \
919 const_iv (INIT_TXN) 969 const_iv (INIT_TXN)
920 const_iv (RECOVER) 970 const_iv (RECOVER)
921 const_iv (INIT_TXN) 971 const_iv (INIT_TXN)
922 const_iv (RECOVER_FATAL) 972 const_iv (RECOVER_FATAL)
923 const_iv (CREATE) 973 const_iv (CREATE)
974 const_iv (RDONLY)
924 const_iv (USE_ENVIRON) 975 const_iv (USE_ENVIRON)
925 const_iv (USE_ENVIRON_ROOT) 976 const_iv (USE_ENVIRON_ROOT)
926 const_iv (LOCKDOWN) 977 const_iv (LOCKDOWN)
927 const_iv (PRIVATE) 978 const_iv (PRIVATE)
928 const_iv (REGISTER) 979 const_iv (REGISTER)
941 const_iv (OVERWRITE) 992 const_iv (OVERWRITE)
942 const_iv (PANIC_ENVIRONMENT) 993 const_iv (PANIC_ENVIRONMENT)
943 const_iv (REGION_INIT) 994 const_iv (REGION_INIT)
944 const_iv (TIME_NOTGRANTED) 995 const_iv (TIME_NOTGRANTED)
945 const_iv (TXN_NOSYNC) 996 const_iv (TXN_NOSYNC)
997 const_iv (TXN_NOT_DURABLE)
946 const_iv (TXN_WRITE_NOSYNC) 998 const_iv (TXN_WRITE_NOSYNC)
947 const_iv (WRITECURSOR) 999 const_iv (WRITECURSOR)
948 const_iv (YIELDCPU) 1000 const_iv (YIELDCPU)
949 const_iv (ENCRYPT_AES) 1001 const_iv (ENCRYPT_AES)
950 const_iv (XA_CREATE) 1002 const_iv (XA_CREATE)
958 const_iv (READ_UNCOMMITTED) 1010 const_iv (READ_UNCOMMITTED)
959 const_iv (TRUNCATE) 1011 const_iv (TRUNCATE)
960 const_iv (NOSYNC) 1012 const_iv (NOSYNC)
961 const_iv (CHKSUM) 1013 const_iv (CHKSUM)
962 const_iv (ENCRYPT) 1014 const_iv (ENCRYPT)
963 const_iv (TXN_NOT_DURABLE)
964 const_iv (DUP) 1015 const_iv (DUP)
965 const_iv (DUPSORT) 1016 const_iv (DUPSORT)
966 const_iv (RECNUM) 1017 const_iv (RECNUM)
967 const_iv (RENUMBER) 1018 const_iv (RENUMBER)
968 const_iv (REVSPLITOFF) 1019 const_iv (REVSPLITOFF)
1074#if DB_VERSION_MINOR >= 5 1125#if DB_VERSION_MINOR >= 5
1075 const_iv (MULTIVERSION) 1126 const_iv (MULTIVERSION)
1076 const_iv (TXN_SNAPSHOT) 1127 const_iv (TXN_SNAPSHOT)
1077#endif 1128#endif
1078#if DB_VERSION_MINOR >= 6 1129#if DB_VERSION_MINOR >= 6
1079 const_iv (DB_PREV_DUP) 1130 const_iv (PREV_DUP)
1131# if 0
1132 const_iv (PRIORITY_UNCHANGED)
1133 const_iv (PRIORITY_VERY_LOW)
1134 const_iv (PRIORITY_LOW)
1135 const_iv (PRIORITY_DEFAULT)
1136 const_iv (PRIORITY_HIGH)
1137 const_iv (PRIORITY_VERY_HIGH)
1138# endif
1080#endif 1139#endif
1081 }; 1140 };
1082 1141
1083 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1142 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1084 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1143 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1085 1144
1086 newCONSTSUB (stash, "DB_VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1)); 1145 newCONSTSUB (stash, "DB_VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1));
1087 newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); 1146 newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1088 1147
1089 create_pipe (respipe); 1148 create_respipe ();
1090 1149
1091 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1150 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1092#ifdef _WIN32 1151#ifdef _WIN32
1093 X_MUTEX_CHECK (wrklock); 1152 X_MUTEX_CHECK (wrklock);
1094 X_MUTEX_CHECK (reslock); 1153 X_MUTEX_CHECK (reslock);
1482 REQ_SEND; 1541 REQ_SEND;
1483 ptr_nuke (ST (0)); 1542 ptr_nuke (ST (0));
1484} 1543}
1485 1544
1486void 1545void
1546db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef)
1547 CODE:
1548{
1549 dREQ (REQ_TXN_FINISH);
1550 req->txn = txn;
1551 req->uint1 = flags;
1552 REQ_SEND;
1553 ptr_nuke (ST (0));
1554}
1555
1556void
1487db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) 1557db_c_close (DBC *dbc, SV *callback = &PL_sv_undef)
1488 CODE: 1558 CODE:
1489{ 1559{
1490 dREQ (REQ_C_CLOSE); 1560 dREQ (REQ_C_CLOSE);
1491 req->dbc = dbc; 1561 req->dbc = dbc;
1669 CODE: 1739 CODE:
1670 RETVAL = env->set_flags (env, flags, onoff); 1740 RETVAL = env->set_flags (env, flags, onoff);
1671 OUTPUT: 1741 OUTPUT:
1672 RETVAL 1742 RETVAL
1673 1743
1674void set_errfile (DB_ENV *env, FILE *errfile) 1744void set_errfile (DB_ENV *env, FILE *errfile = 0)
1675 CODE: 1745 CODE:
1676 env->set_errfile (env, errfile); 1746 env->set_errfile (env, errfile);
1677 1747
1678void set_msgfile (DB_ENV *env, FILE *msgfile) 1748void set_msgfile (DB_ENV *env, FILE *msgfile = 0)
1679 CODE: 1749 CODE:
1680 env->set_msgfile (env, msgfile); 1750 env->set_msgfile (env, msgfile);
1681 1751
1682int set_verbose (DB_ENV *env, U32 which, int onoff = 1) 1752int set_verbose (DB_ENV *env, U32 which, int onoff = 1)
1683 CODE: 1753 CODE:
1689 CODE: 1759 CODE:
1690 RETVAL = env->set_encrypt (env, password, flags); 1760 RETVAL = env->set_encrypt (env, password, flags);
1691 OUTPUT: 1761 OUTPUT:
1692 RETVAL 1762 RETVAL
1693 1763
1694int set_timeout (DB_ENV *env, NV timeout, U32 flags) 1764int set_timeout (DB_ENV *env, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT)
1695 CODE: 1765 CODE:
1696 RETVAL = env->set_timeout (env, timeout * 1000000, flags); 1766 RETVAL = env->set_timeout (env, timeout * 1000000, flags);
1697 OUTPUT: 1767 OUTPUT:
1698 RETVAL 1768 RETVAL
1699 1769
1747 1817
1748int set_lg_max (DB_ENV *env, U32 max) 1818int set_lg_max (DB_ENV *env, U32 max)
1749 CODE: 1819 CODE:
1750 RETVAL = env->set_lg_max (env, max); 1820 RETVAL = env->set_lg_max (env, max);
1751 OUTPUT: 1821 OUTPUT:
1822 RETVAL
1823
1824int mutex_set_max (DB_ENV *env, U32 max)
1825 CODE:
1826 RETVAL = env->mutex_set_max (env, max);
1827 OUTPUT:
1828 RETVAL
1829
1830int mutex_set_increment (DB_ENV *env, U32 increment)
1831 CODE:
1832 RETVAL = env->mutex_set_increment (env, increment);
1833 OUTPUT:
1834 RETVAL
1835
1836int mutex_set_tas_spins (DB_ENV *env, U32 tas_spins)
1837 CODE:
1838 RETVAL = env->mutex_set_tas_spins (env, tas_spins);
1839 OUTPUT:
1840 RETVAL
1841
1842int mutex_set_align (DB_ENV *env, U32 align)
1843 CODE:
1844 RETVAL = env->mutex_set_align (env, align);
1845 OUTPUT:
1752 RETVAL 1846 RETVAL
1753 1847
1754DB_TXN * 1848DB_TXN *
1755txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0) 1849txn_begin (DB_ENV *env, DB_TXN_ornull *parent = 0, U32 flags = 0)
1756 CODE: 1850 CODE:
1776 CODE: 1870 CODE:
1777 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); 1871 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache);
1778 OUTPUT: 1872 OUTPUT:
1779 RETVAL 1873 RETVAL
1780 1874
1781int set_flags (DB *db, U32 flags); 1875int set_flags (DB *db, U32 flags)
1782 CODE: 1876 CODE:
1783 RETVAL = db->set_flags (db, flags); 1877 RETVAL = db->set_flags (db, flags);
1784 OUTPUT: 1878 OUTPUT:
1785 RETVAL 1879 RETVAL
1786 1880
1800 CODE: 1894 CODE:
1801 RETVAL = db->set_bt_minkey (db, minkey); 1895 RETVAL = db->set_bt_minkey (db, minkey);
1802 OUTPUT: 1896 OUTPUT:
1803 RETVAL 1897 RETVAL
1804 1898
1805int set_re_delim(DB *db, int delim); 1899int set_re_delim (DB *db, int delim)
1806 CODE: 1900 CODE:
1807 RETVAL = db->set_re_delim (db, delim); 1901 RETVAL = db->set_re_delim (db, delim);
1808 OUTPUT: 1902 OUTPUT:
1809 RETVAL 1903 RETVAL
1810 1904
1871DESTROY (DB_TXN_ornull *txn) 1965DESTROY (DB_TXN_ornull *txn)
1872 CODE: 1966 CODE:
1873 if (txn) 1967 if (txn)
1874 txn->abort (txn); 1968 txn->abort (txn);
1875 1969
1876int set_timeout (DB_TXN *txn, NV timeout, U32 flags) 1970int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT)
1877 CODE: 1971 CODE:
1878 RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); 1972 RETVAL = txn->set_timeout (txn, timeout * 1000000, flags);
1973 OUTPUT:
1974 RETVAL
1975
1976int failed (DB_TXN *txn)
1977 CODE:
1978 RETVAL = !!(txn->flags & TXN_DEADLOCK);
1879 OUTPUT: 1979 OUTPUT:
1880 RETVAL 1980 RETVAL
1881 1981
1882 1982
1883MODULE = BDB PACKAGE = BDB::Cursor 1983MODULE = BDB PACKAGE = BDB::Cursor

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines