… | |
… | |
597 | |
597 | |
598 | =back |
598 | =back |
599 | |
599 | |
600 | Pick your poison. |
600 | Pick your poison. |
601 | |
601 | |
602 | =head2 Case Study: C<DBD::SQLite> |
|
|
603 | |
|
|
604 | Last not least, while the abovew case studies show some difficult |
|
|
605 | examples, let's look at a more typical easy case, L<DBD::SQLite>. |
|
|
606 | |
|
|
607 | Practically all work is done by calling C<_sqlite_exec> in F<dbdimp.c>, so |
|
|
608 | other than copying F<perlmulticore.h> into the source tree and adding |
|
|
609 | |
|
|
610 | #include "perlmulticore.h" |
|
|
611 | |
|
|
612 | to that file, you only need to change the call to C<sqlite3_exec> in |
|
|
613 | that function by sandwiching it between C<perlinterp_release> and |
|
|
614 | C<perlinterp_acquire>: |
|
|
615 | |
|
|
616 | int |
|
|
617 | _sqlite_exec(pTHX_ SV *h, sqlite3 *db, const char *sql) |
|
|
618 | { |
|
|
619 | int rc; |
|
|
620 | char *errmsg; |
|
|
621 | |
|
|
622 | perlinterp_release (); // added |
|
|
623 | rc = sqlite3_exec(db, sql, NULL, NULL, &errmsg); |
|
|
624 | perlinterp_acquire (); // added |
|
|
625 | ... |
|
|
626 | |
|
|
627 | To also catch the database opening phase, the same needs to be done for |
|
|
628 | C<_sqlite_open>: |
|
|
629 | |
|
|
630 | _sqlite_open(pTHX_ SV *dbh, const char *dbname, sqlite3 **db, int flags, int extended) |
|
|
631 | { |
|
|
632 | int rc; |
|
|
633 | perlinterp_release (); // added |
|
|
634 | if (flags) { |
|
|
635 | rc = sqlite3_open_v2(dbname, db, flags, NULL); |
|
|
636 | } else { |
|
|
637 | rc = sqlite3_open(dbname, db); |
|
|
638 | } |
|
|
639 | perlinterp_acquire (); // added |
|
|
640 | if ( rc != SQLITE_OK ) { |
|
|
641 | |
|
|
642 | And that is it. |
|
|
643 | |
602 | |
644 | =head1 SEE ALSO |
603 | =head1 SEE ALSO |
645 | |
604 | |
646 | This document's canonical web address: L<http://perlmulticore.schmorp.de/> |
605 | This document's canonical web address: L<http://perlmulticore.schmorp.de/> |
647 | |
606 | |