Skip to content

Commit b9f5b14

Browse files
committed
Replace taken_pmysqls perl array by linked list structure
This simplify implementation of taken_pmysqls.
1 parent 2bc6b41 commit b9f5b14

File tree

2 files changed

+25
-48
lines changed

2 files changed

+25
-48
lines changed

dbdimp.c

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,8 +2338,7 @@ static bool mariadb_db_my_login(pTHX_ SV* dbh, imp_dbh_t *imp_dbh)
23382338
char* user;
23392339
char* password;
23402340
char* mysql_socket;
2341-
I32 i;
2342-
bool found_taken_pmysql;
2341+
struct mariadb_list_entry *entry;
23432342
D_imp_xxh(dbh);
23442343
D_imp_drh_from_dbh;
23452344

@@ -2349,40 +2348,29 @@ static bool mariadb_db_my_login(pTHX_ SV* dbh, imp_dbh_t *imp_dbh)
23492348
{
23502349
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
23512350
PerlIO_printf(DBIc_LOGPIO(imp_xxh), "mariadb_db_my_login skip connect\n");
2351+
23522352
/* tell our parent we've adopted an active child */
23532353
++DBIc_ACTIVE_KIDS(DBIc_PARENT_COM(imp_dbh));
2354-
found_taken_pmysql = FALSE;
2355-
if (imp_drh->taken_pmysqls)
2354+
2355+
for (entry = imp_drh->taken_pmysqls; entry; entry = entry->next)
23562356
{
2357-
for (i = AvFILL(imp_drh->taken_pmysqls); i >= 0; --i)
2357+
if ((MYSQL *)entry->data == imp_dbh->pmysql)
23582358
{
2359-
svp = av_fetch(imp_drh->taken_pmysqls, i, FALSE);
2360-
if (!svp || !*svp)
2361-
continue;
2362-
SvGETMAGIC(*svp);
2363-
if (!SvIOK(*svp))
2364-
continue;
2365-
if (imp_dbh->pmysql == INT2PTR(MYSQL *, SvIVX(*svp)))
2366-
{
2367-
found_taken_pmysql = TRUE;
2368-
av_delete(imp_drh->taken_pmysqls, i, G_DISCARD);
2369-
break;
2370-
}
2359+
/* Remove MYSQL* entry from taken list */
2360+
mariadb_list_remove(imp_drh->taken_pmysqls, entry);
2361+
2362+
/* Add imp_dbh entry into active_imp_dbhs list */
2363+
mariadb_list_add(imp_drh->active_imp_dbhs, imp_dbh->list_entry, imp_dbh);
2364+
2365+
return TRUE;
23712366
}
23722367
}
2373-
if (!found_taken_pmysql)
2374-
{
2375-
/* This imp_dbh data belongs to different connection, so destructor should not touch it */
2376-
imp_dbh->list_entry = NULL;
2377-
imp_dbh->pmysql = NULL;
2378-
mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: dbi_imp_data is not valid", "HY000");
2379-
return FALSE;
2380-
}
2381-
2382-
/* Add imp_dbh entry into active_imp_dbhs list */
2383-
mariadb_list_add(imp_drh->active_imp_dbhs, imp_dbh->list_entry, imp_dbh);
23842368

2385-
return TRUE;
2369+
/* This imp_dbh data belongs to different connection, so destructor should not touch it */
2370+
imp_dbh->list_entry = NULL;
2371+
imp_dbh->pmysql = NULL;
2372+
mariadb_dr_do_error(dbh, CR_CONNECTION_ERROR, "Connection error: dbi_imp_data is not valid", "HY000");
2373+
return FALSE;
23862374
}
23872375
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
23882376
PerlIO_printf(DBIc_LOGPIO(imp_xxh),
@@ -2453,12 +2441,12 @@ SV *mariadb_db_take_imp_data(SV *dbh, imp_xxh_t *imp_xxh, void *foo)
24532441
dTHX;
24542442
D_imp_dbh(dbh);
24552443
D_imp_drh_from_dbh;
2444+
struct mariadb_list_entry *entry;
24562445
PERL_UNUSED_ARG(imp_xxh);
24572446
PERL_UNUSED_ARG(foo);
24582447

2459-
if (!imp_drh->taken_pmysqls)
2460-
imp_drh->taken_pmysqls = newAV();
2461-
av_push(imp_drh->taken_pmysqls, newSViv(PTR2IV(imp_dbh->pmysql)));
2448+
/* Add MYSQL* into taken list */
2449+
mariadb_list_add(imp_drh->taken_pmysqls, entry, imp_dbh->pmysql);
24622450

24632451
/* MYSQL* was taken from imp_dbh so remove it also from active_imp_dbhs list */
24642452
mariadb_list_remove(imp_drh->active_imp_dbhs, imp_dbh->list_entry);
@@ -3096,24 +3084,13 @@ int mariadb_db_disconnect(SV* dbh, imp_dbh_t* imp_dbh)
30963084
int mariadb_dr_discon_all (SV *drh, imp_drh_t *imp_drh) {
30973085
dTHX;
30983086
int ret;
3099-
SV **svp;
3100-
I32 i;
3087+
struct mariadb_list_entry *entry;
31013088
PERL_UNUSED_ARG(drh);
31023089

3103-
if (imp_drh->taken_pmysqls)
3090+
while ((entry = imp_drh->taken_pmysqls))
31043091
{
3105-
for (i = AvFILL(imp_drh->taken_pmysqls); i >= 0; --i)
3106-
{
3107-
svp = av_fetch(imp_drh->taken_pmysqls, i, FALSE);
3108-
if (!svp || !*svp)
3109-
continue;
3110-
SvGETMAGIC(*svp);
3111-
if (!SvIOK(*svp))
3112-
continue;
3113-
mariadb_dr_close_mysql(aTHX_ imp_drh, INT2PTR(MYSQL *, SvIVX(*svp)));
3114-
}
3115-
av_undef(imp_drh->taken_pmysqls);
3116-
imp_drh->taken_pmysqls = NULL;
3092+
mariadb_dr_close_mysql(aTHX_ imp_drh, (MYSQL *)entry->data);
3093+
mariadb_list_remove(imp_drh->taken_pmysqls, entry);
31173094
}
31183095

31193096
while (imp_drh->active_imp_dbhs)

dbdimp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ struct imp_drh_st {
460460
dbih_drc_t com; /* MUST be first element in structure */
461461

462462
struct mariadb_list_entry *active_imp_dbhs; /* List of imp_dbh structures with active MYSQL* */
463+
struct mariadb_list_entry *taken_pmysqls; /* List of active MYSQL* from take_imp_data() */
463464
unsigned long int instances;
464465
bool non_embedded_started;
465466
#if !defined(HAVE_EMBEDDED) && defined(HAVE_BROKEN_INIT)
@@ -468,7 +469,6 @@ struct imp_drh_st {
468469
bool embedded_started;
469470
SV *embedded_args;
470471
SV *embedded_groups;
471-
AV *taken_pmysqls; /* List of active MYSQL* structures from take_imp_data() */
472472
};
473473

474474

0 commit comments

Comments
 (0)