Add timeout in kevent.

This commit is contained in:
fengbojiang 2023-04-08 09:29:50 +08:00
parent f27d862f85
commit 8766cedde1
3 changed files with 9 additions and 4 deletions

View File

@ -71,6 +71,7 @@
rte_spinlock_unlock(&sc->lock); \
} while (0)
/* NOTE: deadlock prone while fstack adapter run error */
#define SYSCALL(op, arg) do { \
ACQUIRE_ZONE_LOCK(FF_SC_IDLE); \
sc->ops = (op); \

View File

@ -32,6 +32,8 @@ struct kevent events[MAX_EVENTS];
int kq;
int sockfd;
struct timespec timeout = {0, 100000};
static int exit_flag = 0;
char html[] =
@ -77,7 +79,7 @@ void *loop(void *arg)
{
/* Wait for events to happen */
while (!exit_flag) {
int nevents = kevent(kq, NULL, 0, events, MAX_EVENTS, NULL);
int nevents = kevent(kq, NULL, 0, events, MAX_EVENTS, &timeout);
int i;
if (nevents <= 0) {
@ -185,7 +187,7 @@ int main(int argc, char * argv[])
EV_SET(&kevSet, sockfd, EVFILT_READ, EV_ADD, 0, MAX_EVENTS, NULL);
/* Update kqueue */
ret = kevent(kq, &kevSet, 1, NULL, 0, NULL);
ret = kevent(kq, &kevSet, 1, NULL, 0, &timeout);
if (ret < 0) {
printf("kevent failed\n");
close(kq);

View File

@ -25,6 +25,8 @@ pthread_t hworker[MAX_WORKERS];
pthread_spinlock_t worker_lock;
#define MAX_EVENTS 512
struct timespec timeout = {0, 100000};
static int exit_flag = 0;
char html[] =
@ -126,7 +128,7 @@ void *loop(void *arg)
EV_SET(&kevSet, sockfd, EVFILT_READ, EV_ADD, 0, MAX_EVENTS, NULL);
/* Update kqueue */
ret = kevent(kq, &kevSet, 1, NULL, 0, NULL);
ret = kevent(kq, &kevSet, 1, NULL, 0, &timeout);
if (ret < 0) {
printf("thread %d, kevent failed\n", thread_id);
close(kq);
@ -136,7 +138,7 @@ void *loop(void *arg)
/* Wait for events to happen */
while (!exit_flag) {
int nevents = kevent(kq, NULL, 0, events, MAX_EVENTS, NULL);
int nevents = kevent(kq, NULL, 0, events, MAX_EVENTS, &timeout);
int i;
if (nevents <= 0) {