0
1
mirror of https://github.com/radio95-rnt/rds95.git synced 2026-02-26 20:33:53 +01:00
This commit is contained in:
2025-12-25 22:22:22 +01:00
parent f830ff3e74
commit 7599c35f2f

View File

@@ -57,8 +57,8 @@ int lua_set_rds_program_defaults(lua_State *localL) {
for (int i = 1; i < *unload_refs; i++) luaL_unref(L, LUA_REGISTRYINDEX, unload_refs[i]); for (int i = 1; i < *unload_refs; i++) luaL_unref(L, LUA_REGISTRYINDEX, unload_refs[i]);
unload_refs[0] = 1; unload_refs[0] = 1;
set_rds_defaults(mod->enc, mod->enc->program); set_rds_defaults(mod->enc, mod->enc->program);
lua_call_function("on_init"); lua_call_function_nolock("on_init");
lua_call_function("on_state"); lua_call_function_nolock("on_state");
in_set_defaults = 0; in_set_defaults = 0;
return 0; return 0;
} }
@@ -73,7 +73,7 @@ int lua_reset_rds(lua_State *localL) {
encoder_loadFromFile(mod->enc); encoder_loadFromFile(mod->enc);
for(int i = 0; i < PROGRAMS; i++) reset_rds_state(mod->enc, i); for(int i = 0; i < PROGRAMS; i++) reset_rds_state(mod->enc, i);
Modulator_loadFromFile(&mod->params); Modulator_loadFromFile(&mod->params);
lua_call_function("on_state"); lua_call_function_nolock("on_state");
return 0; return 0;
} }
@@ -724,12 +724,7 @@ void lua_group_ref(RDSGroup* group, int ref) {
pthread_mutex_unlock(&lua_mutex); pthread_mutex_unlock(&lua_mutex);
} }
void lua_call_function(const char* function) { void lua_call_function_nolock(const char* function) {
int need_lock = (pthread_mutex_trylock(&lua_mutex) == 0);
if (!need_lock) {
fprintf(stderr, "Warning: lua_mutex already locked when calling %s\n", function);
return;
}
lua_getglobal(L, function); lua_getglobal(L, function);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
@@ -738,6 +733,14 @@ void lua_call_function(const char* function) {
lua_pop(L, 1); lua_pop(L, 1);
} }
} else lua_pop(L, 1); } else lua_pop(L, 1);
}
void lua_call_function(const char* function) {
int need_lock = (pthread_mutex_trylock(&lua_mutex) == 0);
if (!need_lock) {
fprintf(stderr, "Warning: lua_mutex already locked when calling %s\n", function);
return;
}
lua_call_function_nolock(function);
pthread_mutex_unlock(&lua_mutex); pthread_mutex_unlock(&lua_mutex);
} }