typedef struct {
lua_State *lua_state;
char *lua_function_name;
- pthread_mutex_t lock;
int callback_id;
} clua_callback_data_t;
static char base_path[PATH_MAX];
static lua_script_t *scripts;
+static pthread_mutex_t lua_lock = PTHREAD_MUTEX_INITIALIZER;
static int clua_store_callback(lua_State *L, int idx) /* {{{ */
{
{
clua_callback_data_t *cb = ud->data;
- pthread_mutex_lock(&cb->lock);
+ pthread_mutex_lock(&lua_lock);
lua_State *L = cb->lua_state;
if (status != 0) {
ERROR("Lua plugin: Unable to load callback \"%s\" (id %i).",
cb->lua_function_name, cb->callback_id);
- pthread_mutex_unlock(&cb->lock);
+ pthread_mutex_unlock(&lua_lock);
return -1;
}
/* +1 = 1 */
else
ERROR("Lua plugin: Calling a read callback failed: %s", errmsg);
lua_pop(L, 1);
- pthread_mutex_unlock(&cb->lock);
+ pthread_mutex_unlock(&lua_lock);
return -1;
}
/* pop return value and function */
lua_pop(L, 1); /* -1 = 0 */
- pthread_mutex_unlock(&cb->lock);
+ pthread_mutex_unlock(&lua_lock);
return status;
} /* }}} int clua_read */
user_data_t *ud) {
clua_callback_data_t *cb = ud->data;
- pthread_mutex_lock(&cb->lock);
+ pthread_mutex_lock(&lua_lock);
lua_State *L = cb->lua_state;
if (status != 0) {
ERROR("Lua plugin: Unable to load callback \"%s\" (id %i).",
cb->lua_function_name, cb->callback_id);
- pthread_mutex_unlock(&cb->lock);
+ pthread_mutex_unlock(&lua_lock);
return -1;
}
/* +1 = 1 */
status = luaC_pushvaluelist(L, ds, vl);
if (status != 0) {
lua_pop(L, 1); /* -1 = 0 */
- pthread_mutex_unlock(&cb->lock);
+ pthread_mutex_unlock(&lua_lock);
ERROR("Lua plugin: luaC_pushvaluelist failed.");
return -1;
}
else
ERROR("Lua plugin: Calling the write callback failed:\n%s", errmsg);
lua_pop(L, 1); /* -1 = 0 */
- pthread_mutex_unlock(&cb->lock);
+ pthread_mutex_unlock(&lua_lock);
return -1;
}
}
lua_pop(L, 1); /* -1 = 0 */
- pthread_mutex_unlock(&cb->lock);
+ pthread_mutex_unlock(&lua_lock);
return status;
} /* }}} int clua_write */
static void lua_cb_free(void *data) {
clua_callback_data_t *cb = data;
free(cb->lua_function_name);
- pthread_mutex_destroy(&cb->lock);
free(cb);
}
cb->lua_state = thread;
cb->callback_id = callback_id;
cb->lua_function_name = strdup(function_name);
- pthread_mutex_init(&cb->lock, NULL);
if (PLUGIN_READ == type) {
int status = plugin_register_complex_read(/* group = */ "lua",