| 1346 | (clnt->plugin.state && clnt->plugin.write_response == dohsql_write_response) |
| 1347 | |
| 1348 | void dohsql_wait_for_master(sqlite3_stmt *stmt, struct sqlclntstate *clnt) |
| 1349 | { |
| 1350 | int rc; |
| 1351 | dohsql_connector_t *conn; |
| 1352 | |
| 1353 | if (!stmt || !DOHSQL_CLIENT) |
| 1354 | return; |
| 1355 | |
| 1356 | if (gbl_dohsql_verbose) |
| 1357 | logmsg(LOGMSG_USER, "%p %s waiting for master\n", |
| 1358 | (void *)pthread_self(), __func__); |
| 1359 | |
| 1360 | conn = clnt->plugin.state; |
| 1361 | |
| 1362 | Pthread_mutex_lock(&conn->mtx); |
| 1363 | |
| 1364 | /* wait if run ended ok, master is not done, and there are cached rows */ |
| 1365 | if (!clnt->query_rc) { |
| 1366 | while (conn->status == DOH_RUNNING && |
| 1367 | (conn->selected || (queue_count(conn->que) > 0))) { |
| 1368 | Pthread_mutex_unlock(&conn->mtx); |
| 1369 | poll(NULL, 0, 10); |
| 1370 | if (bdb_lock_desired(thedb->bdb_env)) { |
| 1371 | rc = recover_deadlock_simple(thedb->bdb_env); |
| 1372 | if (rc) { |
| 1373 | logmsg(LOGMSG_ERROR, |
| 1374 | "%s failed recover_deadlock " |
| 1375 | "rc=%d\n", |
| 1376 | __func__, rc); |
| 1377 | return; |
| 1378 | } |
| 1379 | } |
| 1380 | Pthread_mutex_lock(&conn->mtx); |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | if (gbl_dohsql_verbose) |
| 1385 | logmsg(LOGMSG_USER, |
| 1386 | "%p %s done waiting que %p count %d que_free %p count %d\n", |
| 1387 | (void *)pthread_self(), __func__, conn->que, |
| 1388 | queue_count(conn->que), conn->que_free, |
| 1389 | queue_count(conn->que_free)); |
| 1390 | |
| 1391 | _track_que_free(conn); |
| 1392 | trimQue(conn, stmt, conn->que, 0); |
| 1393 | trimQue(conn, stmt, conn->que_free, 0); |
| 1394 | |
| 1395 | /* |
| 1396 | This has to be done after the sql thread has done touching clnt |
| 1397 | structure conn->status = DOH_CLIENT_DONE; |
| 1398 | */ |
| 1399 | |
| 1400 | Pthread_mutex_unlock(&conn->mtx); |
| 1401 | } |
| 1402 | |
| 1403 | const char *dohsql_get_sql(struct sqlclntstate *clnt, int index) |
| 1404 | { |
no test coverage detected