Make the lock recursive, this is because processEventsWhileBlocked may cause us to lock multiple times
This commit is contained in:
parent
48f6d0d800
commit
f5caec488d
@ -1,25 +1,41 @@
|
|||||||
#include "fastlock.h"
|
#include "fastlock.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
thread_local int tls_pid = -1;
|
||||||
|
|
||||||
extern "C" void fastlock_init(struct fastlock *lock)
|
extern "C" void fastlock_init(struct fastlock *lock)
|
||||||
{
|
{
|
||||||
lock->m_lock = 0;
|
lock->m_lock = 0;
|
||||||
|
lock->m_depth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void fastlock_lock(struct fastlock *lock)
|
extern "C" void fastlock_lock(struct fastlock *lock)
|
||||||
{
|
{
|
||||||
while (!__sync_bool_compare_and_swap(&lock->m_lock, 0, 1))
|
while (!__sync_bool_compare_and_swap(&lock->m_lock, 0, 1))
|
||||||
{
|
{
|
||||||
|
if (lock->m_pidOwner == getpid())
|
||||||
|
{
|
||||||
|
++lock->m_depth;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
lock->m_depth = 1;
|
||||||
|
lock->m_pidOwner = getpid();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void fastlock_unlock(struct fastlock *lock)
|
extern "C" void fastlock_unlock(struct fastlock *lock)
|
||||||
{
|
{
|
||||||
__sync_bool_compare_and_swap(&lock->m_lock, 1, 0);
|
--lock->m_depth;
|
||||||
|
if (lock->m_depth == 0)
|
||||||
|
{
|
||||||
|
lock->m_pidOwner = -1;
|
||||||
|
asm volatile ("": : :"memory");
|
||||||
|
__sync_bool_compare_and_swap(&lock->m_lock, 1, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void fastlock_free(struct fastlock *lock)
|
extern "C" void fastlock_free(struct fastlock *lock)
|
||||||
{
|
{
|
||||||
// NOP
|
// NOP
|
||||||
(void)lock;
|
(void)lock;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,9 @@ void fastlock_free(struct fastlock *lock);
|
|||||||
|
|
||||||
struct fastlock
|
struct fastlock
|
||||||
{
|
{
|
||||||
int m_lock;
|
volatile int m_lock;
|
||||||
|
int m_pidOwner;
|
||||||
|
int m_depth;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
fastlock()
|
fastlock()
|
||||||
|
2436
src/networking.cpp
Normal file
2436
src/networking.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user