Lua & lock manager

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Lua & lock manager

Thierry Fournier-2
Hi,

My problem is : In most case, open sources projects uses the OS default Lua
library. This is useful because the task of OS maintainer is providing
libraries updates (fixing bug or security fail), and this is not the
task of the open source project maintainer.

Actually, the “lock interface” is defined using defines at compilation.
I guess this is for performances reason: it is useless to call function
or set a lock if multithread is not enabled. So, with this built-time
solution, the distribs cannot propose a package multithread-ready.

I propose myself to write a patch about multithread and lock, but first
I need your opinion. What do you think about integration of build-optional
"lock manager" for multithread usage of Lua ?

This seems match with requirements:

- No thread and performance requirement, build Lua without lock manager

- Thread and very specific integration, use your own lock with the actual
  macro

- Distribs packaging build with the manager, and each software using the
  distrib lib can use the lock manager or no. The overhead is just a call
  to empty function

The patch could be something like that (this is a very quick idea which
is not perfect):


Make with option:
 
  make MYCFLAGS=-DUSE_REENTRANT_INTERFACE

and in the llimits.h file:

   #if !defined(lua_lock)
   #ifdef USE_REENTRANT_INTERFACE
   #define lua_lock(__L) lua_internal_lock(__L)
   #define lua_lock(__L) lua_internal_unlock(__L)
   #else
   #define lua_lock(L)  ((void) 0)
   #define lua_unlock(L)   ((void) 0)
   #endif
   #endif

In lua.h

   #ifdef USE_REENTRANT_INTERFACE
   void lua_register_lock_manager(void (*lua_lock)(lua_State *L),
                                  void (*lua_unlock)(lua_State *L));
   #endif

In lapi.c (or other file):

   #ifdef USE_REENTRANT_INTERFACE
   static void (*lua_internal_lock_function)(lua_State *L) = NULL;
   static void (*lua_internal_unlock_function)(lua_State *L) = NULL;

   void lua_register_lock_manager(void (*lua_lock_fcn)(lua_State *L),

   void (*lua_unlock_fcn)(lua_State *L))
   {
      lua_internal_lock_function = lua_lock_fcn;
      lua_internal_unlock_function = lua_unlock_fcn;
   }

   void lua_internal_lock(lua_State *L)
   {
      if (lua_internal_lock_function)
         lua_internal_lock_function(L)
   }

   void lua_internal_unlock(lua_State *L)
   {
      if (lua_internal_unlock_function)
         lua_internal_unlock_function(L)
   }
   #endif

Thierry