diff options
| author | ruki <[email protected]> | 2019-07-26 22:15:46 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-07-26 07:34:36 +0800 |
| commit | dd488ffd6dc1ec44b3d0c38a9dfd5f0ca99d6d2f (patch) | |
| tree | a4e730279fc121d409c5508a0e0828bd10a39114 | |
| parent | 59472a642f18bf17953deddd82c68678d40fa254 (diff) | |
improve file lock count
| -rw-r--r-- | core/src/xmake/io/filelock.h | 4 | ||||
| -rw-r--r-- | core/src/xmake/io/filelock_close___gc.c | 2 | ||||
| -rw-r--r-- | core/src/xmake/io/filelock_islocked.c | 2 | ||||
| -rw-r--r-- | core/src/xmake/io/filelock_lock.c | 4 | ||||
| -rw-r--r-- | core/src/xmake/io/filelock_trylock.c | 3 | ||||
| -rw-r--r-- | core/src/xmake/io/filelock_unlock.c | 6 | ||||
| -rw-r--r-- | core/src/xmake/io/openlock.c | 2 | ||||
| -rw-r--r-- | makefile | 1 |
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); @@ -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: |
