Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿啄debugIT
libfastcommon
提交
f296a3e4
L
libfastcommon
项目概览
阿啄debugIT
/
libfastcommon
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libfastcommon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f296a3e4
编写于
6月 19, 2015
作者:
Y
yuqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fast_mblock add fast_mblock_delay_free
上级
7a2c9428
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
109 addition
and
5 deletion
+109
-5
HISTORY
HISTORY
+3
-0
libfastcommon.spec
libfastcommon.spec
+1
-1
src/fast_mblock.c
src/fast_mblock.c
+64
-3
src/fast_mblock.h
src/fast_mblock.h
+41
-1
未找到文件。
HISTORY
浏览文件 @
f296a3e4
Version 1.16 2015-06-19
* fast_mblock add fast_mblock_delay_free
Version 1.15 2015-06-16
* fast_mblock.c support none lock
* ioevent support set timeout
...
...
libfastcommon.spec
浏览文件 @
f296a3e4
Name: libfastcommon
Version: 1.0.1
5
Version: 1.0.1
6
Release: 1%{?dist}
Summary: c common functions library extracted from my open source projects FastDFS
License: GPL
...
...
src/fast_mblock.c
浏览文件 @
f296a3e4
...
...
@@ -8,6 +8,7 @@
#include "logger.h"
#include "shared_func.h"
#include "pthread_func.h"
#include "sched_thread.h"
int
fast_mblock_init_ex
(
struct
fast_mblock_man
*
mblock
,
const
int
element_size
,
const
int
alloc_elements_once
,
fast_mblock_alloc_init_func
init_func
,
...
...
@@ -47,6 +48,8 @@ int fast_mblock_init_ex(struct fast_mblock_man *mblock, const int element_size,
mblock
->
alloc_init_func
=
init_func
;
mblock
->
malloc_chain_head
=
NULL
;
mblock
->
free_chain_head
=
NULL
;
mblock
->
delay_free_chain
.
head
=
NULL
;
mblock
->
delay_free_chain
.
tail
=
NULL
;
mblock
->
total_count
=
0
;
mblock
->
need_lock
=
need_lock
;
...
...
@@ -165,7 +168,17 @@ struct fast_mblock_node *fast_mblock_alloc(struct fast_mblock_man *mblock)
}
else
{
if
((
result
=
fast_mblock_prealloc
(
mblock
))
==
0
)
if
(
mblock
->
delay_free_chain
.
head
!=
NULL
&&
mblock
->
delay_free_chain
.
head
->
recycle_timestamp
<=
get_current_time
())
{
pNode
=
mblock
->
delay_free_chain
.
head
;
mblock
->
delay_free_chain
.
head
=
pNode
->
next
;
if
(
mblock
->
delay_free_chain
.
tail
==
pNode
)
{
mblock
->
delay_free_chain
.
tail
=
NULL
;
}
}
else
if
((
result
=
fast_mblock_prealloc
(
mblock
))
==
0
)
{
pNode
=
mblock
->
free_chain_head
;
mblock
->
free_chain_head
=
pNode
->
next
;
...
...
@@ -215,7 +228,45 @@ int fast_mblock_free(struct fast_mblock_man *mblock, \
return
0
;
}
int
fast_mblock_free_count
(
struct
fast_mblock_man
*
mblock
)
int
fast_mblock_delay_free
(
struct
fast_mblock_man
*
mblock
,
struct
fast_mblock_node
*
pNode
,
const
int
deley
)
{
int
result
;
if
(
mblock
->
need_lock
&&
(
result
=
pthread_mutex_lock
(
&
(
mblock
->
lock
)))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
\
"call pthread_mutex_lock fail, "
\
"errno: %d, error info: %s"
,
\
__LINE__
,
result
,
STRERROR
(
result
));
return
result
;
}
pNode
->
recycle_timestamp
=
get_current_time
()
+
deley
;
if
(
mblock
->
delay_free_chain
.
head
==
NULL
)
{
mblock
->
delay_free_chain
.
head
=
pNode
;
}
else
{
mblock
->
delay_free_chain
.
tail
->
next
=
pNode
;
}
mblock
->
delay_free_chain
.
tail
=
pNode
;
pNode
->
next
=
NULL
;
if
(
mblock
->
need_lock
&&
(
result
=
pthread_mutex_unlock
(
&
(
mblock
->
lock
)))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
\
"call pthread_mutex_unlock fail, "
\
"errno: %d, error info: %s"
,
\
__LINE__
,
result
,
STRERROR
(
result
));
}
return
0
;
}
static
int
fast_mblock_chain_count
(
struct
fast_mblock_man
*
mblock
,
struct
fast_mblock_node
*
head
)
{
struct
fast_mblock_node
*
pNode
;
int
count
;
...
...
@@ -231,7 +282,7 @@ int fast_mblock_free_count(struct fast_mblock_man *mblock)
}
count
=
0
;
pNode
=
mblock
->
free_chain_
head
;
pNode
=
head
;
while
(
pNode
!=
NULL
)
{
pNode
=
pNode
->
next
;
...
...
@@ -249,3 +300,13 @@ int fast_mblock_free_count(struct fast_mblock_man *mblock)
return
count
;
}
int
fast_mblock_free_count
(
struct
fast_mblock_man
*
mblock
)
{
return
fast_mblock_chain_count
(
mblock
,
mblock
->
free_chain_head
);
}
int
fast_mblock_delay_free_count
(
struct
fast_mblock_man
*
mblock
)
{
return
fast_mblock_chain_count
(
mblock
,
mblock
->
delay_free_chain
.
head
);
}
src/fast_mblock.h
浏览文件 @
f296a3e4
...
...
@@ -22,6 +22,7 @@
struct
fast_mblock_node
{
struct
fast_mblock_node
*
next
;
int
recycle_timestamp
;
char
data
[
0
];
//the data buffer
};
...
...
@@ -31,11 +32,17 @@ struct fast_mblock_malloc
struct
fast_mblock_malloc
*
next
;
};
struct
fast_mblock_chain
{
struct
fast_mblock_node
*
head
;
struct
fast_mblock_node
*
tail
;
};
typedef
int
(
*
fast_mblock_alloc_init_func
)(
void
*
element
);
struct
fast_mblock_man
{
struct
fast_mblock_node
*
free_chain_head
;
//free node chain
struct
fast_mblock_node
*
free_chain_head
;
//free node chain
struct
fast_mblock_chain
delay_free_chain
;
//delay free node chain
struct
fast_mblock_malloc
*
malloc_chain_head
;
//malloc chain to be freed
fast_mblock_alloc_init_func
alloc_init_func
;
int
element_size
;
//element size
...
...
@@ -93,6 +100,17 @@ return 0 for success, return none zero if fail
int
fast_mblock_free
(
struct
fast_mblock_man
*
mblock
,
struct
fast_mblock_node
*
pNode
);
/**
delay free a node (put a node to the mblock)
parameters:
mblock: the mblock pointer
pNode: the node to free
delay: delay seconds to free
return 0 for success, return none zero if fail
*/
int
fast_mblock_delay_free
(
struct
fast_mblock_man
*
mblock
,
struct
fast_mblock_node
*
pNode
,
const
int
delay
);
/**
alloc a object from the mblock
parameters:
...
...
@@ -123,6 +141,20 @@ static inline int fast_mblock_free_object(struct fast_mblock_man *mblock,
return
fast_mblock_free
(
mblock
,
fast_mblock_to_node_ptr
(
object
));
}
/**
delay free a object (put a node to the mblock)
parameters:
mblock: the mblock pointer
pNode: the node to free
delay: delay seconds to free
return 0 for success, return none zero if fail
*/
int
fast_mblock_delay_free_object
(
struct
fast_mblock_man
*
mblock
,
void
*
object
,
const
int
delay
)
{
return
fast_mblock_delay_free
(
mblock
,
fast_mblock_to_node_ptr
(
object
),
delay
);
}
/**
get node count of the mblock
parameters:
...
...
@@ -131,6 +163,14 @@ return the free node count of the mblock, return -1 if fail
*/
int
fast_mblock_free_count
(
struct
fast_mblock_man
*
mblock
);
/**
get delay free node count of the mblock
parameters:
mblock: the mblock pointer
return the delay free node count of the mblock, return -1 if fail
*/
int
fast_mblock_delay_free_count
(
struct
fast_mblock_man
*
mblock
);
#define fast_mblock_total_count(mblock) (mblock)->total_count
#ifdef __cplusplus
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录