Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6834200d
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看板
提交
6834200d
编写于
2月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mempool
上级
a2829971
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
26 addition
and
26 deletion
+26
-26
include/util/tmempool.h
include/util/tmempool.h
+10
-11
source/util/src/tmempool.c
source/util/src/tmempool.c
+16
-15
未找到文件。
include/util/tmempool.h
浏览文件 @
6834200d
...
@@ -12,25 +12,24 @@
...
@@ -12,25 +12,24 @@
* You should have received a copy of the GNU Affero General Public License
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#ifndef _TD_UTIL_MEMPOOL_H
#ifndef _TD_UTIL_MEMPOOL_H_
#define _TD_UTIL_MEMPOOL_H
#define _TD_UTIL_MEMPOOL_H_
#include "os.h"
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
#endif
#endif
#define mpool_h void *
typedef
void
*
mpool_h
;
mpool_h
taosMemPoolInit
(
int
maxNum
,
int
blockSize
);
mpool_h
taosMemPoolInit
(
int32_t
maxNum
,
int32_t
blockSize
);
char
*
taosMemPoolMalloc
(
mpool_h
handle
);
char
*
taosMemPoolMalloc
(
mpool_h
handle
);
void
taosMemPoolFree
(
mpool_h
handle
,
char
*
p
);
void
taosMemPoolFree
(
mpool_h
handle
,
char
*
p
);
void
taosMemPoolCleanUp
(
mpool_h
handle
);
void
taosMemPoolCleanUp
(
mpool_h
handle
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
#endif
/*_TD_UTIL_MEMPOOL_H*/
#endif
/*_TD_UTIL_MEMPOOL_H
_
*/
source/util/src/tmempool.c
浏览文件 @
6834200d
...
@@ -13,22 +13,23 @@
...
@@ -13,22 +13,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#
include "tlog.h"
#
define _DEFAULT_SOURCE
#include "tmempool.h"
#include "tmempool.h"
#include "tlog.h"
#include "tutil.h"
#include "tutil.h"
typedef
struct
{
typedef
struct
{
int
numOfFree
;
/* number of free slots */
int
32_t
numOfFree
;
/* number of free slots */
int
first
;
/* the first free slot */
int
32_t
first
;
/* the first free slot */
int
numOfBlock
;
/* the number of blocks */
int
32_t
numOfBlock
;
/* the number of blocks */
int
blockSize
;
/* block size in bytes */
int
32_t
blockSize
;
/* block size in bytes */
int
*
freeList
;
/* the index list */
int
32_t
*
freeList
;
/* the index list */
char
*
pool
;
/* the actual mem block */
char
*
pool
;
/* the actual mem block */
pthread_mutex_t
mutex
;
pthread_mutex_t
mutex
;
}
pool_t
;
}
pool_t
;
mpool_h
taosMemPoolInit
(
int
numOfBlock
,
in
t
blockSize
)
{
mpool_h
taosMemPoolInit
(
int
32_t
numOfBlock
,
int32_
t
blockSize
)
{
int
i
;
int
32_t
i
;
pool_t
*
pool_p
;
pool_t
*
pool_p
;
if
(
numOfBlock
<=
1
||
blockSize
<=
1
)
{
if
(
numOfBlock
<=
1
||
blockSize
<=
1
)
{
...
@@ -47,7 +48,7 @@ mpool_h taosMemPoolInit(int numOfBlock, int blockSize) {
...
@@ -47,7 +48,7 @@ mpool_h taosMemPoolInit(int numOfBlock, int blockSize) {
pool_p
->
blockSize
=
blockSize
;
pool_p
->
blockSize
=
blockSize
;
pool_p
->
numOfBlock
=
numOfBlock
;
pool_p
->
numOfBlock
=
numOfBlock
;
pool_p
->
pool
=
(
char
*
)
malloc
((
size_t
)(
blockSize
*
numOfBlock
));
pool_p
->
pool
=
(
char
*
)
malloc
((
size_t
)(
blockSize
*
numOfBlock
));
pool_p
->
freeList
=
(
int
*
)
malloc
(
sizeof
(
in
t
)
*
(
size_t
)
numOfBlock
);
pool_p
->
freeList
=
(
int
32_t
*
)
malloc
(
sizeof
(
int32_
t
)
*
(
size_t
)
numOfBlock
);
if
(
pool_p
->
pool
==
NULL
||
pool_p
->
freeList
==
NULL
)
{
if
(
pool_p
->
pool
==
NULL
||
pool_p
->
freeList
==
NULL
)
{
uError
(
"failed to allocate memory
\n
"
);
uError
(
"failed to allocate memory
\n
"
);
...
@@ -69,7 +70,7 @@ mpool_h taosMemPoolInit(int numOfBlock, int blockSize) {
...
@@ -69,7 +70,7 @@ mpool_h taosMemPoolInit(int numOfBlock, int blockSize) {
}
}
char
*
taosMemPoolMalloc
(
mpool_h
handle
)
{
char
*
taosMemPoolMalloc
(
mpool_h
handle
)
{
char
*
pos
=
NULL
;
char
*
pos
=
NULL
;
pool_t
*
pool_p
=
(
pool_t
*
)
handle
;
pool_t
*
pool_p
=
(
pool_t
*
)
handle
;
pthread_mutex_lock
(
&
(
pool_p
->
mutex
));
pthread_mutex_lock
(
&
(
pool_p
->
mutex
));
...
@@ -88,20 +89,20 @@ char *taosMemPoolMalloc(mpool_h handle) {
...
@@ -88,20 +89,20 @@ char *taosMemPoolMalloc(mpool_h handle) {
}
}
void
taosMemPoolFree
(
mpool_h
handle
,
char
*
pMem
)
{
void
taosMemPoolFree
(
mpool_h
handle
,
char
*
pMem
)
{
int
index
;
int
32_t
index
;
pool_t
*
pool_p
=
(
pool_t
*
)
handle
;
pool_t
*
pool_p
=
(
pool_t
*
)
handle
;
if
(
pMem
==
NULL
)
return
;
if
(
pMem
==
NULL
)
return
;
index
=
(
int
)(
pMem
-
pool_p
->
pool
)
%
pool_p
->
blockSize
;
index
=
(
int
32_t
)(
pMem
-
pool_p
->
pool
)
%
pool_p
->
blockSize
;
if
(
index
!=
0
)
{
if
(
index
!=
0
)
{
uError
(
"invalid free address:%p
\n
"
,
pMem
);
uError
(
"invalid free address:%p
\n
"
,
pMem
);
return
;
return
;
}
}
index
=
(
int
)((
pMem
-
pool_p
->
pool
)
/
pool_p
->
blockSize
);
index
=
(
int
32_t
)((
pMem
-
pool_p
->
pool
)
/
pool_p
->
blockSize
);
if
(
index
<
0
||
index
>=
pool_p
->
numOfBlock
)
{
if
(
index
<
0
||
index
>=
pool_p
->
numOfBlock
)
{
uError
(
"mempool: error, invalid address:%p
\n
"
,
pMem
);
uError
(
"mempool: error, invalid address:%p"
,
pMem
);
return
;
return
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录