Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
17dfbffb
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
17dfbffb
编写于
2月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
minor changes
上级
cb71affe
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
66 deletion
+44
-66
include/util/tjson.h
include/util/tjson.h
+6
-6
include/util/tlockfree.h
include/util/tlockfree.h
+21
-24
source/util/src/tjson.c
source/util/src/tjson.c
+14
-33
source/util/src/tlockfree.c
source/util/src/tlockfree.c
+3
-3
未找到文件。
include/util/tjson.h
浏览文件 @
17dfbffb
...
...
@@ -16,18 +16,18 @@
#ifndef _TD_UTIL_JSON_H_
#define _TD_UTIL_JSON_H_
#include "os.h"
#ifdef __cplusplus
extern
"C"
{
#endif
#include "os.h"
typedef
void
SJson
;
SJson
*
tjsonCreateObject
();
void
tjsonDelete
(
SJson
*
pJson
);
void
tjsonDelete
(
SJson
*
pJson
);
SJson
*
tjsonAddArrayToObject
(
SJson
*
pJson
,
const
char
*
pName
);
SJson
*
tjsonAddArrayToObject
(
SJson
*
pJson
,
const
char
*
pName
);
int32_t
tjsonAddIntegerToObject
(
SJson
*
pJson
,
const
char
*
pName
,
const
uint64_t
number
);
int32_t
tjsonAddDoubleToObject
(
SJson
*
pJson
,
const
char
*
pName
,
const
double
number
);
int32_t
tjsonAddBoolToObject
(
SJson
*
pJson
,
const
char
*
pName
,
const
bool
boolean
);
...
...
@@ -35,7 +35,7 @@ int32_t tjsonAddStringToObject(SJson* pJson, const char* pName, const char* pVal
int32_t
tjsonAddItemToObject
(
SJson
*
pJson
,
const
char
*
pName
,
SJson
*
pItem
);
int32_t
tjsonAddItemToArray
(
SJson
*
pJson
,
SJson
*
pItem
);
SJson
*
tjsonGetObjectItem
(
const
SJson
*
pJson
,
const
char
*
pName
);
SJson
*
tjsonGetObjectItem
(
const
SJson
*
pJson
,
const
char
*
pName
);
int32_t
tjsonGetStringValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
char
*
pVal
);
int32_t
tjsonDupStringValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
char
**
pVal
);
int32_t
tjsonGetBigIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
int64_t
*
pVal
);
...
...
@@ -48,7 +48,7 @@ int32_t tjsonGetBoolValue(const SJson* pJson, const char* pName, bool* pVal);
int32_t
tjsonGetDoubleValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
double
*
pVal
);
int32_t
tjsonGetArraySize
(
const
SJson
*
pJson
);
SJson
*
tjsonGetArrayItem
(
const
SJson
*
pJson
,
int32_t
index
);
SJson
*
tjsonGetArrayItem
(
const
SJson
*
pJson
,
int32_t
index
);
typedef
int32_t
(
*
FToJson
)(
const
void
*
pObj
,
SJson
*
pJson
);
...
...
include/util/tlockfree.h
浏览文件 @
17dfbffb
...
...
@@ -12,8 +12,9 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_UTIL_LOCK_FREE_H
#define _TD_UTIL_LOCK_FREE_H
#ifndef _TD_UTIL_LOCK_FREE_H_
#define _TD_UTIL_LOCK_FREE_H_
#include "os.h"
...
...
@@ -22,7 +23,7 @@ extern "C" {
#endif
// reference counting
typedef
void
(
*
_ref_fn_t
)(
const
void
*
pObj
);
typedef
void
(
*
_ref_fn_t
)(
const
void
*
pObj
);
#define T_REF_DECLARE() \
struct { \
...
...
@@ -67,8 +68,6 @@ typedef void (*_ref_fn_t)(const void* pObj);
#define T_REF_VAL_GET(x) (x)->_ref.val
// single writer multiple reader lock
typedef
volatile
int32_t
SRWLatch
;
...
...
@@ -78,35 +77,33 @@ void taosWUnLockLatch(SRWLatch *pLatch);
void
taosRLockLatch
(
SRWLatch
*
pLatch
);
void
taosRUnLockLatch
(
SRWLatch
*
pLatch
);
// copy on read
#define taosCorBeginRead(x) for (uint32_t i_ = 1; 1; ++i_) { \
#define taosCorBeginRead(x) \
for (uint32_t i_ = 1; 1; ++i_) { \
int32_t old_ = atomic_add_fetch_32((x), 0); \
if (old_ & 0x00000001) { \
if (i_ % 1000 == 0) { \
sched_yield(); \
} \
continue; \
if (old_ & 0x00000001) {
\
if (i_ % 1000 == 0) {
\
sched_yield();
\
}
\
continue;
\
}
#define taosCorEndRead(x) \
if (atomic_add_fetch_32((x), 0) == old_) { \
break;
\
}
\
#define taosCorEndRead(x)
\
if (atomic_add_fetch_32((x), 0) == old_) { \
break;
\
}
\
}
#define taosCorBeginWrite(x) taosCorBeginRead(x) \
if (atomic_val_compare_exchange_32((x), old_, old_ + 1) != old_) { \
continue; \
}
#define taosCorBeginWrite(x) \
taosCorBeginRead(x) if (atomic_val_compare_exchange_32((x), old_, old_ + 1) != old_) { continue; }
#define taosCorEndWrite(x) atomic_add_fetch_32((x), 1); \
break; \
#define taosCorEndWrite(x) \
atomic_add_fetch_32((x), 1); \
break; \
}
#ifdef __cplusplus
}
#endif
#endif
/*_TD_UTIL_LOCK_FREE_H*/
#endif
/*_TD_UTIL_LOCK_FREE_H
_
*/
source/util/src/tjson.c
浏览文件 @
17dfbffb
...
...
@@ -13,22 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "tjson.h"
#include "taoserror.h"
#include "cJSON.h"
#include "taoserror.h"
SJson
*
tjsonCreateObject
()
{
return
cJSON_CreateObject
();
}
SJson
*
tjsonCreateObject
()
{
return
cJSON_CreateObject
();
}
void
tjsonDelete
(
SJson
*
pJson
)
{
cJSON_Delete
((
cJSON
*
)
pJson
);
}
void
tjsonDelete
(
SJson
*
pJson
)
{
cJSON_Delete
((
cJSON
*
)
pJson
);
}
int32_t
tjsonAddIntegerToObject
(
SJson
*
pJson
,
const
char
*
pName
,
const
uint64_t
number
)
{
char
tmp
[
40
]
=
{
0
};
snprintf
(
tmp
,
tListLen
(
tmp
),
"%"
PRId64
,
number
);
snprintf
(
tmp
,
tListLen
(
tmp
),
"%"
PRId64
,
number
);
return
tjsonAddStringToObject
(
pJson
,
pName
,
tmp
);
}
...
...
@@ -44,11 +40,9 @@ int32_t tjsonAddStringToObject(SJson* pJson, const char* pName, const char* pVal
return
(
NULL
==
cJSON_AddStringToObject
((
cJSON
*
)
pJson
,
pName
,
pVal
)
?
TSDB_CODE_FAILED
:
TSDB_CODE_SUCCESS
);
}
SJson
*
tjsonAddArrayToObject
(
SJson
*
pJson
,
const
char
*
pName
)
{
return
cJSON_AddArrayToObject
((
cJSON
*
)
pJson
,
pName
);
}
SJson
*
tjsonAddArrayToObject
(
SJson
*
pJson
,
const
char
*
pName
)
{
return
cJSON_AddArrayToObject
((
cJSON
*
)
pJson
,
pName
);
}
int32_t
tjsonAddItemToObject
(
SJson
*
pJson
,
const
char
*
pName
,
SJson
*
pItem
)
{
int32_t
tjsonAddItemToObject
(
SJson
*
pJson
,
const
char
*
pName
,
SJson
*
pItem
)
{
return
(
cJSON_AddItemToObject
((
cJSON
*
)
pJson
,
pName
,
pItem
)
?
TSDB_CODE_SUCCESS
:
TSDB_CODE_FAILED
);
}
...
...
@@ -79,18 +73,11 @@ int32_t tjsonAddItem(SJson* pJson, FToJson func, const void* pObj) {
return
tjsonAddItemToArray
(
pJson
,
pJobj
);
}
char
*
tjsonToString
(
const
SJson
*
pJson
)
{
return
cJSON_Print
((
cJSON
*
)
pJson
);
}
char
*
tjsonToUnformattedString
(
const
SJson
*
pJson
)
{
return
cJSON_PrintUnformatted
((
cJSON
*
)
pJson
);
}
char
*
tjsonToString
(
const
SJson
*
pJson
)
{
return
cJSON_Print
((
cJSON
*
)
pJson
);
}
char
*
tjsonToUnformattedString
(
const
SJson
*
pJson
)
{
return
cJSON_PrintUnformatted
((
cJSON
*
)
pJson
);
}
SJson
*
tjsonGetObjectItem
(
const
SJson
*
pJson
,
const
char
*
pName
)
{
return
cJSON_GetObjectItem
(
pJson
,
pName
);
}
SJson
*
tjsonGetObjectItem
(
const
SJson
*
pJson
,
const
char
*
pName
)
{
return
cJSON_GetObjectItem
(
pJson
,
pName
);
}
int32_t
tjsonGetStringValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
char
*
pVal
)
{
char
*
p
=
cJSON_GetStringValue
(
tjsonGetObjectItem
((
cJSON
*
)
pJson
,
pName
));
...
...
@@ -153,7 +140,7 @@ int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pV
int32_t
tjsonGetUTinyIntValue
(
const
SJson
*
pJson
,
const
char
*
pName
,
uint8_t
*
pVal
)
{
uint64_t
val
=
0
;
int32_t
code
=
tjsonGetUBigIntValue
(
pJson
,
pName
,
&
val
);
int32_t
code
=
tjsonGetUBigIntValue
(
pJson
,
pName
,
&
val
);
*
pVal
=
val
;
return
code
;
}
...
...
@@ -176,13 +163,9 @@ int32_t tjsonGetDoubleValue(const SJson* pJson, const char* pName, double* pVal)
return
TSDB_CODE_SUCCESS
;
}
int32_t
tjsonGetArraySize
(
const
SJson
*
pJson
)
{
return
cJSON_GetArraySize
(
pJson
);
}
int32_t
tjsonGetArraySize
(
const
SJson
*
pJson
)
{
return
cJSON_GetArraySize
(
pJson
);
}
SJson
*
tjsonGetArrayItem
(
const
SJson
*
pJson
,
int32_t
index
)
{
return
cJSON_GetArrayItem
(
pJson
,
index
);
}
SJson
*
tjsonGetArrayItem
(
const
SJson
*
pJson
,
int32_t
index
)
{
return
cJSON_GetArrayItem
(
pJson
,
index
);
}
int32_t
tjsonToObject
(
const
SJson
*
pJson
,
const
char
*
pName
,
FToObject
func
,
void
*
pObj
)
{
SJson
*
pJsonObj
=
tjsonGetObjectItem
(
pJson
,
pName
);
...
...
@@ -192,6 +175,4 @@ int32_t tjsonToObject(const SJson* pJson, const char* pName, FToObject func, voi
return
func
(
pJsonObj
,
pObj
);
}
SJson
*
tjsonParse
(
const
char
*
pStr
)
{
return
cJSON_Parse
(
pStr
);
}
SJson
*
tjsonParse
(
const
char
*
pStr
)
{
return
cJSON_Parse
(
pStr
);
}
source/util/src/tlockfree.c
浏览文件 @
17dfbffb
...
...
@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#
include "os.h"
#
define _DEFAULT_SOURCE
#include "tlockfree.h"
#define TD_RWLATCH_WRITE_FLAG 0x40000000
...
...
@@ -22,7 +22,7 @@ void taosInitRWLatch(SRWLatch *pLatch) { *pLatch = 0; }
void
taosWLockLatch
(
SRWLatch
*
pLatch
)
{
SRWLatch
oLatch
,
nLatch
;
int
nLoops
=
0
;
int
32_t
nLoops
=
0
;
// Set write flag
while
(
1
)
{
...
...
@@ -57,7 +57,7 @@ void taosWUnLockLatch(SRWLatch *pLatch) { atomic_store_32(pLatch, 0); }
void
taosRLockLatch
(
SRWLatch
*
pLatch
)
{
SRWLatch
oLatch
,
nLatch
;
int
nLoops
=
0
;
int
32_t
nLoops
=
0
;
while
(
1
)
{
oLatch
=
atomic_load_32
(
pLatch
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录