mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-18 19:57:31 +00:00
dm: create mevent's pipe in non-blocking mode
It was designed to be used in non-blocking mode to prevent the mevent thread from blocking itself indefinitely, but it was created in blocking mode. Tracked-On: #2319 Signed-off-by: Peter Fang <peter.fang@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
This commit is contained in:
parent
a9709bf857
commit
d1e1aa3077
@ -35,6 +35,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
@ -96,7 +97,7 @@ static void
|
|||||||
mevent_pipe_read(int fd, enum ev_type type, void *param)
|
mevent_pipe_read(int fd, enum ev_type type, void *param)
|
||||||
{
|
{
|
||||||
char buf[MEVENT_MAX];
|
char buf[MEVENT_MAX];
|
||||||
int status;
|
ssize_t status;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Drain the pipe read side. The fd is non-blocking so this is
|
* Drain the pipe read side. The fd is non-blocking so this is
|
||||||
@ -107,7 +108,7 @@ mevent_pipe_read(int fd, enum ev_type type, void *param)
|
|||||||
} while (status == MEVENT_MAX);
|
} while (status == MEVENT_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*On error, -1 is returned, else return zero*/
|
/* On error, -1 is returned, else return zero */
|
||||||
int
|
int
|
||||||
mevent_notify(void)
|
mevent_notify(void)
|
||||||
{
|
{
|
||||||
@ -247,6 +248,7 @@ mevent_add(int tfd, enum ev_type type,
|
|||||||
ee.events = mevent_kq_filter(mevp);
|
ee.events = mevent_kq_filter(mevp);
|
||||||
ee.data.ptr = mevp;
|
ee.data.ptr = mevp;
|
||||||
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, mevp->me_fd, &ee);
|
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, mevp->me_fd, &ee);
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
mevent_qlock();
|
mevent_qlock();
|
||||||
LIST_INSERT_HEAD(&global_head, mevp, me_list);
|
LIST_INSERT_HEAD(&global_head, mevp, me_list);
|
||||||
@ -408,7 +410,7 @@ mevent_dispatch(void)
|
|||||||
* the blocking kqueue call to exit by writing to it. Set the
|
* the blocking kqueue call to exit by writing to it. Set the
|
||||||
* descriptor to non-blocking.
|
* descriptor to non-blocking.
|
||||||
*/
|
*/
|
||||||
ret = pipe(mevent_pipefd);
|
ret = pipe2(mevent_pipefd, O_NONBLOCK);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
perror("pipe");
|
perror("pipe");
|
||||||
exit(0);
|
exit(0);
|
||||||
@ -427,6 +429,7 @@ mevent_dispatch(void)
|
|||||||
* Block awaiting events
|
* Block awaiting events
|
||||||
*/
|
*/
|
||||||
ret = epoll_wait(epoll_fd, eventlist, MEVENT_MAX, -1);
|
ret = epoll_wait(epoll_fd, eventlist, MEVENT_MAX, -1);
|
||||||
|
|
||||||
if (ret == -1 && errno != EINTR)
|
if (ret == -1 && errno != EINTR)
|
||||||
perror("Error return from epoll_wait");
|
perror("Error return from epoll_wait");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user