mirror of
https://gitee.com/openharmony/commonlibrary_ets_utils
synced 2024-11-27 09:30:48 +00:00
cherry pick 1197b46
from https://gitee.com/diartyz/commonlibrary_ets_utils/pulls/1457
Fix gettid() in AsyncLock Issue: https://gitee.com/openharmony/commonlibrary_ets_utils/issues/IASPI5?from=project-issue Signed-off-by: liu-zelin <liuzelin8@huawei.com> Change-Id: I3eae6ae15b9ecc550860d9fd9ddd5f72d803c2d8
This commit is contained in:
parent
0fc71cdb19
commit
d4562b6c43
@ -42,7 +42,7 @@ napi_value AsyncLock::LockAsync(napi_env env, napi_ref cb, LockMode mode, const
|
||||
napi_deferred deferred;
|
||||
napi_create_promise(env, &deferred, &promise);
|
||||
LockRequest *lockRequest =
|
||||
new LockRequest(this, AsyncLockManager::GetCurrentTid(), env, cb, mode, options, deferred);
|
||||
new LockRequest(this, AsyncLockManager::GetCurrentTid(env), env, cb, mode, options, deferred);
|
||||
std::unique_lock<std::mutex> lock(asyncLockMutex_);
|
||||
if (!CanAcquireLock(lockRequest) && options.isAvailable) {
|
||||
napi_value err;
|
||||
@ -98,9 +98,9 @@ void AsyncLock::ProcessPendingLockRequest(napi_env env)
|
||||
if (!CanAcquireLock(lockRequest)) {
|
||||
return;
|
||||
}
|
||||
if (lockRequest->GetTid() == AsyncLockManager::GetCurrentTid() && lockRequest->GetMode() == LOCK_MODE_SHARED) {
|
||||
if (lockRequest->GetTid() == AsyncLockManager::GetCurrentTid(env) && lockRequest->GetMode() == LOCK_MODE_SHARED) {
|
||||
lockStatus_ = LOCK_MODE_SHARED;
|
||||
while (lockRequest->GetTid() == AsyncLockManager::GetCurrentTid() &&
|
||||
while (lockRequest->GetTid() == AsyncLockManager::GetCurrentTid(env) &&
|
||||
lockRequest->GetMode() == LOCK_MODE_SHARED) {
|
||||
lockRequest->OnSatisfied();
|
||||
heldList_.push_back(lockRequest);
|
||||
|
@ -459,8 +459,9 @@ bool AsyncLockManager::GetLockOptions(napi_env env, napi_value val, LockOptions
|
||||
return true;
|
||||
}
|
||||
|
||||
tid_t AsyncLockManager::GetCurrentTid()
|
||||
tid_t AsyncLockManager::GetCurrentTid(napi_env env)
|
||||
{
|
||||
return static_cast<tid_t>(gettid());
|
||||
NativeEngine *engine = reinterpret_cast<NativeEngine *>(env);
|
||||
return engine->GetCurSysTid();
|
||||
}
|
||||
} // namespace Commonlibrary::Concurrent::LocksModule
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
static napi_value Query(napi_env env, napi_callback_info cbinfo);
|
||||
static napi_value QueryAll(napi_env env, napi_callback_info cbinfo);
|
||||
|
||||
static tid_t GetCurrentTid();
|
||||
static tid_t GetCurrentTid(napi_env env);
|
||||
static void DumpLocksInfoForThread(tid_t targetTid, std::string &result);
|
||||
|
||||
AsyncLockManager() = delete;
|
||||
|
@ -18,9 +18,9 @@
|
||||
|
||||
namespace Commonlibrary::Concurrent::LocksModule {
|
||||
|
||||
using tid_t = int;
|
||||
using tid_t = uint32_t;
|
||||
inline constexpr tid_t INVALID_TID = std::numeric_limits<tid_t>::max();
|
||||
|
||||
} // namespace Commonlibrary::Concurrent::LocksModule
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -209,7 +209,7 @@ void LockRequest::TimeoutCallback(uv_timer_t *handle)
|
||||
// Check deadlocks and form the rejector value with or w/o the warning. It is required to be done
|
||||
// first in order to obtain the actual data.
|
||||
std::string error;
|
||||
AsyncLockManager::DumpLocksInfoForThread(AsyncLockManager::GetCurrentTid(), error);
|
||||
AsyncLockManager::DumpLocksInfoForThread(AsyncLockManager::GetCurrentTid(data->request->env_), error);
|
||||
|
||||
// NOTE: both AsyncLock and LockRequest might be deleted here, but at this point we imply that
|
||||
// AsyncLock exists, later on we we will handle the case when it does not
|
||||
|
Loading…
Reference in New Issue
Block a user