1/* 2* Copyright (c) 2023 Huawei Device Co., Ltd. 3* Licensed under the Apache License, Version 2.0 (the "License"); 4* you may not use this file except in compliance with the License. 5* You may obtain a copy of the License at 6* 7* http://www.apache.org/licenses/LICENSE-2.0 8* 9* Unless required by applicable law or agreed to in writing, software 10* distributed under the License is distributed on an "AS IS" BASIS, 11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12* See the License for the specific language governing permissions and 13* limitations under the License. 14*/ 15 16#include "ecmascript/debugger/js_debugger_manager.h" 17 18namespace panda::ecmascript::tooling { 19 20 std::unordered_map<int, JsDebuggerManager *> JsDebuggerManager::jsDebuggerManagerMap_ {}; 21 std::shared_mutex JsDebuggerManager::mutex_; 22 23 void JsDebuggerManager::AddJsDebuggerManager (int tid, JsDebuggerManager *jsDebuggerManager) 24 { 25 std::unique_lock<std::shared_mutex> lock(mutex_); 26 if (jsDebuggerManagerMap_.find(tid) == jsDebuggerManagerMap_.end()) { 27 jsDebuggerManagerMap_.emplace(tid, jsDebuggerManager); 28 } 29 } 30 31 JsDebuggerManager *JsDebuggerManager::GetJsDebuggerManager(int tid) 32 { 33 std::shared_lock<std::shared_mutex> lock(mutex_); 34 if (jsDebuggerManagerMap_.find(tid) == jsDebuggerManagerMap_.end()) { 35 return nullptr; 36 } 37 return jsDebuggerManagerMap_[tid]; 38 } 39 40 void JsDebuggerManager::DeleteJsDebuggerManager(int tid) 41 { 42 std::unique_lock<std::shared_mutex> lock(mutex_); 43 auto it = jsDebuggerManagerMap_.find(tid); 44 if (it != jsDebuggerManagerMap_.end()) { 45 jsDebuggerManagerMap_.erase(it); 46 } 47 } 48} // namespace panda::ecmascript::tooling