Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
02925dd9
R
redis
项目概览
别团等shy哥发育
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
02925dd9
编写于
9月 13, 2011
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bio.o added to redis-server objects
上级
d1ec6c8b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
114 addition
and
1 deletion
+114
-1
src/Makefile
src/Makefile
+1
-1
src/bio.c
src/bio.c
+107
-0
src/bio.h
src/bio.h
+6
-0
未找到文件。
src/Makefile
浏览文件 @
02925dd9
...
...
@@ -61,7 +61,7 @@ QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR
QUIET_LINK
=
@printf
' %b %b\n'
$(LINKCOLOR)
LINK
$(ENDCOLOR)
$(BINCOLOR)$@$(ENDCOLOR)
;
endif
OBJ
=
adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endian.o slowlog.o scripting.o
OBJ
=
adlist.o ae.o anet.o dict.o redis.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endian.o slowlog.o scripting.o
bio.o
BENCHOBJ
=
ae.o anet.o redis-benchmark.o sds.o adlist.o zmalloc.o
CLIOBJ
=
anet.o sds.o adlist.o redis-cli.o zmalloc.o release.o
CHECKDUMPOBJ
=
redis-check-dump.o lzf_c.o lzf_d.o
...
...
src/bio.c
0 → 100644
浏览文件 @
02925dd9
/* Background I/O service for Redis.
*
* This file implements operations that we need to perform in the background.
* Currently there is only a single operation, that is a background close(2)
* system call. This is needed as when the process is the last owner of a
* reference to a file closing it means unlinking it, and the deletion of the
* file is slow, blocking the server.
*
* In the future we'll either continue implementing new things we need or
* we'll switch to libeio. However there are probably long term uses for this
* file as we may want to put here Redis specific background tasks (for instance
* it is not impossible that we'll need a non blocking FLUSHDB/FLUSHALL
* implementation).
*
* DESIGN
* ------
*
* The design is trivial, we have a structure representing a job to perform
* and a single thread performing all the I/O operations in the queue.
* Currently there is no way for the creator of the job to be notified about
* the completion of the operation, this will only be added when/if needed.
*/
#include "redis.h"
#include "bio.h"
static
pthread_mutex_t
bio_mutex
;
static
pthread_cond_t
bio_condvar
;
list
*
bio_jobs
;
/* This structure represents a background Job. It is only used locally to this
* file as the API deos not expose the internals at all. */
struct
bio_job
{
int
type
;
/* Job type, for instance BIO_JOB_CLOSE */
void
*
data
;
/* Job specific arguments pointer. */
}
void
*
bioProcessBackgroundJobs
(
void
*
arg
);
/* Initialize the background system, spawning the thread. */
void
bioInit
(
void
)
{
pthread_attr_t
attr
;
pthread_t
thread
;
size_t
stacksize
;
pthread_mutex_init
(
bio_mutex
,
NULL
);
pthread_cond_init
(
bio_condvar
,
NULL
);
bio_jobs
=
listCreate
();
/* Set the stack size as by default it may be small in some system */
pthread_attr_init
(
&
attr
);
pthread_attr_getstacksize
(
&
attr
);
if
(
!
stacksize
)
stacksize
=
1
;
/* The world is full of Solaris Fixes */
while
(
stacksize
<
REDIS_THREAD_STACK_SIZE
)
stacksize
*=
2
;
pthread_attr_setstacksize
(
&
attr
,
stacksize
);
/* Ready to spawn our thread */
if
(
pthread_create
(
&
thread
,
&
attr
,
bioProcessBackgroundJobs
,
NULL
)
!=
0
)
{
redisLog
(
REDIS_WARNING
,
"Fatal: Can't initialize Background Jobs."
);
exit
(
1
);
}
}
void
bioCreateBackgroundJob
(
int
type
,
void
*
data
)
{
struct
bio_job
*
job
=
zmalloc
(
sizeof
(
*
job
));
job
->
type
=
type
;
job
->
data
=
data
;
pthread_mutex_lock
(
&
bio_mutex
);
listAddNodeTail
(
bio_jobs
,
job
);
pthread_mutex_unlock
(
&
bio_mutex
);
}
void
*
bioProcessBackgroundJobs
(
void
*
arg
)
{
struct
bio_job
*
job
;
pthread_detach
(
pthread_self
());
pthread_mutex_lock
(
&
bio_mutex
);
while
(
1
)
{
listNode
*
ln
;
/* The loop always starts with the lock hold. */
if
(
listLength
(
server
.
io_newjobs
)
==
0
)
{
pthread_cond_wait
(
&
bio_condvar
,
&
bio_mutex
);
continue
;
}
/* Pop the job from the queue. */
ln
=
listFirst
(
bio_jobs
);
job
=
ln
->
value
;
listDelNode
(
bio_jobs
,
ln
);
/* It is now possible to unlock the background system as we know have
* a stand alone job structure to process.*/
pthread_mutex_unlock
(
&
bio_mutex
);
/* Process the job accordingly to its type. */
if
(
job
->
type
==
REDIS_BIO_CLOSE_FILE
)
{
close
((
long
)
job
->
data
);
}
else
{
redisPanic
(
"Wrong job type in bioProcessBackgroundJobs()."
);
}
zfree
(
job
);
/* Lock again before reiterating the loop, if there are no longer
* jobs to process we'll block again in pthread_cond_wait(). */
pthread_mutex_lock
(
&
bio_mutex
);
}
}
src/bio.h
0 → 100644
浏览文件 @
02925dd9
/* Exported API */
void
bioInit
(
void
);
void
bioCreateBackgroundJob
(
int
type
,
void
*
data
);
/* Background job opcodes */
#define REDIS_BIO_CLOSE_FILE 1
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录