]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
const-ify it
authorAlan T. DeKok <aland@freeradius.org>
Mon, 14 Nov 2016 15:32:04 +0000 (10:32 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 14 Nov 2016 15:32:04 +0000 (10:32 -0500)
src/modules/rlm_lua/lua.c
src/modules/rlm_lua/lua.h
src/modules/rlm_lua/rlm_lua.c

index c99f755cf9b95275da0c47f6567b8cfe58d05937..a30fb443c6bd2f65cc8423ce7da6876cf4bc32c9 100644 (file)
@@ -720,7 +720,7 @@ static int _lua_state_free(lua_State **marker)
 /** Get a lua interpreter to use
  *
  */
-static lua_State *rlm_lua_get_interp(rlm_lua_t *inst) {
+static lua_State *rlm_lua_get_interp(rlm_lua_t const *inst) {
        lua_State **marker;
        lua_State *L;
 
@@ -730,7 +730,7 @@ static lua_State *rlm_lua_get_interp(rlm_lua_t *inst) {
         *      and return the instance specific interpreter.
         */
        if (!inst->threads) {
-               pthread_mutex_lock(&inst->mutex);
+               pthread_mutex_lock(inst->mutex);
                return inst->interpreter;
        }
 
@@ -762,12 +762,12 @@ static lua_State *rlm_lua_get_interp(rlm_lua_t *inst) {
 }
 
 #ifdef HAVE_PTHREAD_H
-#define rlm_lua_release_interp(_x)  if (!_x->threads) pthread_mutex_unlock(&_x->mutex)
+#define rlm_lua_release_interp(_x)  if (!_x->threads) pthread_mutex_unlock(_x->mutex)
 #else
 #define rlm_lua_release_interp(_x)
 #endif
 
-int do_lua(rlm_lua_t *inst, REQUEST *request, char const *funcname)
+int do_lua(rlm_lua_t const *inst, REQUEST *request, char const *funcname)
 {
        vp_cursor_t cursor;
        lua_State *L;
index b727d161a664848b607f6c0d92faf9c1b0924195..1108040cec9e700cfb430679583dcc8af71797d0 100644 (file)
@@ -52,7 +52,7 @@ typedef struct rlm_lua {
 
 #ifdef HAVE_PTHREAD_H
        pthread_key_t   key;                    //!< Key to access the thread local and instance specific interpreter.
-       pthread_mutex_t mutex;                  //!< Mutex used to protect interpreter, when running with a single
+       pthread_mutex_t *mutex;                 //!< Mutex used to protect interpreter, when running with a single
                                                //!< interpreter (threads = no).
 #endif
        bool            jit;                    //!< Whether the linked interpreter is Lua 5.1 or LuaJIT.
index 673bd3213d30382ef6e17c1c49aa43a3ba9f8490..633812865120380a24fdd36fbe638c01d7451e89 100644 (file)
@@ -86,9 +86,9 @@ static void _tls_interp_destroy(void *ctx)
         *      call lua_close and free the actual interpreter.
         */
        rad_assert(inst = talloc_find_parent_bytype(marker, rlm_lua_t));
-       pthread_mutex_lock(&inst->mutex);
+       pthread_mutex_lock(inst->mutex);
        talloc_free(marker);
-       pthread_mutex_unlock(&inst->mutex);
+       pthread_mutex_unlock(inst->mutex);
 }
 
 static int mod_instantiate(CONF_SECTION *conf, void *instance)
@@ -101,7 +101,8 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
        }
 
 #ifdef HAVE_PTHREAD_H
-       pthread_mutex_init(&inst->mutex, NULL); /* Used in both threaded and non-threaded modes */
+       inst->mutex = talloc(inst, pthread_mutex_t);
+       pthread_mutex_init(inst->mutex, NULL);  /* Used in both threaded and non-threaded modes */
 
        if (inst->threads) {
                int errno;
@@ -139,7 +140,7 @@ static int mod_detach(void *instance)
 }
 
 #define DO_LUA(_s)\
-static rlm_rcode_t mod_##_s(void const *instance, UNUSED void *thread, REQUEST *request) {\
+static rlm_rcode_t mod_##_s(void *instance, UNUSED void *thread, REQUEST *request) {\
        rlm_lua_t const *inst = instance;\
        if (!inst->func_##_s) {\
                return RLM_MODULE_NOOP;\