Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
a4174645
A
apollo
项目概览
Pinoxchio
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a4174645
编写于
12月 29, 2020
作者:
S
storypku
提交者:
Liu Jiaming
1月 06, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cyber: reorg optimized shared_library into independent directory
上级
a7f25a7b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
115 addition
and
68 deletion
+115
-68
cyber/class_loader/BUILD
cyber/class_loader/BUILD
+1
-13
cyber/class_loader/shared_library/BUILD
cyber/class_loader/shared_library/BUILD
+21
-0
cyber/class_loader/shared_library/exceptions.h
cyber/class_loader/shared_library/exceptions.h
+42
-0
cyber/class_loader/shared_library/shared_library.cc
cyber/class_loader/shared_library/shared_library.cc
+14
-16
cyber/class_loader/shared_library/shared_library.h
cyber/class_loader/shared_library/shared_library.h
+12
-14
cyber/class_loader/utility/class_loader_utility.cc
cyber/class_loader/utility/class_loader_utility.cc
+21
-21
cyber/class_loader/utility/class_loader_utility.h
cyber/class_loader/utility/class_loader_utility.h
+4
-4
未找到文件。
cyber/class_loader/BUILD
浏览文件 @
a4174645
...
...
@@ -3,18 +3,6 @@ load("//tools:cpplint.bzl", "cpplint")
package
(
default_visibility
=
[
"//visibility:public"
])
cc_library
(
name
=
"shared_library"
,
srcs
=
[
"utility/shared_library.cc"
,
],
hdrs
=
[
"utility/shared_library.h"
,
"utility/exception.h"
,
],
linkopts
=
[
'-ldl'
],
)
cc_library
(
name
=
"class_loader"
,
srcs
=
[
...
...
@@ -31,7 +19,7 @@ cc_library(
deps
=
[
"//cyber:init"
,
"//cyber/common:log"
,
"//cyber/class_loader
:
shared_library"
,
"//cyber/class_loader
/
shared_library"
,
],
)
...
...
cyber/class_loader/shared_library/BUILD
0 → 100644
浏览文件 @
a4174645
load
(
"@rules_cc//cc:defs.bzl"
,
"cc_library"
)
load
(
"//tools:cpplint.bzl"
,
"cpplint"
)
package
(
default_visibility
=
[
"//visibility:public"
])
cc_library
(
name
=
"shared_library"
,
srcs
=
[
"shared_library.cc"
],
hdrs
=
[
"shared_library.h"
],
linkopts
=
[
"-ldl"
],
deps
=
[
":exceptions"
,
],
)
cc_library
(
name
=
"exceptions"
,
hdrs
=
[
"exceptions.h"
],
)
cpplint
()
cyber/class_loader/
utility/exception
.h
→
cyber/class_loader/
shared_library/exceptions
.h
浏览文件 @
a4174645
/******************************************************************************
* Copyright 20
18
The Apollo Authors. All Rights Reserved.
* Copyright 20
20
The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -14,38 +14,29 @@
* limitations under the License.
*****************************************************************************/
#ifndef CYBER_CLASS_LOADER_
UTILITY_EXCEPTION
_H_
#define CYBER_CLASS_LOADER_
UTILITY_EXCEPTION
_H_
#ifndef CYBER_CLASS_LOADER_
SHARED_LIBRARY_EXCEPTIONS
_H_
#define CYBER_CLASS_LOADER_
SHARED_LIBRARY_EXCEPTIONS
_H_
#include <string>
#include <exception>
#include <stdexcept>
namespace
apollo
{
namespace
cyber
{
namespace
class_loader
{
namespace
utility
{
#define DECLARE_EXCEPTION_CLASS(CLS, BASE) \
class CLS : public BASE { \
public: \
explicit CLS(const std::string& err_msg) : err_msg_(err_msg) {} \
const char* what() const noexcept override { \
return err_msg_.c_str(); \
} \
private: \
std::string err_msg_; \
#define DECLARE_SHARED_LIBRARY_EXCEPTION(CLS, BASE) \
class CLS : public BASE { \
public: \
explicit CLS(const std::string& err_msg) : BASE(err_msg) {} \
~CLS() throw() {} \
};
DECLARE_SHARED_LIBRARY_EXCEPTION
(
LibraryAlreadyLoadedException
,
std
::
runtime_error
);
DECLARE_SHARED_LIBRARY_EXCEPTION
(
LibraryLoadException
,
std
::
runtime_error
);
DECLARE_SHARED_LIBRARY_EXCEPTION
(
SymbolNotFoundException
,
std
::
runtime_error
);
DECLARE_EXCEPTION_CLASS
(
LibraryAlreadyLoadedException
,
std
::
exception
)
DECLARE_EXCEPTION_CLASS
(
LibraryLoadException
,
std
::
exception
)
DECLARE_EXCEPTION_CLASS
(
NotFoundException
,
std
::
exception
)
}
// namespace utility
}
// namespace class_loader
}
// namespace cyber
}
// namespace apollo
#endif // CYBER_CLASS_LOADER_
UTILITY_EXCEPTION
_H_
#endif // CYBER_CLASS_LOADER_
SHARED_LIBRARY_EXCEPTIONS
_H_
cyber/class_loader/
utilit
y/shared_library.cc
→
cyber/class_loader/
shared_librar
y/shared_library.cc
浏览文件 @
a4174645
...
...
@@ -14,32 +14,31 @@
* limitations under the License.
*****************************************************************************/
#include "cyber/class_loader/
utilit
y/shared_library.h"
#include "cyber/class_loader/
shared_librar
y/shared_library.h"
#include <dlfcn.h>
namespace
apollo
{
namespace
cyber
{
namespace
class_loader
{
namespace
utility
{
SharedLibrary
::
SharedLibrary
()
:
handle_
(
nullptr
)
{}
SharedLibrary
::
SharedLibrary
(
const
std
::
string
&
filename
)
{
Load
(
filename
,
0
);
SharedLibrary
::
SharedLibrary
(
const
std
::
string
&
path
)
{
Load
(
path
,
0
);
}
SharedLibrary
::
SharedLibrary
(
const
std
::
string
&
filename
,
int
flags
)
{
Load
(
filename
,
flags
);
SharedLibrary
::
SharedLibrary
(
const
std
::
string
&
path
,
int
flags
)
{
Load
(
path
,
flags
);
}
void
SharedLibrary
::
Load
(
const
std
::
string
&
filename
)
{
Load
(
filename
,
0
);
void
SharedLibrary
::
Load
(
const
std
::
string
&
path
)
{
Load
(
path
,
0
);
}
void
SharedLibrary
::
Load
(
const
std
::
string
&
filename
,
int
flags
)
{
void
SharedLibrary
::
Load
(
const
std
::
string
&
path
,
int
flags
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
if
(
handle_
)
throw
LibraryAlreadyLoadedException
(
filename
);
if
(
handle_
)
throw
LibraryAlreadyLoadedException
(
path
);
int
real_flag
=
RTLD_LAZY
;
if
(
flags
&
SHLIB_LOCAL
)
{
...
...
@@ -47,13 +46,13 @@ void SharedLibrary::Load(const std::string& filename, int flags) {
}
else
{
real_flag
|=
SHLIB_GLOBAL
;
}
handle_
=
dlopen
(
filename
.
c_str
(),
real_flag
);
handle_
=
dlopen
(
path
.
c_str
(),
real_flag
);
if
(
!
handle_
)
{
const
char
*
err
=
dlerror
();
throw
LibraryLoadException
(
err
?
std
::
string
(
err
)
:
filename
);
throw
LibraryLoadException
(
err
?
std
::
string
(
err
)
:
path
);
}
filename_
=
filename
;
path_
=
path
;
}
void
SharedLibrary
::
Unload
()
{
...
...
@@ -79,7 +78,7 @@ void* SharedLibrary::GetSymbol(const std::string& name) {
void
*
result
=
dlsym
(
handle_
,
name
.
c_str
());
if
(
!
result
)
{
throw
NotFoundException
(
name
);
throw
Symbol
NotFoundException
(
name
);
}
return
result
;
...
...
@@ -90,7 +89,6 @@ SharedLibrary::~SharedLibrary() {
}
}
// namespace utility
}
// namespace class_loader
}
// namespace shared_library
}
// namespace cyber
}
// namespace apollo
cyber/class_loader/
utilit
y/shared_library.h
→
cyber/class_loader/
shared_librar
y/shared_library.h
浏览文件 @
a4174645
/******************************************************************************
* Copyright 20
18
The Apollo Authors. All Rights Reserved.
* Copyright 20
20
The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -14,18 +14,17 @@
* limitations under the License.
*****************************************************************************/
#ifndef CYBER_CLASS_LOADER_
UTILITY_
SHARED_LIBRARY_H_
#define CYBER_CLASS_LOADER_
UTILITY_
SHARED_LIBRARY_H_
#ifndef CYBER_CLASS_LOADER_SHARED_LIBRARY_H_
#define CYBER_CLASS_LOADER_SHARED_LIBRARY_H_
#include <string>
#include <mutex>
#include "cyber/class_loader/
utility/exception
.h"
#include "cyber/class_loader/
shared_library/exceptions
.h"
namespace
apollo
{
namespace
cyber
{
namespace
class_loader
{
namespace
utility
{
class
SharedLibrary
{
public:
...
...
@@ -36,15 +35,15 @@ class SharedLibrary {
SharedLibrary
();
explicit
SharedLibrary
(
const
std
::
string
&
filename
);
explicit
SharedLibrary
(
const
std
::
string
&
path
);
SharedLibrary
(
const
std
::
string
&
filename
,
int
flags
);
SharedLibrary
(
const
std
::
string
&
path
,
int
flags
);
virtual
~
SharedLibrary
();
void
Load
(
const
std
::
string
&
filename
);
void
Load
(
const
std
::
string
&
path
);
void
Load
(
const
std
::
string
&
filename
,
int
flags
);
void
Load
(
const
std
::
string
&
path
,
int
flags
);
void
Unload
();
...
...
@@ -54,21 +53,20 @@ class SharedLibrary {
void
*
GetSymbol
(
const
std
::
string
&
name
);
inline
const
std
::
string
&
GetPath
()
const
{
return
filename
_
;
}
inline
const
std
::
string
&
GetPath
()
const
{
return
path
_
;
}
SharedLibrary
(
const
SharedLibrary
&
)
=
delete
;
SharedLibrary
&
operator
=
(
const
SharedLibrary
&
)
=
delete
;
private:
void
*
handle_
;
std
::
string
filename
_
;
void
*
handle_
=
nullptr
;
std
::
string
path
_
;
std
::
mutex
mutex_
;
};
}
// namespace utility
}
// namespace class_loader
}
// namespace cyber
}
// namespace apollo
#endif // CYBER_CLASS_LOADER_
UTILITY_
SHARED_LIBRARY_H_
#endif // CYBER_CLASS_LOADER_SHARED_LIBRARY_H_
cyber/class_loader/utility/class_loader_utility.cc
浏览文件 @
a4174645
...
...
@@ -28,7 +28,7 @@ std::recursive_mutex& GetClassFactoryMapMapMutex() {
return
m
;
}
std
::
recursive_mutex
&
GetLibPathShareLibMutex
()
{
std
::
recursive_mutex
&
GetLibPathShare
d
LibMutex
()
{
static
std
::
recursive_mutex
m
;
return
m
;
}
...
...
@@ -38,8 +38,8 @@ BaseToClassFactoryMapMap& GetClassFactoryMapMap() {
return
instance
;
}
Lib
pathSharedlibVector
&
GetLibPathShare
LibVector
()
{
static
Lib
pathSharedl
ibVector
instance
;
Lib
PathSharedLibVector
&
GetLibPathShared
LibVector
()
{
static
Lib
PathSharedL
ibVector
instance
;
return
instance
;
}
...
...
@@ -127,7 +127,7 @@ void DestroyClassFactoryObjectsOfLibrary(
if
(
class_factory_object
->
GetRelativeLibraryPath
()
==
library_path
&&
class_factory_object
->
IsOwnedBy
(
class_loader
))
{
class_factory_object
->
RemoveOwnedClassLoader
(
class_loader
);
// when no anybody owner,delete && erase
// when no anybody owner,
delete && erase
if
(
!
class_factory_object
->
IsOwnedByAnybody
())
{
itr
=
class_factory_map
->
erase
(
itr
);
delete
class_factory_object
;
...
...
@@ -151,10 +151,10 @@ void DestroyClassFactoryObjectsOfLibrary(const std::string& library_path,
}
}
Lib
pathSharedl
ibVector
::
iterator
FindLoadedLibrary
(
Lib
PathSharedL
ibVector
::
iterator
FindLoadedLibrary
(
const
std
::
string
&
library_path
)
{
Lib
pathSharedlibVector
&
opened_libraries
=
GetLibPathShare
LibVector
();
Lib
pathSharedl
ibVector
::
iterator
itr
;
Lib
PathSharedLibVector
&
opened_libraries
=
GetLibPathShared
LibVector
();
Lib
PathSharedL
ibVector
::
iterator
itr
;
for
(
itr
=
opened_libraries
.
begin
();
itr
!=
opened_libraries
.
end
();
++
itr
)
{
if
(
itr
->
first
==
library_path
)
{
break
;
...
...
@@ -164,10 +164,10 @@ LibpathSharedlibVector::iterator FindLoadedLibrary(
}
bool
IsLibraryLoadedByAnybody
(
const
std
::
string
&
library_path
)
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lck
(
GetLibPathShareLibMutex
());
std
::
lock_guard
<
std
::
recursive_mutex
>
lck
(
GetLibPathShare
d
LibMutex
());
Lib
pathSharedlibVector
&
opened_libraries
=
GetLibPathShare
LibVector
();
Lib
pathSharedl
ibVector
::
iterator
itr
=
FindLoadedLibrary
(
library_path
);
Lib
PathSharedLibVector
&
opened_libraries
=
GetLibPathShared
LibVector
();
Lib
PathSharedL
ibVector
::
iterator
itr
=
FindLoadedLibrary
(
library_path
);
return
itr
!=
opened_libraries
.
end
();
}
...
...
@@ -222,10 +222,10 @@ bool LoadLibrary(const std::string& library_path, ClassLoader* loader) {
SetCurLoadingLibraryName
(
""
);
SetCurActiveClassLoader
(
nullptr
);
AERROR
<<
"LibraryAlreadyLoadedException: "
<<
e
.
what
();
}
catch
(
const
NotFoundException
&
e
)
{
}
catch
(
const
Symbol
NotFoundException
&
e
)
{
SetCurLoadingLibraryName
(
""
);
SetCurActiveClassLoader
(
nullptr
);
AERROR
<<
"NotFoundException: "
<<
e
.
what
();
AERROR
<<
"
Symbol
NotFoundException: "
<<
e
.
what
();
}
SetCurLoadingLibraryName
(
""
);
...
...
@@ -242,8 +242,8 @@ bool LoadLibrary(const std::string& library_path, ClassLoader* loader) {
AWARN
<<
"Class factory objs counts is 0, maybe registerclass failed."
;
}
std
::
lock_guard
<
std
::
recursive_mutex
>
lck
(
GetLibPathShareLibMutex
());
Lib
pathSharedlibVector
&
opened_libraries
=
GetLibPathShare
LibVector
();
std
::
lock_guard
<
std
::
recursive_mutex
>
lck
(
GetLibPathShare
d
LibMutex
());
Lib
PathSharedLibVector
&
opened_libraries
=
GetLibPathShared
LibVector
();
opened_libraries
.
emplace_back
(
std
::
pair
<
std
::
string
,
SharedLibraryPtr
>
(
library_path
,
shared_library
));
return
true
;
...
...
@@ -251,9 +251,9 @@ bool LoadLibrary(const std::string& library_path, ClassLoader* loader) {
void
UnloadLibrary
(
const
std
::
string
&
library_path
,
ClassLoader
*
loader
)
{
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lck
(
GetLibPathShareLibMutex
());
Lib
pathSharedlibVector
&
opened_libraries
=
GetLibPathShare
LibVector
();
Lib
pathSharedl
ibVector
::
iterator
itr
=
FindLoadedLibrary
(
library_path
);
std
::
lock_guard
<
std
::
recursive_mutex
>
lck
(
GetLibPathShare
d
LibMutex
());
Lib
PathSharedLibVector
&
opened_libraries
=
GetLibPathShared
LibVector
();
Lib
PathSharedL
ibVector
::
iterator
itr
=
FindLoadedLibrary
(
library_path
);
if
(
itr
==
opened_libraries
.
end
())
{
AERROR
<<
"Attempt to UnloadLibrary lib, but can't find lib: "
<<
library_path
;
...
...
@@ -268,12 +268,12 @@ void UnloadLibrary(const std::string& library_path, ClassLoader* loader) {
itr
->
second
->
Unload
();
itr
=
opened_libraries
.
erase
(
itr
);
}
else
{
AWARN
<<
"ClassFactory
Objects still remain in memory,meaning other
"
"
ClassL
oaders are still using library:"
AWARN
<<
"ClassFactory
objects still remain in memory, meaning other
"
"
class l
oaders are still using library:"
<<
library_path
;
}
}
catch
(
const
std
::
exception
&
e
)
{
AERROR
<<
"
library unL
oad error: "
<<
e
.
what
();
}
catch
(
const
std
::
runtime_error
&
e
)
{
AERROR
<<
"
Library unl
oad error: "
<<
e
.
what
();
}
}
}
...
...
cyber/class_loader/utility/class_loader_utility.h
浏览文件 @
a4174645
...
...
@@ -28,7 +28,7 @@
#include <utility>
#include <vector>
#include "cyber/class_loader/
utilit
y/shared_library.h"
#include "cyber/class_loader/
shared_librar
y/shared_library.h"
#include "cyber/class_loader/utility/class_factory.h"
#include "cyber/common/log.h"
...
...
@@ -47,14 +47,14 @@ using SharedLibraryPtr = std::shared_ptr<SharedLibrary>;
using
ClassClassFactoryMap
=
std
::
map
<
std
::
string
,
utility
::
AbstractClassFactoryBase
*>
;
using
BaseToClassFactoryMapMap
=
std
::
map
<
std
::
string
,
ClassClassFactoryMap
>
;
using
Lib
pathSharedl
ibVector
=
using
Lib
PathSharedL
ibVector
=
std
::
vector
<
std
::
pair
<
std
::
string
,
SharedLibraryPtr
>>
;
using
ClassFactoryVector
=
std
::
vector
<
AbstractClassFactoryBase
*>
;
BaseToClassFactoryMapMap
&
GetClassFactoryMapMap
();
std
::
recursive_mutex
&
GetClassFactoryMapMapMutex
();
Lib
pathSharedlibVector
&
GetLibPathShare
LibVector
();
std
::
recursive_mutex
&
GetLibPathShareLibMutex
();
Lib
PathSharedLibVector
&
GetLibPathShared
LibVector
();
std
::
recursive_mutex
&
GetLibPathShare
d
LibMutex
();
ClassClassFactoryMap
&
GetClassFactoryMapByBaseClass
(
const
std
::
string
&
typeid_base_class_name
);
std
::
string
GetCurLoadingLibraryName
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录