Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
RT-Thread
rt-thread
提交
2aa1056f
R
rt-thread
项目概览
RT-Thread
/
rt-thread
大约 1 年 前同步成功
通知
778
Star
8912
Fork
4736
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2aa1056f
编写于
8月 03, 2023
作者:
Z
zmq810150896
提交者:
GitHub
8月 03, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add fops for dfs_v2 and rt_set_errno (#7910)
上级
325c3d2a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
68 addition
and
36 deletion
+68
-36
components/libc/posix/io/epoll/epoll.c
components/libc/posix/io/epoll/epoll.c
+46
-21
components/libc/posix/io/eventfd/eventfd.c
components/libc/posix/io/eventfd/eventfd.c
+22
-15
未找到文件。
components/libc/posix/io/epoll/epoll.c
浏览文件 @
2aa1056f
...
...
@@ -164,7 +164,7 @@ static int epoll_poll(struct dfs_file *file, struct rt_pollreq *req)
fdlist
=
fdlist
->
next
;
mask
=
epoll_get_event
(
fdlist
,
&
fdlist
->
req
);
if
(
mask
&
fdlist
->
epev
.
events
)
if
(
mask
&
fdlist
->
r
events
)
{
events
|=
mask
|
POLLIN
|
EPOLLRDNORM
;
break
;
...
...
@@ -221,7 +221,7 @@ static int epoll_rdlist_add(struct rt_fd_list *fdl, rt_uint32_t revents)
if
(
rdlist
!=
RT_NULL
)
{
rdlist
->
rdl_event
=
fdl
;
rdlist
->
rdl_event
->
epev
.
events
=
fdl
->
epev
.
events
&
revents
;
rdlist
->
rdl_event
->
epev
.
events
=
fdl
->
r
events
&
revents
;
rdlist
->
next
=
ep
->
rdlist
->
next
;
rdlist
->
exclusive
=
0
;
ep
->
rdlist
->
next
=
rdlist
;
...
...
@@ -250,7 +250,7 @@ static int epoll_wqueue_callback(struct rt_wqueue_node *wait, void *key)
fdlist
=
rt_container_of
(
wait
,
struct
rt_fd_list
,
wqn
);
if
(
fdlist
->
epev
.
events
)
if
(
fdlist
->
r
events
)
{
epoll_rdlist_add
(
fdlist
,
(
rt_ubase_t
)
key
);
}
...
...
@@ -279,10 +279,10 @@ static void epoll_ctl_install(struct rt_fd_list *fdlist, struct rt_eventpoll *ep
{
rt_uint32_t
mask
=
0
;
fdlist
->
req
.
_key
=
fdlist
->
epev
.
events
;
fdlist
->
req
.
_key
=
fdlist
->
r
events
;
mask
=
epoll_get_event
(
fdlist
,
&
fdlist
->
req
);
if
(
mask
&
fdlist
->
epev
.
events
)
if
(
mask
&
fdlist
->
r
events
)
{
epoll_rdlist_add
(
fdlist
,
mask
);
}
...
...
@@ -317,6 +317,10 @@ static int epoll_epf_init(int fd)
rt_mutex_init
(
&
ep
->
lock
,
EPOLL_MUTEX_NAME
,
RT_IPC_FLAG_FIFO
);
#ifdef RT_USING_DFS_V2
df
->
fops
=
&
epoll_fops
;
#endif
df
->
vnode
=
(
struct
dfs_vnode
*
)
rt_malloc
(
sizeof
(
struct
dfs_vnode
));
if
(
df
->
vnode
)
{
...
...
@@ -353,13 +357,13 @@ static int epoll_epf_init(int fd)
static
int
epoll_do_create
(
int
size
)
{
rt_err_t
ret
=
0
;
rt_err_t
ret
=
-
1
;
int
status
;
int
fd
;
if
(
size
<
0
)
{
r
et
=
-
EINVAL
;
r
t_set_errno
(
EINVAL
)
;
}
else
{
...
...
@@ -371,12 +375,12 @@ static int epoll_do_create(int size)
if
(
status
<
0
)
{
fd_release
(
fd
);
r
et
=
status
;
r
t_set_errno
(
-
status
)
;
}
}
else
{
r
et
=
fd
;
r
t_set_errno
(
-
fd
)
;
}
}
...
...
@@ -518,23 +522,31 @@ static int epoll_do_ctl(int epfd, int op, int fd, struct epoll_event *event)
{
struct
dfs_file
*
epdf
;
struct
rt_eventpoll
*
ep
;
rt_err_t
ret
=
-
EINVAL
;
rt_err_t
ret
=
0
;
if
(
op
&
~
EFD_SHARED_EPOLL_TYPE
)
return
-
EINVAL
;
{
rt_set_errno
(
EINVAL
);
return
-
1
;
}
if
((
epfd
==
fd
)
||
(
epfd
<
0
)
||
(
fd
<
0
)
||
(
event
->
data
.
fd
!=
fd
))
return
-
EINVAL
;
{
rt_set_errno
(
EINVAL
);
return
-
1
;
}
if
(
!
(
event
->
events
&
EPOLLEXCLUSIVE_BITS
))
return
-
EINVAL
;
{
rt_set_errno
(
EINVAL
);
return
-
1
;
}
epdf
=
fd_get
(
epfd
);
if
(
epdf
->
vnode
->
data
)
{
ep
=
epdf
->
vnode
->
data
;
ret
=
0
;
rt_mutex_take
(
&
ep
->
lock
,
RT_WAITING_FOREVER
);
...
...
@@ -550,12 +562,18 @@ static int epoll_do_ctl(int epfd, int op, int fd, struct epoll_event *event)
ret
=
epoll_ctl_mod
(
epdf
,
event
);
break
;
default:
r
et
=
-
EINVAL
;
r
t_set_errno
(
EINVAL
)
;
break
;
}
}
rt_mutex_release
(
&
ep
->
lock
);
if
(
ret
<
0
)
{
rt_set_errno
(
-
ret
);
ret
=
-
1
;
}
rt_mutex_release
(
&
ep
->
lock
);
}
return
ret
;
}
...
...
@@ -613,13 +631,13 @@ static int epoll_get_event(struct rt_fd_list *fl, rt_pollreq_t *req)
{
if
(
df
->
vnode
->
fops
->
poll
)
{
req
->
_key
=
fl
->
epev
.
events
|
POLLERR
|
POLLHUP
;
req
->
_key
=
fl
->
r
events
|
POLLERR
|
POLLHUP
;
mask
=
df
->
vnode
->
fops
->
poll
(
df
,
req
);
if
(
mask
<
0
)
return
mask
;
}
mask
&=
fl
->
epev
.
events
|
EPOLLOUT
|
POLLERR
;
mask
&=
fl
->
r
events
|
EPOLLOUT
|
POLLERR
;
}
}
...
...
@@ -659,7 +677,8 @@ static int epoll_do(struct rt_eventpoll *ep, struct epoll_event *events, int max
if
(
rdlist
->
rdl_event
->
revents
&
EPOLLET
)
{
rt_wqueue_remove
(
&
rdlist
->
rdl_event
->
wqn
);
epoll_get_event
(
rdlist
->
rdl_event
,
&
rdlist
->
rdl_event
->
req
);
mask
=
epoll_get_event
(
rdlist
->
rdl_event
,
&
rdlist
->
rdl_event
->
req
);
rdlist
->
rdl_event
->
epev
.
events
=
mask
&
rdlist
->
rdl_event
->
revents
;
isfree
=
1
;
}
else
...
...
@@ -729,7 +748,7 @@ static int epoll_do_wait(int epfd, struct epoll_event *events, int maxevents, in
struct
rt_eventpoll
*
ep
;
struct
dfs_file
*
df
;
lwp_sigset_t
old_sig
,
new_sig
;
rt_err_t
ret
=
-
EINVAL
;
rt_err_t
ret
=
0
;
if
(
ss
)
{
...
...
@@ -755,6 +774,12 @@ static int epoll_do_wait(int epfd, struct epoll_event *events, int maxevents, in
lwp_thread_signal_mask
(
rt_thread_self
(),
LWP_SIG_MASK_CMD_SET_MASK
,
&
old_sig
,
RT_NULL
);
}
if
(
ret
<
0
)
{
rt_set_errno
(
-
ret
);
ret
=
-
1
;
}
return
ret
;
}
...
...
components/libc/posix/io/eventfd/eventfd.c
浏览文件 @
2aa1056f
...
...
@@ -40,13 +40,13 @@ struct eventfd_ctx
#ifndef RT_USING_DFS_V2
static
int
eventfd_close
(
struct
dfs_file
*
file
);
static
int
eventfd_poll
(
struct
dfs_file
*
file
,
struct
rt_pollreq
*
req
);
static
in
t
eventfd_read
(
struct
dfs_file
*
file
,
void
*
buf
,
size_t
count
);
static
in
t
eventfd_write
(
struct
dfs_file
*
file
,
const
void
*
buf
,
size_t
count
);
static
ssize_
t
eventfd_read
(
struct
dfs_file
*
file
,
void
*
buf
,
size_t
count
);
static
ssize_
t
eventfd_write
(
struct
dfs_file
*
file
,
const
void
*
buf
,
size_t
count
);
#else
static
int
eventfd_close
(
struct
dfs_file
*
file
);
static
int
eventfd_poll
(
struct
dfs_file
*
file
,
struct
rt_pollreq
*
req
);
static
in
t
eventfd_read
(
struct
dfs_file
*
file
,
void
*
buf
,
size_t
count
,
off_t
*
pos
);
static
in
t
eventfd_write
(
struct
dfs_file
*
file
,
const
void
*
buf
,
size_t
count
,
off_t
*
pos
);
static
ssize_
t
eventfd_read
(
struct
dfs_file
*
file
,
void
*
buf
,
size_t
count
,
off_t
*
pos
);
static
ssize_
t
eventfd_write
(
struct
dfs_file
*
file
,
const
void
*
buf
,
size_t
count
,
off_t
*
pos
);
#endif
static
const
struct
dfs_file_ops
eventfd_fops
=
...
...
@@ -76,7 +76,6 @@ static int eventfd_poll(struct dfs_file *file, struct rt_pollreq *req)
count
=
ctx
->
count
;
rt_poll_add
(
&
ctx
->
reader_queue
,
req
);
rt_poll_add
(
&
ctx
->
writer_queue
,
req
);
if
(
count
>
0
)
events
|=
POLLIN
;
...
...
@@ -91,9 +90,9 @@ static int eventfd_poll(struct dfs_file *file, struct rt_pollreq *req)
}
#ifndef RT_USING_DFS_V2
static
in
t
eventfd_read
(
struct
dfs_file
*
file
,
void
*
buf
,
size_t
count
)
static
ssize_
t
eventfd_read
(
struct
dfs_file
*
file
,
void
*
buf
,
size_t
count
)
#else
static
in
t
eventfd_read
(
struct
dfs_file
*
file
,
void
*
buf
,
size_t
count
,
off_t
*
pos
)
static
ssize_
t
eventfd_read
(
struct
dfs_file
*
file
,
void
*
buf
,
size_t
count
,
off_t
*
pos
)
#endif
{
struct
eventfd_ctx
*
ctx
=
(
struct
eventfd_ctx
*
)
file
->
vnode
->
data
;
...
...
@@ -107,7 +106,7 @@ static int eventfd_read(struct dfs_file *file, void *buf, size_t count, off_t *p
rt_mutex_take
(
&
ctx
->
lock
,
RT_WAITING_FOREVER
);
if
(
ctx
->
count
=
=
0
)
if
(
ctx
->
count
<
=
0
)
{
if
(
file
->
flags
&
O_NONBLOCK
)
{
...
...
@@ -135,7 +134,6 @@ static int eventfd_read(struct dfs_file *file, void *buf, size_t count, off_t *p
}
ctx
->
count
-=
counter_num
;
(
*
buffer
)
=
counter_num
;
rt_mutex_release
(
&
ctx
->
lock
);
...
...
@@ -144,9 +142,9 @@ static int eventfd_read(struct dfs_file *file, void *buf, size_t count, off_t *p
}
#ifndef RT_USING_DFS_V2
static
in
t
eventfd_write
(
struct
dfs_file
*
file
,
const
void
*
buf
,
size_t
count
)
static
ssize_
t
eventfd_write
(
struct
dfs_file
*
file
,
const
void
*
buf
,
size_t
count
)
#else
static
in
t
eventfd_write
(
struct
dfs_file
*
file
,
const
void
*
buf
,
size_t
count
,
off_t
*
pos
)
static
ssize_
t
eventfd_write
(
struct
dfs_file
*
file
,
const
void
*
buf
,
size_t
count
,
off_t
*
pos
)
#endif
{
struct
eventfd_ctx
*
ctx
=
(
struct
eventfd_ctx
*
)
file
->
vnode
->
data
;
...
...
@@ -182,7 +180,6 @@ static int eventfd_write(struct dfs_file *file, const void *buf, size_t count, o
/* Release the mutex to avoid a deadlock */
rt_mutex_release
(
&
ctx
->
lock
);
rt_wqueue_wait
(
&
ctx
->
writer_queue
,
0
,
RT_WAITING_FOREVER
);
rt_wqueue_wakeup
(
&
ctx
->
reader_queue
,
(
void
*
)
POLLIN
);
rt_mutex_take
(
&
ctx
->
lock
,
RT_WAITING_FOREVER
);
}
}
...
...
@@ -232,6 +229,11 @@ static int rt_eventfd_create(struct dfs_file *df, unsigned int count, int flags)
rt_free
(
ctx
);
ret
=
-
ENOMEM
;
}
#ifdef RT_USING_DFS_V2
df
->
fops
=
&
eventfd_fops
;
#endif
}
return
ret
;
...
...
@@ -245,7 +247,10 @@ static int do_eventfd(unsigned int count, int flags)
rt_ssize_t
ret
=
0
;
if
(
flags
&
~
EFD_FLAGS_SET
)
return
-
RT_EINVAL
;
{
rt_set_errno
(
EINVAL
);
return
-
1
;
}
fd
=
fd_new
();
if
(
fd
>=
0
)
...
...
@@ -257,12 +262,14 @@ static int do_eventfd(unsigned int count, int flags)
if
(
status
<
0
)
{
fd_release
(
fd
);
ret
=
status
;
rt_set_errno
(
-
status
);
ret
=
-
1
;
}
}
else
{
ret
=
fd
;
rt_set_errno
(
-
fd
);
ret
=
-
1
;
}
return
ret
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录