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

Comparing BDB/BDB.xs (file contents):
Revision 1.33 by root, Sun Mar 30 04:57:55 2008 UTC vs.
Revision 1.37 by root, Sat May 10 20:23:06 2008 UTC

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;
1348 CODE: 1392 CODE:
1349 RETVAL = db_strerror (errorno); 1393 RETVAL = db_strerror (errorno);
1350 OUTPUT: 1394 OUTPUT:
1351 RETVAL 1395 RETVAL
1352 1396
1397void _on_next_submit (SV *cb)
1398 CODE:
1399 SvREFCNT_dec (on_next_submit);
1400 on_next_submit = SvOK (cb) ? newSVsv (cb) : 0;
1401
1353DB_ENV * 1402DB_ENV *
1354db_env_create (U32 env_flags = 0) 1403db_env_create (U32 env_flags = 0)
1355 CODE: 1404 CODE:
1356{ 1405{
1357 errno = db_env_create (&RETVAL, env_flags); 1406 errno = db_env_create (&RETVAL, env_flags);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines