fix: conev add/del race

This commit is contained in:
ruti 2024-05-04 18:58:23 +03:00
parent 325d96ec15
commit 1a1bc7d96f
3 changed files with 14 additions and 4 deletions

15
conev.c
View File

@ -14,6 +14,7 @@ struct poolhd *init_pool(int count)
}
pool->max = count;
pool->count = 0;
pool->init_count = 0;
pool->iters = 0;
#ifndef NOEPOLL
@ -51,12 +52,17 @@ struct eval *add_event(struct poolhd *pool, enum eid type,
return 0;
}
val = pool->links[c];
} while (c && val->del_iter == pool->iters);
} while (c < pool->init_count && val->del_iter == pool->iters);
if (c != pool->count) {
struct eval *t = pool->links[c];
pool->links[c] = pool->links[pool->count];
pool->links[pool->count] = t;
}
memset(val, 0, sizeof(*val));
val->fd = fd;
val->index = c;
val->index = pool->count;
val->type = type;
#ifndef NOEPOLL
@ -68,7 +74,7 @@ struct eval *add_event(struct poolhd *pool, enum eid type,
}
val->events = ev.events;
#else
struct pollfd *pfd = &(pool->pevents[c]);
struct pollfd *pfd = &(pool->pevents[pool->count]);
pfd->fd = fd;
pfd->events = POLLIN | e;
@ -76,6 +82,9 @@ struct eval *add_event(struct poolhd *pool, enum eid type,
#endif
pool->count++;
if (pool->count > pool->init_count) {
pool->init_count = pool->count;
}
return val;
}

View File

@ -85,6 +85,7 @@ struct eval {
struct poolhd {
int max;
int init_count;
int count;
int efd;
struct eval **links;

View File

@ -807,7 +807,7 @@ int event_loop(int srvfd)
uniperror("(e)poll");
break;
}
LOG(LOG_L, "new event: fd: %d, evt: %s\n", val->fd, eid_name[val->type]);
LOG(LOG_L, "new event: fd: %d, evt: %s, del_iter: %d\n", val->fd, eid_name[val->type], val->del_iter);
if (val->del_iter) {
continue;