| 5723 | } |
| 5724 | |
| 5725 | static int l_send_back_row(Lua lua, sqlite3_stmt *stmt, int nargs) |
| 5726 | { |
| 5727 | int rc = 0; |
| 5728 | SP sp = getsp(lua); |
| 5729 | luaL_argcheck(lua, nargs > 0, 1, "no row to send back"); |
| 5730 | if (nargs > MAXCOLUMNS) { |
| 5731 | return luabb_error(lua, sp, "attempt to read %d cols (maxcols:%d)", |
| 5732 | nargs, MAXCOLUMNS); |
| 5733 | } |
| 5734 | rc = release_locks_on_emit_row(sp->clnt); |
| 5735 | if (rc) { |
| 5736 | logmsg(LOGMSG_ERROR, "%s release_locks_on_emit_row %d\n", __func__, rc); |
| 5737 | return rc; |
| 5738 | } |
| 5739 | struct response_data arg = {0}; |
| 5740 | arg.ncols = nargs; |
| 5741 | arg.stmt = stmt; |
| 5742 | arg.sp = sp; |
| 5743 | arg.pingpong = sp->pingpong; |
| 5744 | SP parent = sp->parent; |
| 5745 | struct sqlclntstate *clnt = parent->clnt; |
| 5746 | if (clnt->osql.sent_column_data == 0) { |
| 5747 | Pthread_mutex_lock(parent->emit_mutex); |
| 5748 | if (clnt->osql.sent_column_data == 0) { |
| 5749 | new_col_info(parent, nargs); |
| 5750 | rc = write_response(clnt, RESPONSE_COLUMNS_LUA, &arg, 0); |
| 5751 | clnt->osql.sent_column_data = 1; |
| 5752 | } |
| 5753 | Pthread_mutex_unlock(parent->emit_mutex); |
| 5754 | if (rc) return rc; |
| 5755 | } |
| 5756 | int type = stmt ? RESPONSE_ROW : RESPONSE_ROW_LUA; |
| 5757 | int sp_rc = sp->rc; |
| 5758 | sp->rc = 0; |
| 5759 | |
| 5760 | if (!gbl_libevent_appsock) { |
| 5761 | Pthread_mutex_lock(parent->emit_mutex); /* old way */ |
| 5762 | } else |
| 5763 | /* If SP has threads, one of them may hold emit_mutex waiting for a slow |
| 5764 | * client to read (in sql_flush_int). We trylock instead and come up for |
| 5765 | * air to check if bdb_lock_desired */ |
| 5766 | while ((rc = pthread_mutex_trylock(parent->emit_mutex)) == EBUSY) { |
| 5767 | if (bdb_lock_desired(thedb->bdb_env)) { |
| 5768 | rc = release_locks("release locks on emit-row for lock-desired"); |
| 5769 | if (rc) { |
| 5770 | logmsg(LOGMSG_ERROR, "%s release_locks_on_emit_row %d\n", __func__, rc); |
| 5771 | return rc; |
| 5772 | } |
| 5773 | } |
| 5774 | Pthread_mutex_lock(parent->wait_lock); |
| 5775 | struct timespec delay; |
| 5776 | clock_gettime(CLOCK_REALTIME, &delay); |
| 5777 | delay.tv_sec += 1; |
| 5778 | pthread_cond_timedwait(parent->wait_cond, parent->wait_lock, &delay); |
| 5779 | Pthread_mutex_unlock(parent->wait_lock); |
| 5780 | } |
| 5781 | if (rc != 0) { |
| 5782 | abort(); /* as if Pthread_mutex_lock failed */ |
no test coverage detected