ext/sleepy_penguin/kqueue.c in sleepy_penguin-3.2.0 vs ext/sleepy_penguin/kqueue.c in sleepy_penguin-3.3.0
- old
+ new
@@ -3,10 +3,11 @@
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
+#include "missing_clock_gettime.h"
#include "missing_rb_thread_fd_close.h"
#include "missing_rb_update_max_fd.h"
#include "value2timespec.h"
#ifdef HAVE_SYS_MOUNT_H /* for VQ_* flags on FreeBSD */
@@ -71,35 +72,22 @@
return 1;
}
static struct kq_per_thread *kpt_get(VALUE self, int nchanges, int nevents)
{
- static __thread struct kq_per_thread *kpt;
+ struct kq_per_thread *kpt;
size_t size;
- void *ptr;
- int err;
int max = nchanges > nevents ? nchanges : nevents;
/* error check here to prevent OOM from posix_memalign */
if (max < 0) {
errno = EINVAL;
rb_sys_fail("kevent got negative events < 0");
}
- if (kpt && kpt->capa >= max)
- goto out;
-
size = sizeof(struct kq_per_thread) + sizeof(struct kevent) * max;
-
- free(kpt); /* free(NULL) is POSIX */
- err = posix_memalign(&ptr, rb_sp_l1_cache_line_size, size);
- if (err) {
- errno = err;
- rb_memerror();
- }
- kpt = ptr;
+ kpt = rb_sp_gettlsbuf(&size);
kpt->capa = max;
-out:
kpt->nchanges = nchanges;
kpt->nevents = nevents;
kpt->io = self;
kpt->fd = rb_sp_fileno(kpt->io);