Apollo 10.0
自动驾驶开放平台
class_loader.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
17
18namespace apollo {
19namespace cyber {
20namespace class_loader {
21ClassLoader::ClassLoader(const std::string& library_path)
22 : library_path_(library_path),
23 loadlib_ref_count_(0),
24 classobj_ref_count_(0) {
26}
27
29
31 return utility::IsLibraryLoaded(library_path_, this);
32}
33
35 std::lock_guard<std::mutex> lck(loadlib_ref_count_mutex_);
36 ++loadlib_ref_count_;
37 AINFO << "Begin LoadLibrary: " << library_path_;
38 return utility::LoadLibrary(library_path_, this);
39}
40
42 std::lock_guard<std::mutex> lckLib(loadlib_ref_count_mutex_);
43 std::lock_guard<std::mutex> lckObj(classobj_ref_count_mutex_);
44
45 if (classobj_ref_count_ > 0) {
46 AINFO << "There are still classobjs have not been deleted, "
47 "classobj_ref_count_: "
48 << classobj_ref_count_;
49 } else {
50 --loadlib_ref_count_;
51 if (loadlib_ref_count_ == 0) {
52 utility::UnloadLibrary(library_path_, this);
53 } else {
54 if (loadlib_ref_count_ < 0) {
55 loadlib_ref_count_ = 0;
56 }
57 }
58 }
59 return loadlib_ref_count_;
60}
61
62const std::string ClassLoader::GetLibraryPath() const { return library_path_; }
63
64} // namespace class_loader
65} // namespace cyber
66} // namespace apollo
const std::string GetLibraryPath() const
ClassLoader(const std::string &library_path)
#define AINFO
Definition log.h:42
bool LoadLibrary(const std::string &library_path, ClassLoader *loader)
void UnloadLibrary(const std::string &library_path, ClassLoader *loader)
bool IsLibraryLoaded(const std::string &library_path, ClassLoader *class_loader)
class register implement
Definition arena_queue.h:37