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

Comparing BDB/BDB.xs (file contents):
Revision 1.31 by root, Sun Mar 30 04:34:20 2008 UTC vs.
Revision 1.38 by root, Wed May 21 19:13:43 2008 UTC

47typedef DBC DBC_ornuked; 47typedef DBC DBC_ornuked;
48typedef DB DB_ornuked; 48typedef DB DB_ornuked;
49typedef DB_SEQUENCE DB_SEQUENCE_ornuked; 49typedef DB_SEQUENCE DB_SEQUENCE_ornuked;
50 50
51typedef SV SV8; /* byte-sv, used for argument-checking */ 51typedef SV SV8; /* byte-sv, used for argument-checking */
52typedef char *octetstring; 52typedef char *bdb_filename;
53 53
54static SV *prepare_cb; 54static SV *prepare_cb;
55 55
56#if DB_VERSION_MINOR >= 6 56#if DB_VERSION_MINOR >= 6
57# define c_close close 57# define c_close close
60# define c_dup dup 60# define c_dup dup
61# define c_get get 61# define c_get get
62# define c_pget pget 62# define c_pget pget
63# define c_put put 63# define c_put put
64#endif 64#endif
65
66static char *
67get_bdb_filename (SV *sv)
68{
69 if (!SvOK (sv))
70 return 0;
71
72#if _WIN32
73 /* win32 madness + win32 perl absolutely brokenness make for horrible hacks */
74 {
75 STRLEN len;
76 char *src = SvPVbyte (sv, len);
77 SV *t1 = sv_newmortal ();
78 SV *t2 = sv_newmortal ();
79
80 sv_upgrade (t1, SVt_PV); SvPOK_only (t1); SvGROW (t1, len * 16 + 1);
81 sv_upgrade (t2, SVt_PV); SvPOK_only (t2); SvGROW (t2, len * 16 + 1);
82
83 len = MultiByteToWideChar (CP_ACP, 0, src, len, (WCHAR *)SvPVX (t1), SvLEN (t1) / sizeof (WCHAR));
84 len = WideCharToMultiByte (CP_UTF8, 0, (WCHAR *)SvPVX (t1), len, SvPVX (t2), SvLEN (t2), 0, 0);
85 SvPOK_only (t2);
86 SvPVX (t2)[len] = 0;
87 SvCUR_set (t2, len);
88
89 return SvPVX (t2);
90 }
91#else
92 return SvPVbyte_nolen (sv);
93#endif
94}
65 95
66static void 96static void
67debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) 97debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg)
68{ 98{
69 printf ("err[%s]\n", msg); 99 printf ("err[%s]\n", msg);
151 NUM_PRI = PRI_MAX + PRI_BIAS + 1, 181 NUM_PRI = PRI_MAX + PRI_BIAS + 1,
152}; 182};
153 183
154#define AIO_TICKS ((1000000 + 1023) >> 10) 184#define AIO_TICKS ((1000000 + 1023) >> 10)
155 185
186static SV *on_next_submit;
187
156static unsigned int max_poll_time = 0; 188static unsigned int max_poll_time = 0;
157static unsigned int max_poll_reqs = 0; 189static unsigned int max_poll_reqs = 0;
158 190
159/* calculcate time difference in ~1/AIO_TICKS of a second */ 191/* calculcate time difference in ~1/AIO_TICKS of a second */
160static int tvdiff (struct timeval *tv1, struct timeval *tv2) 192static int tvdiff (struct timeval *tv1, struct timeval *tv2)
205static mutex_t reqlock = X_MUTEX_INIT; 237static mutex_t reqlock = X_MUTEX_INIT;
206static cond_t reqwait = X_COND_INIT; 238static cond_t reqwait = X_COND_INIT;
207 239
208#if WORDACCESS_UNSAFE 240#if WORDACCESS_UNSAFE
209 241
210static unsigned int get_nready () 242static unsigned int get_nready (void)
211{ 243{
212 unsigned int retval; 244 unsigned int retval;
213 245
214 X_LOCK (reqlock); 246 X_LOCK (reqlock);
215 retval = nready; 247 retval = nready;
216 X_UNLOCK (reqlock); 248 X_UNLOCK (reqlock);
217 249
218 return retval; 250 return retval;
219} 251}
220 252
221static unsigned int get_npending () 253static unsigned int get_npending (void)
222{ 254{
223 unsigned int retval; 255 unsigned int retval;
224 256
225 X_LOCK (reslock); 257 X_LOCK (reslock);
226 retval = npending; 258 retval = npending;
227 X_UNLOCK (reslock); 259 X_UNLOCK (reslock);
228 260
229 return retval; 261 return retval;
230} 262}
231 263
232static unsigned int get_nthreads () 264static unsigned int get_nthreads (void)
233{ 265{
234 unsigned int retval; 266 unsigned int retval;
235 267
236 X_LOCK (wrklock); 268 X_LOCK (wrklock);
237 retval = started; 269 retval = started;
300 } 332 }
301 333
302 abort (); 334 abort ();
303} 335}
304 336
305static int poll_cb (); 337static int poll_cb (void);
306static void req_free (bdb_req req); 338static void req_free (bdb_req req);
307static void req_cancel (bdb_req req); 339static void req_cancel (bdb_req req);
308 340
309static int req_invoke (bdb_req req) 341static int req_invoke (bdb_req req)
310{ 342{
391#else 423#else
392# define TO_SOCKET(x) (x) 424# define TO_SOCKET(x) (x)
393#endif 425#endif
394 426
395static void 427static void
396create_respipe () 428create_respipe (void)
397{ 429{
398#ifdef _WIN32 430#ifdef _WIN32
399 int arg; /* argg */ 431 int arg; /* argg */
400#endif 432#endif
401 int old_readfd = respipe [0]; 433 int old_readfd = respipe [0];
455 free (wrk); 487 free (wrk);
456 488
457 X_UNLOCK (wrklock); 489 X_UNLOCK (wrklock);
458} 490}
459 491
460static void maybe_start_thread () 492static void maybe_start_thread (void)
461{ 493{
462 if (get_nthreads () >= wanted) 494 if (get_nthreads () >= wanted)
463 return; 495 return;
464 496
465 /* todo: maybe use idle here, but might be less exact */ 497 /* todo: maybe use idle here, but might be less exact */
470} 502}
471 503
472static void req_send (bdb_req req) 504static void req_send (bdb_req req)
473{ 505{
474 SV *wait_callback = 0; 506 SV *wait_callback = 0;
507
508 if (on_next_submit)
509 {
510 dSP;
511 SV *cb = sv_2mortal (on_next_submit);
512
513 on_next_submit = 0;
514
515 PUSHMARK (SP);
516 PUTBACK;
517 call_sv (cb, G_DISCARD | G_EVAL);
518 }
475 519
476 // synthesize callback if none given 520 // synthesize callback if none given
477 if (!SvOK (req->callback)) 521 if (!SvOK (req->callback))
478 { 522 {
479 int count; 523 int count;
550 594
551 while (started > wanted) 595 while (started > wanted)
552 end_thread (); 596 end_thread ();
553} 597}
554 598
555static void poll_wait () 599static void poll_wait (void)
556{ 600{
557 fd_set rfd; 601 fd_set rfd;
558 602
559 while (nreqs) 603 while (nreqs)
560 { 604 {
573 617
574 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); 618 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
575 } 619 }
576} 620}
577 621
578static int poll_cb () 622static int poll_cb (void)
579{ 623{
580 dSP; 624 dSP;
581 int count = 0; 625 int count = 0;
582 int maxreqs = max_poll_reqs; 626 int maxreqs = max_poll_reqs;
583 int do_croak = 0; 627 int do_croak = 0;
960errno_get (pTHX_ SV *sv, MAGIC *mg) 1004errno_get (pTHX_ SV *sv, MAGIC *mg)
961{ 1005{
962 if (*mg->mg_ptr == '!') // should always be the case 1006 if (*mg->mg_ptr == '!') // should always be the case
963 if (-30999 <= errno && errno <= -30800) 1007 if (-30999 <= errno && errno <= -30800)
964 { 1008 {
1009 sv_setnv (sv, (NV)errno);
965 sv_setpv (sv, db_strerror (errno)); 1010 sv_setpv (sv, db_strerror (errno));
1011 SvNOK_on (sv); /* what a wonderful hack! */
1012 // ^^^ copied from perl sources
966 return 0; 1013 return 0;
967 } 1014 }
968 1015
969 return PL_vtbl_sv.svt_get (aTHX_ sv, mg); 1016 return PL_vtbl_sv.svt_get (aTHX_ sv, mg);
970} 1017}
1188 newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); 1235 newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1189 1236
1190 create_respipe (); 1237 create_respipe ();
1191 1238
1192 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1239 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1193#ifdef _WIN32
1194 X_MUTEX_CHECK (wrklock);
1195 X_MUTEX_CHECK (reslock);
1196 X_MUTEX_CHECK (reqlock);
1197
1198 X_COND_CHECK (reqwait);
1199#endif
1200 patch_errno (); 1240 patch_errno ();
1201} 1241}
1202 1242
1203void 1243void
1204max_poll_reqs (int nreqs) 1244max_poll_reqs (int nreqs)
1345 CODE: 1385 CODE:
1346 RETVAL = db_strerror (errorno); 1386 RETVAL = db_strerror (errorno);
1347 OUTPUT: 1387 OUTPUT:
1348 RETVAL 1388 RETVAL
1349 1389
1390void _on_next_submit (SV *cb)
1391 CODE:
1392 SvREFCNT_dec (on_next_submit);
1393 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1394
1350DB_ENV * 1395DB_ENV *
1351db_env_create (U32 env_flags = 0) 1396db_env_create (U32 env_flags = 0)
1352 CODE: 1397 CODE:
1353{ 1398{
1354 errno = db_env_create (&RETVAL, env_flags); 1399 errno = db_env_create (&RETVAL, env_flags);
1363} 1408}
1364 OUTPUT: 1409 OUTPUT:
1365 RETVAL 1410 RETVAL
1366 1411
1367void 1412void
1368db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) 1413db_env_open (DB_ENV *env, bdb_filename db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef)
1369 CODE: 1414 CODE:
1370{ 1415{
1371 dREQ (REQ_ENV_OPEN); 1416 dREQ (REQ_ENV_OPEN);
1372 1417
1373 req->env = env; 1418 req->env = env;
1444} 1489}
1445 OUTPUT: 1490 OUTPUT:
1446 RETVAL 1491 RETVAL
1447 1492
1448void 1493void
1449db_open (DB *db, DB_TXN_ornull *txnid, octetstring file, octetstring database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef) 1494db_open (DB *db, DB_TXN_ornull *txnid, bdb_filename file, bdb_filename database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef)
1450 CODE: 1495 CODE:
1451{ 1496{
1452 dREQ (REQ_DB_OPEN); 1497 dREQ (REQ_DB_OPEN);
1453 req->db = db; 1498 req->db = db;
1454 req->txn = txnid; 1499 req->txn = txnid;
1494 req->uint1 = flags; 1539 req->uint1 = flags;
1495 REQ_SEND; 1540 REQ_SEND;
1496} 1541}
1497 1542
1498void 1543void
1499db_upgrade (DB *db, octetstring file, U32 flags = 0, SV *callback = &PL_sv_undef) 1544db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = &PL_sv_undef)
1500 CODE: 1545 CODE:
1501{ 1546{
1502 dREQ (REQ_DB_SYNC); 1547 dREQ (REQ_DB_SYNC);
1503 req->db = db; 1548 req->db = db;
1504 req->buf1 = strdup (file); 1549 req->buf1 = strdup (file);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines