summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/xmake/io/filelock.h4
-rw-r--r--core/src/xmake/io/filelock_close___gc.c2
-rw-r--r--core/src/xmake/io/filelock_islocked.c2
-rw-r--r--core/src/xmake/io/filelock_lock.c4
-rw-r--r--core/src/xmake/io/filelock_trylock.c3
-rw-r--r--core/src/xmake/io/filelock_unlock.c6
-rw-r--r--core/src/xmake/io/openlock.c2
-rw-r--r--makefile1
8 files changed, 13 insertions, 11 deletions
diff --git a/core/src/xmake/io/filelock.h b/core/src/xmake/io/filelock.h
index 6221b2cae..460467d57 100644
--- a/core/src/xmake/io/filelock.h
+++ b/core/src/xmake/io/filelock.h
@@ -67,8 +67,8 @@ typedef struct __xm_io_filelock_t
// is opened?
tb_bool_t is_opened;
- // is locked?
- tb_bool_t is_locked;
+ // the locked count
+ tb_long_t nlocked;
// the lock name
tb_char_t name[64];
diff --git a/core/src/xmake/io/filelock_close___gc.c b/core/src/xmake/io/filelock_close___gc.c
index 792d60a7b..c362994ba 100644
--- a/core/src/xmake/io/filelock_close___gc.c
+++ b/core/src/xmake/io/filelock_close___gc.c
@@ -58,7 +58,7 @@ static tb_int_t xm_io_filelock_close_impl(lua_State* lua, tb_bool_t allow_closed
tb_filelock_exit(lock->lock_ref);
lock->lock_ref = tb_null;
lock->is_opened = tb_false;
- lock->is_locked = tb_false;
+ lock->nlocked = 0;
// free lock path
if (lock->path)
diff --git a/core/src/xmake/io/filelock_islocked.c b/core/src/xmake/io/filelock_islocked.c
index b2a226ef9..633d9b738 100644
--- a/core/src/xmake/io/filelock_islocked.c
+++ b/core/src/xmake/io/filelock_islocked.c
@@ -47,7 +47,7 @@ tb_int_t xm_io_filelock_islocked(lua_State* lua)
xm_io_filelock_return_error_closed(lua);
else
{
- lua_pushboolean(lua, lock->is_locked);
+ lua_pushboolean(lua, lock->nlocked > 0);
xm_io_filelock_return_success();
}
}
diff --git a/core/src/xmake/io/filelock_lock.c b/core/src/xmake/io/filelock_lock.c
index 0e9a93d47..338afe3c9 100644
--- a/core/src/xmake/io/filelock_lock.c
+++ b/core/src/xmake/io/filelock_lock.c
@@ -62,9 +62,9 @@ tb_int_t xm_io_filelock_lock(lua_State* lua)
else
{
// lock it
- if (lock->is_locked || tb_filelock_enter(lock->lock_ref, is_shared? TB_FILELOCK_MODE_SH : TB_FILELOCK_MODE_EX))
+ if (lock->nlocked > 0 || tb_filelock_enter(lock->lock_ref, is_shared? TB_FILELOCK_MODE_SH : TB_FILELOCK_MODE_EX))
{
- lock->is_locked = tb_true;
+ lock->nlocked++;
lua_pushboolean(lua, tb_true);
xm_io_filelock_return_success();
}
diff --git a/core/src/xmake/io/filelock_trylock.c b/core/src/xmake/io/filelock_trylock.c
index f13d04936..9f8a9dfd4 100644
--- a/core/src/xmake/io/filelock_trylock.c
+++ b/core/src/xmake/io/filelock_trylock.c
@@ -62,8 +62,9 @@ tb_int_t xm_io_filelock_trylock(lua_State* lua)
else
{
// try to lock it
- if (lock->is_locked || tb_filelock_enter_try(lock->lock_ref, is_shared? TB_FILELOCK_MODE_SH : TB_FILELOCK_MODE_EX))
+ if (lock->nlocked > 0 || tb_filelock_enter_try(lock->lock_ref, is_shared? TB_FILELOCK_MODE_SH : TB_FILELOCK_MODE_EX))
{
+ lock->nlocked++;
lua_pushboolean(lua, tb_true);
xm_io_filelock_return_success();
}
diff --git a/core/src/xmake/io/filelock_unlock.c b/core/src/xmake/io/filelock_unlock.c
index a6b0150d4..5cec814e9 100644
--- a/core/src/xmake/io/filelock_unlock.c
+++ b/core/src/xmake/io/filelock_unlock.c
@@ -47,9 +47,11 @@ tb_int_t xm_io_filelock_unlock(lua_State* lua)
else
{
// unlock it
- if (tb_filelock_leave(lock->lock_ref))
+ if (lock->nlocked > 1 || tb_filelock_leave(lock->lock_ref))
{
- lock->is_locked = tb_false;
+ if (lock->nlocked > 0)
+ lock->nlocked--;
+ else lock->nlocked = 0;
lua_pushboolean(lua, tb_true);
xm_io_filelock_return_success();
}
diff --git a/core/src/xmake/io/openlock.c b/core/src/xmake/io/openlock.c
index 12bb242e3..c3653cbfc 100644
--- a/core/src/xmake/io/openlock.c
+++ b/core/src/xmake/io/openlock.c
@@ -54,7 +54,7 @@ tb_int_t xm_io_openlock(lua_State* lua)
xm_io_filelock_t* xmlock = xm_io_new_filelock(lua);
xmlock->lock_ref = lock;
xmlock->is_opened = tb_true;
- xmlock->is_locked = tb_false;
+ xmlock->nlocked = 0;
// save lock path
tb_size_t pathlen = tb_strlen(path);
diff --git a/makefile b/makefile
index 3646cc656..6c4bcf82a 100644
--- a/makefile
+++ b/makefile
@@ -62,7 +62,6 @@ build:
@echo compiling xmake-core ...
@if [ -f core/.config.mak ]; then rm core/.config.mak; fi
@$(MAKE) -C core --no-print-directory f DEBUG=$(debug)
- @$(MAKE) -C core --no-print-directory c
@$(MAKE) -C core --no-print-directory
install: