Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
qemu
提交
8653c015
Q
qemu
项目概览
openeuler
/
qemu
通知
10
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
qemu
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8653c015
编写于
2月 21, 2009
作者:
M
malc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Error checking
git-svn-id:
svn://svn.savannah.nongnu.org/qemu/trunk@6630
c046a42c-6fe2-441c-8c8c-71466251a162
上级
5518f3a6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
72 addition
and
24 deletion
+72
-24
posix-aio-compat.c
posix-aio-compat.c
+72
-24
未找到文件。
posix-aio-compat.c
浏览文件 @
8653c015
...
...
@@ -15,6 +15,9 @@
#include <unistd.h>
#include <errno.h>
#include <sys/time.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "osdep.h"
#include "posix-aio-compat.h"
...
...
@@ -27,20 +30,64 @@ static int cur_threads = 0;
static
int
idle_threads
=
0
;
static
TAILQ_HEAD
(,
qemu_paiocb
)
request_list
;
static
void
die2
(
int
err
,
const
char
*
what
)
{
fprintf
(
stderr
,
"%s failed: %s
\n
"
,
what
,
strerror
(
err
));
abort
();
}
static
void
die
(
const
char
*
what
)
{
die2
(
errno
,
what
);
}
static
void
mutex_lock
(
pthread_mutex_t
*
mutex
)
{
int
ret
=
pthread_mutex_lock
(
mutex
);
if
(
ret
)
die2
(
ret
,
"pthread_mutex_lock"
);
}
static
void
mutex_unlock
(
pthread_mutex_t
*
mutex
)
{
int
ret
=
pthread_mutex_unlock
(
mutex
);
if
(
ret
)
die2
(
ret
,
"pthread_mutex_unlock"
);
}
static
int
cond_timedwait
(
pthread_cond_t
*
cond
,
pthread_mutex_t
*
mutex
,
struct
timespec
*
ts
)
{
int
ret
=
pthread_cond_timedwait
(
cond
,
mutex
,
ts
);
if
(
ret
&&
ret
!=
ETIMEDOUT
)
die2
(
ret
,
"pthread_cond_timedwait"
);
return
ret
;
}
static
void
cond_broadcast
(
pthread_cond_t
*
cond
)
{
int
ret
=
pthread_cond_broadcast
(
cond
);
if
(
ret
)
die2
(
ret
,
"pthread_cond_broadcast"
);
}
static
void
thread_create
(
pthread_t
*
thread
,
pthread_attr_t
*
attr
,
void
*
(
*
start_routine
)(
void
*
),
void
*
arg
)
{
int
ret
=
pthread_create
(
thread
,
attr
,
start_routine
,
arg
);
if
(
ret
)
die2
(
ret
,
"pthread_create"
);
}
static
void
*
aio_thread
(
void
*
unused
)
{
sigset_t
set
;
/* block all signals */
sigfillset
(
&
set
);
sigprocmask
(
SIG_BLOCK
,
&
set
,
NULL
);
if
(
sigfillset
(
&
set
))
die
(
"sigfillset"
);
if
(
sigprocmask
(
SIG_BLOCK
,
&
set
,
NULL
))
die
(
"sigprocmask"
);
while
(
1
)
{
struct
qemu_paiocb
*
aiocb
;
size_t
offset
;
int
ret
=
0
;
pthread_
mutex_lock
(
&
lock
);
mutex_lock
(
&
lock
);
while
(
TAILQ_EMPTY
(
&
request_list
)
&&
!
(
ret
==
ETIMEDOUT
))
{
...
...
@@ -49,7 +96,7 @@ static void *aio_thread(void *unused)
qemu_gettimeofday
(
&
tv
);
ts
.
tv_sec
=
tv
.
tv_sec
+
10
;
ret
=
pthread_
cond_timedwait
(
&
cond
,
&
lock
,
&
ts
);
ret
=
cond_timedwait
(
&
cond
,
&
lock
,
&
ts
);
}
if
(
ret
==
ETIMEDOUT
)
...
...
@@ -62,7 +109,7 @@ static void *aio_thread(void *unused)
aiocb
->
active
=
1
;
idle_threads
--
;
pthread_
mutex_unlock
(
&
lock
);
mutex_unlock
(
&
lock
);
while
(
offset
<
aiocb
->
aio_nbytes
)
{
ssize_t
len
;
...
...
@@ -89,35 +136,36 @@ static void *aio_thread(void *unused)
offset
+=
len
;
}
pthread_
mutex_lock
(
&
lock
);
mutex_lock
(
&
lock
);
aiocb
->
ret
=
offset
;
idle_threads
++
;
pthread_
mutex_unlock
(
&
lock
);
mutex_unlock
(
&
lock
);
kill
(
getpid
(),
aiocb
->
ev_signo
);
if
(
kill
(
getpid
(),
aiocb
->
ev_signo
))
die
(
"kill failed"
);
}
idle_threads
--
;
cur_threads
--
;
pthread_
mutex_unlock
(
&
lock
);
mutex_unlock
(
&
lock
);
return
NULL
;
}
static
int
spawn_thread
(
void
)
static
void
spawn_thread
(
void
)
{
pthread_attr_t
attr
;
int
ret
;
pthread_attr_t
attr
;
cur_threads
++
;
idle_threads
++
;
pthread_attr_init
(
&
attr
);
pthread_attr_setdetachstate
(
&
attr
,
PTHREAD_CREATE_DETACHED
);
ret
=
pthread_create
(
&
thread_id
,
&
attr
,
aio_thread
,
NULL
);
pthread_attr_destroy
(
&
attr
);
return
ret
;
ret
=
pthread_attr_init
(
&
attr
);
if
(
ret
)
die2
(
ret
,
"pthread_attr_init"
);
ret
=
pthread_attr_setdetachstate
(
&
attr
,
PTHREAD_CREATE_DETACHED
);
if
(
ret
)
die2
(
ret
,
"pthread_attr_setdetachstate"
);
thread_create
(
&
thread_id
,
&
attr
,
aio_thread
,
NULL
);
ret
=
pthread_attr_destroy
(
&
attr
);
if
(
ret
)
die2
(
ret
,
"pthread_attr_destroy"
);
}
int
qemu_paio_init
(
struct
qemu_paioinit
*
aioinit
)
...
...
@@ -132,12 +180,12 @@ static int qemu_paio_submit(struct qemu_paiocb *aiocb, int is_write)
aiocb
->
is_write
=
is_write
;
aiocb
->
ret
=
-
EINPROGRESS
;
aiocb
->
active
=
0
;
pthread_
mutex_lock
(
&
lock
);
mutex_lock
(
&
lock
);
if
(
idle_threads
==
0
&&
cur_threads
<
max_threads
)
spawn_thread
();
TAILQ_INSERT_TAIL
(
&
request_list
,
aiocb
,
node
);
pthread_
mutex_unlock
(
&
lock
);
pthread_
cond_broadcast
(
&
cond
);
mutex_unlock
(
&
lock
);
cond_broadcast
(
&
cond
);
return
0
;
}
...
...
@@ -156,9 +204,9 @@ ssize_t qemu_paio_return(struct qemu_paiocb *aiocb)
{
ssize_t
ret
;
pthread_
mutex_lock
(
&
lock
);
mutex_lock
(
&
lock
);
ret
=
aiocb
->
ret
;
pthread_
mutex_unlock
(
&
lock
);
mutex_unlock
(
&
lock
);
return
ret
;
}
...
...
@@ -179,7 +227,7 @@ int qemu_paio_cancel(int fd, struct qemu_paiocb *aiocb)
{
int
ret
;
pthread_
mutex_lock
(
&
lock
);
mutex_lock
(
&
lock
);
if
(
!
aiocb
->
active
)
{
TAILQ_REMOVE
(
&
request_list
,
aiocb
,
node
);
aiocb
->
ret
=
-
ECANCELED
;
...
...
@@ -188,7 +236,7 @@ int qemu_paio_cancel(int fd, struct qemu_paiocb *aiocb)
ret
=
QEMU_PAIO_NOTCANCELED
;
else
ret
=
QEMU_PAIO_ALLDONE
;
pthread_
mutex_unlock
(
&
lock
);
mutex_unlock
(
&
lock
);
return
ret
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录