MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / db_create_thread_int

Function db_create_thread_int

lua/sp.c:3203–3270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3201}
3202
3203static int db_create_thread_int(Lua lua, const char *funcname)
3204{
3205 SP sp = getsp(lua);
3206 SP newsp = NULL;
3207 char *err = NULL;
3208 dbthread_type *dbthd = NULL;
3209 struct sqlclntstate *clnt = NULL;
3210 if ((newsp = create_sp(&err)) == NULL) {
3211 goto err;
3212 }
3213 Lua newlua = newsp->lua;
3214 remove_thd_funcs(newlua);
3215 add_tran_funcs(newlua);
3216 lua_sethook(newlua, InstructionCountHook, 0, 1); /*This means no hook.*/
3217 dbthd = calloc(sizeof(dbthread_type), 1);
3218 struct sqlclntstate *parent_clnt = sp->clnt;
3219 clnt = &dbthd->clnt;
3220 reset_clnt(clnt, 1);
3221 clnt->origin = parent_clnt->origin;
3222 clnt->want_stored_procedure_trace = parent_clnt->want_stored_procedure_trace;
3223 clnt->dbtran.mode = parent_clnt->dbtran.mode;
3224 clnt->appdata = parent_clnt->appdata;
3225 clnt->plugin = parent_clnt->plugin;
3226 clnt->sp = newsp;
3227 clnt->sql = parent_clnt->sql;
3228 clnt->exec_lua_thread = 1;
3229 clnt->dbtran.trans_has_sp = 1;
3230 clnt->queue_me = 1;
3231 setup_clnt_for_sp(clnt);
3232 clnt->done_cb = thread_dispatch_failed;
3233 strcpy(clnt->tzname, parent_clnt->tzname);
3234 Pthread_mutex_init(&dbthd->lua_thread_mutex, NULL);
3235 Pthread_cond_init(&dbthd->lua_thread_cond, NULL);
3236 strncpy0(newsp->spname, sp->spname, sizeof(newsp->spname));
3237 newsp->clnt = clnt;
3238 newsp->dbthd = dbthd;
3239 newsp->parent = sp->parent;
3240 newsp->spversion = sp->spversion;
3241 if (newsp->spversion.version_str) {
3242 newsp->spversion.version_str = strdup(newsp->spversion.version_str);
3243 }
3244 if (process_src(newlua, sp->src, &err) != 0) {
3245 goto err;
3246 }
3247 if (get_func_by_name(newlua, funcname, &err) != 0) {
3248 goto err;
3249 }
3250 if (sp->wait_cond == NULL) {
3251 sp->wait_cond = malloc(sizeof(pthread_cond_t));
3252 sp->wait_lock = malloc(sizeof(pthread_mutex_t));
3253 Pthread_cond_init(sp->wait_cond, NULL);
3254 Pthread_mutex_init(sp->wait_lock, NULL);
3255 }
3256 copy_state_stacks(lua, newlua, 1);
3257 dbthd->status = THREAD_STATUS_DISPATCH_WAITING;
3258 if (dispatch_sql_query_no_wait(clnt) == 0) { // --> exec_thread()
3259 LIST_INSERT_HEAD(&sp->dbthds, dbthd, entries);
3260 dbthread_t *lt;

Callers 1

db_create_threadFunction · 0.85

Calls 15

create_spFunction · 0.85
remove_thd_funcsFunction · 0.85
add_tran_funcsFunction · 0.85
lua_sethookFunction · 0.85
callocFunction · 0.85
reset_clntFunction · 0.85
setup_clnt_for_spFunction · 0.85
process_srcFunction · 0.85
get_func_by_nameFunction · 0.85
mallocFunction · 0.85
copy_state_stacksFunction · 0.85

Tested by

no test coverage detected