Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4826a185
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看板
提交
4826a185
编写于
4月 24, 2020
作者:
weixin_48148422
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-153: add defer support
上级
736ddfbb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
85 addition
and
14 deletion
+85
-14
src/util/inc/exception.h
src/util/inc/exception.h
+59
-11
src/util/src/exception.c
src/util/src/exception.c
+26
-3
未找到文件。
src/util/inc/exception.h
浏览文件 @
4826a185
/*
* Copyright (c) 20
19
TAOS Data, Inc. <jhtao@taosdata.com>
* Copyright (c) 20
20
TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
...
...
@@ -17,33 +17,81 @@
#define TDENGINE_EXCEPTION_H
#include <setjmp.h>
#include <stdint.h>
#include <assert.h>
#ifdef __cplusplus
extern
"C"
{
#endif
/*
* exception handling
*/
typedef
struct
SExceptionNode
{
struct
SExceptionNode
*
prev
;
jmp_buf
jb
;
int
code
;
}
SExceptionNode
;
void
expPushNode
(
SExceptionNode
*
node
);
int
expPopNode
();
void
expThrow
(
int
code
);
void
exceptionPushNode
(
SExceptionNode
*
node
);
int
exceptionPopNode
();
void
exceptionThrow
(
int
code
);
#define THROW( x ) exceptionThrow( (x) )
#define CAUGHT_EXCEPTION() (caught_exception == 1)
#define TRY do { \
SExceptionNode expNode = { 0 }; \
expPushNode( &expNode ); \
if( setjmp(expNode.jb) == 0 ) {
exceptionPushNode( &expNode ); \
int caught_exception = setjmp(expNode.jb); \
if( caught_exception == 0 )
#define CATCH( code ) int code = exceptionPopNode(); \
if( caught_exception == 1 )
#define FINALLY( code ) int code = exceptionPopNode();
#define END_TRY } while( 0 );
/*
* defered operations
*/
typedef
struct
SDeferedOperation
{
void
(
*
wrapper
)(
struct
SDeferedOperation
*
dp
);
void
*
func
;
void
*
arg
;
}
SDeferedOperation
;
void
deferExecute
(
SDeferedOperation
*
operations
,
unsigned
int
numOfOperations
);
void
deferWrapper_void_void
(
SDeferedOperation
*
dp
);
void
deferWrapper_void_ptr
(
SDeferedOperation
*
dp
);
void
deferWrapper_int_int
(
SDeferedOperation
*
dp
);
#define DEFER_INIT( MaxOperations ) unsigned int maxDeferedOperations = MaxOperations, numOfDeferedOperations = 0; \
SDeferedOperation deferedOperations[MaxOperations]
#define DEFER_PUSH( wrapperFunc, deferedFunc, argument ) do { \
assert( numOfDeferedOperations < maxDeferedOperations ); \
SDeferedOperation* dp = deferedOperations + numOfDeferedOperations++; \
dp->wrapper = wrapperFunc; \
dp->func = (void*)deferedFunc; \
dp->arg = (void*)argument; \
} while( 0 )
#define DEFER_POP() do { --numOfDeferedOperations; } while( 0 )
#define CATCH( code ) expPopNode(); \
} else { \
int code = expPopNode();
#define DEFER_EXECUTE() do{ \
deferExecute( deferedOperations, numOfDeferedOperations ); \
numOfDeferedOperations = 0; \
} while( 0 )
#define END_CATCH } } while( 0 );
#define DEFER_PUSH_VOID_PTR( func, arg ) DEFER_PUSH( deferWrapper_void_ptr, func, arg )
#define DEFER_PUSH_INT_INT( func, arg ) DEFER_PUSH( deferWrapper_int_int, func, arg )
#define DEFER_PUSH_VOID_VOID( func ) DEFER_PUSH( deferWrapper_void_void, func, 0 )
#define THROW( x ) expThrow( (x) )
#define DEFER_PUSH_FREE( arg ) DEFER_PUSH( deferWrapper_void_ptr, free, arg )
#define DEFER_PUSH_CLOSE( arg ) DEFER_PUSH( deferWrapper_int_int, close, arg )
#ifdef __cplusplus
}
...
...
src/util/src/exception.c
浏览文件 @
4826a185
...
...
@@ -3,18 +3,41 @@
static
_Thread_local
SExceptionNode
*
expList
;
void
ex
p
PushNode
(
SExceptionNode
*
node
)
{
void
ex
ception
PushNode
(
SExceptionNode
*
node
)
{
node
->
prev
=
expList
;
expList
=
node
;
}
int
ex
p
PopNode
()
{
int
ex
ception
PopNode
()
{
SExceptionNode
*
node
=
expList
;
expList
=
node
->
prev
;
return
node
->
code
;
}
void
ex
p
Throw
(
int
code
)
{
void
ex
ception
Throw
(
int
code
)
{
expList
->
code
=
code
;
longjmp
(
expList
->
jb
,
1
);
}
void
deferWrapper_void_ptr
(
SDeferedOperation
*
dp
)
{
void
(
*
func
)(
void
*
)
=
dp
->
func
;
func
(
dp
->
arg
);
}
void
deferWrapper_int_int
(
SDeferedOperation
*
dp
)
{
int
(
*
func
)(
int
)
=
dp
->
func
;
func
(
(
int
)(
intptr_t
)(
dp
->
arg
)
);
}
void
deferWrapper_void_void
(
SDeferedOperation
*
dp
)
{
void
(
*
func
)()
=
dp
->
func
;
func
();
}
void
deferExecute
(
SDeferedOperation
*
operations
,
unsigned
int
numOfOperations
)
{
while
(
numOfOperations
>
0
)
{
--
numOfOperations
;
SDeferedOperation
*
dp
=
operations
+
numOfOperations
;
dp
->
wrapper
(
dp
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录