Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
12187a38
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
未验证
提交
12187a38
编写于
4月 19, 2022
作者:
H
Haojun Liao
提交者:
GitHub
4月 19, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9101 from haoyifan/tcache_cleanup_branch
Tcache cleanup branch
上级
8d2f7e63
fbfa7a09
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
31 addition
and
23 deletion
+31
-23
src/util/src/tcache.c
src/util/src/tcache.c
+31
-23
未找到文件。
src/util/src/tcache.c
浏览文件 @
12187a38
...
...
@@ -85,7 +85,7 @@ static void doInitRefreshThread(void) {
pthread_attr_destroy
(
&
thattr
);
}
pthread_t
doRegisterCacheObj
(
SCacheObj
*
pCacheObj
)
{
static
pthread_t
doRegisterCacheObj
(
SCacheObj
*
pCacheObj
)
{
pthread_once
(
&
cacheThreadInit
,
doInitRefreshThread
);
pthread_mutex_lock
(
&
guard
);
...
...
@@ -184,7 +184,7 @@ static FORCE_INLINE void doDestroyTrashcanElem(SCacheObj* pCacheObj, STrashElem
}
SCacheObj
*
taosCacheInit
(
int32_t
keyType
,
int64_t
refreshTimeInSeconds
,
bool
extendLifespan
,
__cache_free_fn_t
fn
,
const
char
*
cacheName
)
{
const
int32_t
SLEEP_DURATION
=
500
;
//500 ms
const
int32_t
SLEEP_DURATION
_IN_MS
=
500
;
if
(
refreshTimeInSeconds
<=
0
)
{
return
NULL
;
...
...
@@ -197,21 +197,29 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
}
pCacheObj
->
pHashTable
=
taosHashInit
(
4096
,
taosGetDefaultHashFunction
(
keyType
),
false
,
HASH_ENTRY_LOCK
);
pCacheObj
->
name
=
strdup
(
cacheName
);
if
(
pCacheObj
->
pHashTable
==
NULL
)
{
free
(
pCacheObj
);
uError
(
"failed to allocate memory, reason:%s"
,
strerror
(
errno
));
return
NULL
;
}
pCacheObj
->
name
=
strdup
(
cacheName
);
if
(
pCacheObj
->
name
==
NULL
)
{
taosHashCleanup
(
pCacheObj
->
pHashTable
);
free
(
pCacheObj
);
uError
(
"failed to allocate memory, reason:%s"
,
strerror
(
errno
));
return
NULL
;
}
// set free cache node callback function
pCacheObj
->
freeFp
=
fn
;
pCacheObj
->
refreshTime
=
refreshTimeInSeconds
*
1000
;
pCacheObj
->
checkTick
=
pCacheObj
->
refreshTime
/
SLEEP_DURATION
;
pCacheObj
->
checkTick
=
pCacheObj
->
refreshTime
/
SLEEP_DURATION
_IN_MS
;
pCacheObj
->
extendLifespan
=
extendLifespan
;
// the TTL after the last access
if
(
__cache_lock_init
(
pCacheObj
)
!=
0
)
{
taosHashCleanup
(
pCacheObj
->
pHashTable
);
free
(
pCacheObj
->
name
);
free
(
pCacheObj
);
uError
(
"failed to init lock, reason:%s"
,
strerror
(
errno
));
...
...
@@ -694,12 +702,12 @@ void* taosCacheTimedRefresh(void *handle) {
setThreadName
(
"cacheRefresh"
);
const
int32_t
SLEEP_DURATION
=
500
;
//500 ms
const
int32_t
SLEEP_DURATION
_IN_MS
=
500
;
int64_t
count
=
0
;
atexit
(
taosCacheRefreshWorkerUnexpectedStopped
);
while
(
1
)
{
taosMsleep
(
SLEEP_DURATION
);
taosMsleep
(
SLEEP_DURATION
_IN_MS
);
if
(
stopRefreshWorker
)
{
goto
_end
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录