Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a6b327fb
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a6b327fb
编写于
2月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
exception
上级
0fae01c9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
160 addition
and
171 deletion
+160
-171
include/util/exception.h
include/util/exception.h
+76
-70
source/util/src/exception.c
source/util/src/exception.c
+84
-101
未找到文件。
include/util/exception.h
浏览文件 @
a6b327fb
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_UTIL_EXCEPTION_H
#define _TD_UTIL_EXCEPTION_H
#ifndef _TD_UTIL_EXCEPTION_H
_
#define _TD_UTIL_EXCEPTION_H
_
#include "os.h"
...
...
@@ -26,100 +26,106 @@ extern "C" {
* cleanup actions
*/
typedef
struct
SCleanupAction
{
bool
failOnly
;
uint8_t
wrapper
;
uint16_t
reserved
;
void
*
func
;
union
{
void
*
Ptr
;
bool
Bool
;
char
Char
;
int8_t
Int8
;
uint8_t
Uint8
;
int16_t
Int16
;
uint16_t
Uint16
;
int
Int
;
unsigned
int
Uint
;
int32_t
Int32
;
uint32_t
Uint32
;
int64_t
Int64
;
uint64_t
Uint64
;
float
Float
;
double
Double
;
}
arg1
,
arg2
;
bool
failOnly
;
uint8_t
wrapper
;
uint16_t
reserved
;
void
*
func
;
union
{
void
*
Ptr
;
bool
Bool
;
char
Char
;
int8_t
Int8
;
uint8_t
Uint8
;
int16_t
Int16
;
uint16_t
Uint16
;
int
Int
;
unsigned
int
Uint
;
int32_t
Int32
;
uint32_t
Uint32
;
int64_t
Int64
;
uint64_t
Uint64
;
float
Float
;
double
Double
;
}
arg1
,
arg2
;
}
SCleanupAction
;
/*
* exception hander registration
*/
typedef
struct
SExceptionNode
{
struct
SExceptionNode
*
prev
;
jmp_buf
jb
;
int32_t
code
;
int32_t
maxCleanupAction
;
int32_t
numCleanupAction
;
SCleanupAction
*
cleanupActions
;
struct
SExceptionNode
*
prev
;
jmp_buf
jb
;
int32_t
code
;
int32_t
maxCleanupAction
;
int32_t
numCleanupAction
;
SCleanupAction
*
cleanupActions
;
}
SExceptionNode
;
////////////////////////////////////////////////////////////////////////////////
// functions & macros for auto-cleanup
void
cleanupPush_void_ptr_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg1
,
void
*
arg2
);
void
cleanupPush_void_ptr_bool
(
bool
failOnly
,
void
*
func
,
void
*
arg1
,
bool
arg2
);
void
cleanupPush_void_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg
);
void
cleanupPush_int_int
(
bool
failOnly
,
void
*
func
,
int
arg
);
void
cleanupPush_void
(
bool
failOnly
,
void
*
func
);
void
cleanupPush_int_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg
);
void
cleanupPush_void_ptr_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg1
,
void
*
arg2
);
void
cleanupPush_void_ptr_bool
(
bool
failOnly
,
void
*
func
,
void
*
arg1
,
bool
arg2
);
void
cleanupPush_void_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg
);
void
cleanupPush_int_int
(
bool
failOnly
,
void
*
func
,
int
arg
);
void
cleanupPush_void
(
bool
failOnly
,
void
*
func
);
void
cleanupPush_int_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg
);
int32_t
cleanupGetActionCount
();
void
cleanupExecuteTo
(
int32_t
anchor
,
bool
failed
);
void
cleanupExecute
(
SExceptionNode
*
node
,
bool
failed
);
bool
cleanupExceedLimit
();
#define CLEANUP_PUSH_VOID_PTR_PTR( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_ptr( (failOnly), (void*)(func), (void*)(arg1), (void*)(arg2) )
#define CLEANUP_PUSH_VOID_PTR_BOOL( failOnly, func, arg1, arg2 ) cleanupPush_void_ptr_bool( (failOnly), (void*)(func), (void*)(arg1), (bool)(arg2) )
#define CLEANUP_PUSH_VOID_PTR( failOnly, func, arg ) cleanupPush_void_ptr( (failOnly), (void*)(func), (void*)(arg) )
#define CLEANUP_PUSH_INT_INT( failOnly, func, arg ) cleanupPush_void_ptr( (failOnly), (void*)(func), (int)(arg) )
#define CLEANUP_PUSH_VOID( failOnly, func ) cleanupPush_void( (failOnly), (void*)(func) )
#define CLEANUP_PUSH_INT_PTR( failOnly, func, arg ) cleanupPush_int_ptr( (failOnly), (void*)(func), (void*)(arg) )
#define CLEANUP_PUSH_FREE( failOnly, arg ) cleanupPush_void_ptr( (failOnly), free, (void*)(arg) )
#define CLEANUP_PUSH_CLOSE( failOnly, arg ) cleanupPush_int_int( (failOnly), close, (int)(arg) )
#define CLEANUP_PUSH_FCLOSE( failOnly, arg ) cleanupPush_int_ptr( (failOnly), fclose, (void*)(arg) )
#define CLEANUP_GET_ANCHOR() cleanupGetActionCount()
#define CLEANUP_EXECUTE_TO( anchor, failed ) cleanupExecuteTo( (anchor), (failed) )
#define CLEANUP_EXCEED_LIMIT() cleanupExceedLimit()
void
cleanupExecuteTo
(
int32_t
anchor
,
bool
failed
);
void
cleanupExecute
(
SExceptionNode
*
node
,
bool
failed
);
bool
cleanupExceedLimit
();
#define CLEANUP_PUSH_VOID_PTR_PTR(failOnly, func, arg1, arg2) \
cleanupPush_void_ptr_ptr((failOnly), (void*)(func), (void*)(arg1), (void*)(arg2))
#define CLEANUP_PUSH_VOID_PTR_BOOL(failOnly, func, arg1, arg2) \
cleanupPush_void_ptr_bool((failOnly), (void*)(func), (void*)(arg1), (bool)(arg2))
#define CLEANUP_PUSH_VOID_PTR(failOnly, func, arg) cleanupPush_void_ptr((failOnly), (void*)(func), (void*)(arg))
#define CLEANUP_PUSH_INT_INT(failOnly, func, arg) cleanupPush_void_ptr((failOnly), (void*)(func), (int)(arg))
#define CLEANUP_PUSH_VOID(failOnly, func) cleanupPush_void((failOnly), (void*)(func))
#define CLEANUP_PUSH_INT_PTR(failOnly, func, arg) cleanupPush_int_ptr((failOnly), (void*)(func), (void*)(arg))
#define CLEANUP_PUSH_FREE(failOnly, arg) cleanupPush_void_ptr((failOnly), free, (void*)(arg))
#define CLEANUP_PUSH_CLOSE(failOnly, arg) cleanupPush_int_int((failOnly), close, (int)(arg))
#define CLEANUP_PUSH_FCLOSE(failOnly, arg) cleanupPush_int_ptr((failOnly), fclose, (void*)(arg))
#define CLEANUP_GET_ANCHOR() cleanupGetActionCount()
#define CLEANUP_EXECUTE_TO(anchor, failed) cleanupExecuteTo((anchor), (failed))
#define CLEANUP_EXCEED_LIMIT() cleanupExceedLimit()
////////////////////////////////////////////////////////////////////////////////
// functions & macros for exception handling
void
exceptionPushNode
(
SExceptionNode
*
node
);
void
exceptionPushNode
(
SExceptionNode
*
node
);
int32_t
exceptionPopNode
();
void
exceptionThrow
(
int32_t
code
);
void
exceptionThrow
(
int32_t
code
);
#define TRY(maxCleanupActions) do { \
SExceptionNode exceptionNode = { 0 }; \
SCleanupAction cleanupActions[(maxCleanupActions) > 0 ? (maxCleanupActions) : 1]; \
#define TRY(maxCleanupActions) \
do { \
SExceptionNode exceptionNode = {0}; \
SCleanupAction cleanupActions[(maxCleanupActions) > 0 ? (maxCleanupActions) : 1]; \
exceptionNode.maxCleanupAction = (maxCleanupActions) > 0 ? (maxCleanupActions) : 1; \
exceptionNode.cleanupActions = cleanupActions; \
exceptionPushNode(
&exceptionNode );
\
int caughtException = setjmp(
exceptionNode.jb );
\
if
( caughtException == 0
)
exceptionNode.cleanupActions = cleanupActions;
\
exceptionPushNode(
&exceptionNode);
\
int caughtException = setjmp(
exceptionNode.jb);
\
if
(caughtException == 0
)
#define CATCH( code ) int32_t code = exceptionPopNode(); \
if( caughtException == 1 )
#define CATCH(code) \
int32_t code = exceptionPopNode(); \
if (caughtException == 1)
#define FINALLY(
code
) int32_t code = exceptionPopNode();
#define FINALLY(
code
) int32_t code = exceptionPopNode();
#define END_TRY } while( 0 );
#define END_TRY \
} \
while (0) \
;
#define THROW(
x ) exceptionThrow( (x)
)
#define CAUGHT_EXCEPTION()
((bool)(caughtException == 1))
#define CLEANUP_EXECUTE()
cleanupExecute( &exceptionNode, CAUGHT_EXCEPTION()
)
#define THROW(
x) exceptionThrow((x)
)
#define CAUGHT_EXCEPTION() ((bool)(caughtException == 1))
#define CLEANUP_EXECUTE()
cleanupExecute(&exceptionNode, CAUGHT_EXCEPTION()
)
#ifdef __cplusplus
}
#endif
#endif
/*_TD_UTIL_EXCEPTION_H*/
#endif
/*_TD_UTIL_EXCEPTION_H
_
*/
source/util/src/exception.c
浏览文件 @
a6b327fb
...
...
@@ -13,154 +13,137 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#
include "os.h"
#
define _DEFAULT_SOURCE
#include "exception.h"
static
threadlocal
SExceptionNode
*
expList
;
void
exceptionPushNode
(
SExceptionNode
*
node
)
{
node
->
prev
=
expList
;
expList
=
node
;
void
exceptionPushNode
(
SExceptionNode
*
node
)
{
node
->
prev
=
expList
;
expList
=
node
;
}
int32_t
exceptionPopNode
()
{
SExceptionNode
*
node
=
expList
;
expList
=
node
->
prev
;
return
node
->
code
;
SExceptionNode
*
node
=
expList
;
expList
=
node
->
prev
;
return
node
->
code
;
}
void
exceptionThrow
(
int32_t
code
)
{
expList
->
code
=
code
;
longjmp
(
expList
->
jb
,
1
);
void
exceptionThrow
(
int32_t
code
)
{
expList
->
code
=
code
;
longjmp
(
expList
->
jb
,
1
);
}
static
void
cleanupWrapper_void_ptr_ptr
(
SCleanupAction
*
ca
)
{
void
(
*
func
)(
void
*
,
void
*
)
=
ca
->
func
;
func
(
ca
->
arg1
.
Ptr
,
ca
->
arg2
.
Ptr
);
static
void
cleanupWrapper_void_ptr_ptr
(
SCleanupAction
*
ca
)
{
void
(
*
func
)(
void
*
,
void
*
)
=
ca
->
func
;
func
(
ca
->
arg1
.
Ptr
,
ca
->
arg2
.
Ptr
);
}
static
void
cleanupWrapper_void_ptr_bool
(
SCleanupAction
*
ca
)
{
void
(
*
func
)(
void
*
,
bool
)
=
ca
->
func
;
func
(
ca
->
arg1
.
Ptr
,
ca
->
arg2
.
Bool
);
static
void
cleanupWrapper_void_ptr_bool
(
SCleanupAction
*
ca
)
{
void
(
*
func
)(
void
*
,
bool
)
=
ca
->
func
;
func
(
ca
->
arg1
.
Ptr
,
ca
->
arg2
.
Bool
);
}
static
void
cleanupWrapper_void_ptr
(
SCleanupAction
*
ca
)
{
void
(
*
func
)(
void
*
)
=
ca
->
func
;
func
(
ca
->
arg1
.
Ptr
);
static
void
cleanupWrapper_void_ptr
(
SCleanupAction
*
ca
)
{
void
(
*
func
)(
void
*
)
=
ca
->
func
;
func
(
ca
->
arg1
.
Ptr
);
}
static
void
cleanupWrapper_int_int
(
SCleanupAction
*
ca
)
{
int
(
*
func
)(
int
)
=
ca
->
func
;
func
(
ca
->
arg1
.
Int
);
static
void
cleanupWrapper_int_int
(
SCleanupAction
*
ca
)
{
int32_t
(
*
func
)(
int32_t
)
=
ca
->
func
;
func
(
ca
->
arg1
.
Int
);
}
static
void
cleanupWrapper_void
(
SCleanupAction
*
ca
)
{
void
(
*
func
)()
=
ca
->
func
;
func
();
static
void
cleanupWrapper_void
(
SCleanupAction
*
ca
)
{
void
(
*
func
)()
=
ca
->
func
;
func
();
}
static
void
cleanupWrapper_int_ptr
(
SCleanupAction
*
ca
)
{
int
(
*
func
)(
void
*
)
=
ca
->
func
;
func
(
ca
->
arg1
.
Ptr
);
static
void
cleanupWrapper_int_ptr
(
SCleanupAction
*
ca
)
{
int32_t
(
*
func
)(
void
*
)
=
ca
->
func
;
func
(
ca
->
arg1
.
Ptr
);
}
typedef
void
(
*
wrapper
)(
SCleanupAction
*
);
static
wrapper
wrappers
[]
=
{
cleanupWrapper_void_ptr_ptr
,
cleanupWrapper_void_ptr_bool
,
cleanupWrapper_void_ptr
,
cleanupWrapper_int_int
,
cleanupWrapper_void
,
cleanupWrapper_int_ptr
,
cleanupWrapper_void_ptr_ptr
,
cleanupWrapper_void_ptr_bool
,
cleanupWrapper_void_ptr
,
cleanupWrapper_int_int
,
cleanupWrapper_void
,
cleanupWrapper_int_ptr
,
};
void
cleanupPush_void_ptr_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg1
,
void
*
arg2
)
{
assert
(
expList
->
numCleanupAction
<
expList
->
maxCleanupAction
);
void
cleanupPush_void_ptr_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg1
,
void
*
arg2
)
{
assert
(
expList
->
numCleanupAction
<
expList
->
maxCleanupAction
);
SCleanupAction
*
ca
=
expList
->
cleanupActions
+
expList
->
numCleanupAction
++
;
ca
->
wrapper
=
0
;
ca
->
failOnly
=
failOnly
;
ca
->
func
=
func
;
ca
->
arg1
.
Ptr
=
arg1
;
ca
->
arg2
.
Ptr
=
arg2
;
SCleanupAction
*
ca
=
expList
->
cleanupActions
+
expList
->
numCleanupAction
++
;
ca
->
wrapper
=
0
;
ca
->
failOnly
=
failOnly
;
ca
->
func
=
func
;
ca
->
arg1
.
Ptr
=
arg1
;
ca
->
arg2
.
Ptr
=
arg2
;
}
void
cleanupPush_void_ptr_bool
(
bool
failOnly
,
void
*
func
,
void
*
arg1
,
bool
arg2
)
{
assert
(
expList
->
numCleanupAction
<
expList
->
maxCleanupAction
);
void
cleanupPush_void_ptr_bool
(
bool
failOnly
,
void
*
func
,
void
*
arg1
,
bool
arg2
)
{
assert
(
expList
->
numCleanupAction
<
expList
->
maxCleanupAction
);
SCleanupAction
*
ca
=
expList
->
cleanupActions
+
expList
->
numCleanupAction
++
;
ca
->
wrapper
=
1
;
ca
->
failOnly
=
failOnly
;
ca
->
func
=
func
;
ca
->
arg1
.
Ptr
=
arg1
;
ca
->
arg2
.
Bool
=
arg2
;
SCleanupAction
*
ca
=
expList
->
cleanupActions
+
expList
->
numCleanupAction
++
;
ca
->
wrapper
=
1
;
ca
->
failOnly
=
failOnly
;
ca
->
func
=
func
;
ca
->
arg1
.
Ptr
=
arg1
;
ca
->
arg2
.
Bool
=
arg2
;
}
void
cleanupPush_void_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg
)
{
assert
(
expList
->
numCleanupAction
<
expList
->
maxCleanupAction
);
void
cleanupPush_void_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg
)
{
assert
(
expList
->
numCleanupAction
<
expList
->
maxCleanupAction
);
SCleanupAction
*
ca
=
expList
->
cleanupActions
+
expList
->
numCleanupAction
++
;
ca
->
wrapper
=
2
;
ca
->
failOnly
=
failOnly
;
ca
->
func
=
func
;
ca
->
arg1
.
Ptr
=
arg
;
SCleanupAction
*
ca
=
expList
->
cleanupActions
+
expList
->
numCleanupAction
++
;
ca
->
wrapper
=
2
;
ca
->
failOnly
=
failOnly
;
ca
->
func
=
func
;
ca
->
arg1
.
Ptr
=
arg
;
}
void
cleanupPush_int_int
(
bool
failOnly
,
void
*
func
,
int
arg
)
{
assert
(
expList
->
numCleanupAction
<
expList
->
maxCleanupAction
);
void
cleanupPush_int_int
(
bool
failOnly
,
void
*
func
,
int32_t
arg
)
{
assert
(
expList
->
numCleanupAction
<
expList
->
maxCleanupAction
);
SCleanupAction
*
ca
=
expList
->
cleanupActions
+
expList
->
numCleanupAction
++
;
ca
->
wrapper
=
3
;
ca
->
failOnly
=
failOnly
;
ca
->
func
=
func
;
ca
->
arg1
.
Int
=
arg
;
SCleanupAction
*
ca
=
expList
->
cleanupActions
+
expList
->
numCleanupAction
++
;
ca
->
wrapper
=
3
;
ca
->
failOnly
=
failOnly
;
ca
->
func
=
func
;
ca
->
arg1
.
Int
=
arg
;
}
void
cleanupPush_void
(
bool
failOnly
,
void
*
func
)
{
assert
(
expList
->
numCleanupAction
<
expList
->
maxCleanupAction
);
void
cleanupPush_void
(
bool
failOnly
,
void
*
func
)
{
assert
(
expList
->
numCleanupAction
<
expList
->
maxCleanupAction
);
SCleanupAction
*
ca
=
expList
->
cleanupActions
+
expList
->
numCleanupAction
++
;
ca
->
wrapper
=
4
;
ca
->
failOnly
=
failOnly
;
ca
->
func
=
func
;
SCleanupAction
*
ca
=
expList
->
cleanupActions
+
expList
->
numCleanupAction
++
;
ca
->
wrapper
=
4
;
ca
->
failOnly
=
failOnly
;
ca
->
func
=
func
;
}
void
cleanupPush_int_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg
)
{
assert
(
expList
->
numCleanupAction
<
expList
->
maxCleanupAction
);
void
cleanupPush_int_ptr
(
bool
failOnly
,
void
*
func
,
void
*
arg
)
{
assert
(
expList
->
numCleanupAction
<
expList
->
maxCleanupAction
);
SCleanupAction
*
ca
=
expList
->
cleanupActions
+
expList
->
numCleanupAction
++
;
ca
->
wrapper
=
5
;
ca
->
failOnly
=
failOnly
;
ca
->
func
=
func
;
ca
->
arg1
.
Ptr
=
arg
;
SCleanupAction
*
ca
=
expList
->
cleanupActions
+
expList
->
numCleanupAction
++
;
ca
->
wrapper
=
5
;
ca
->
failOnly
=
failOnly
;
ca
->
func
=
func
;
ca
->
arg1
.
Ptr
=
arg
;
}
int32_t
cleanupGetActionCount
()
{
return
expList
->
numCleanupAction
;
}
int32_t
cleanupGetActionCount
()
{
return
expList
->
numCleanupAction
;
}
static
void
doExecuteCleanup
(
SExceptionNode
*
node
,
int32_t
anchor
,
bool
failed
)
{
while
(
node
->
numCleanupAction
>
anchor
)
{
--
node
->
numCleanupAction
;
SCleanupAction
*
ca
=
node
->
cleanupActions
+
node
->
numCleanupAction
;
if
(
failed
||
!
(
ca
->
failOnly
)
)
{
wrappers
[
ca
->
wrapper
](
ca
);
}
static
void
doExecuteCleanup
(
SExceptionNode
*
node
,
int32_t
anchor
,
bool
failed
)
{
while
(
node
->
numCleanupAction
>
anchor
)
{
--
node
->
numCleanupAction
;
SCleanupAction
*
ca
=
node
->
cleanupActions
+
node
->
numCleanupAction
;
if
(
failed
||
!
(
ca
->
failOnly
))
{
wrappers
[
ca
->
wrapper
](
ca
);
}
}
}
void
cleanupExecuteTo
(
int32_t
anchor
,
bool
failed
)
{
doExecuteCleanup
(
expList
,
anchor
,
failed
);
}
void
cleanupExecuteTo
(
int32_t
anchor
,
bool
failed
)
{
doExecuteCleanup
(
expList
,
anchor
,
failed
);
}
void
cleanupExecute
(
SExceptionNode
*
node
,
bool
failed
)
{
doExecuteCleanup
(
node
,
0
,
failed
);
}
bool
cleanupExceedLimit
()
{
return
expList
->
numCleanupAction
>=
expList
->
maxCleanupAction
;
}
void
cleanupExecute
(
SExceptionNode
*
node
,
bool
failed
)
{
doExecuteCleanup
(
node
,
0
,
failed
);
}
bool
cleanupExceedLimit
()
{
return
expList
->
numCleanupAction
>=
expList
->
maxCleanupAction
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录