mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 16:45:20 +02:00
Fix Lua scripting synchronization
For several years now, the lua script lock has been completely broken. This commit fixes the main issue (creation of a temporary rather than scoped object), and fixes a subsequent deadlock issue caused by nested script API calls by adding support for recursive mutexes.
This commit is contained in:
@@ -34,15 +34,25 @@ DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#define UNUSED(expr) do { (void)(expr); } while (0)
|
||||
|
||||
|
||||
Mutex::Mutex()
|
||||
Mutex::Mutex(bool recursive)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// Windows critical sections are recursive by default
|
||||
UNUSED(recursive);
|
||||
|
||||
InitializeCriticalSection(&mutex);
|
||||
#else
|
||||
int ret = pthread_mutex_init(&mutex, NULL);
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
|
||||
if (recursive)
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
|
||||
int ret = pthread_mutex_init(&mutex, &attr);
|
||||
assert(!ret);
|
||||
UNUSED(ret);
|
||||
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -49,7 +49,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
class Mutex
|
||||
{
|
||||
public:
|
||||
Mutex();
|
||||
Mutex(bool recursive=false);
|
||||
~Mutex();
|
||||
void lock();
|
||||
void unlock();
|
||||
|
Reference in New Issue
Block a user