Changeset cd1ab55918856e8682710ede8ef2e44377887173

Show
Ignore:
Timestamp:
12/03/07 04:32:21 (7 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1196656341 +0000
git-parent:

[01751d3c6a2df6acc30c50e9cd1cce9064262450]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1196656341 +0000
Message:

more work on the kqueue stuff

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/eventer/eventer_kqueue_impl.c

    r01751d3 rcd1ab55  
    66#include "noit_defines.h" 
    77#include "eventer/eventer.h" 
     8#include "utils/noit_atomic.h" 
    89 
    910#include <sys/event.h> 
     11#include <pthread.h> 
     12 
     13int maxfds; 
     14struct { 
     15  eventer_t e; 
     16  pthread_t executor; 
     17  noit_spinlock_t lock; 
     18} **master_fds; 
     19 
     20int kqueue_fd; 
     21typedef struct kqueue_setup { 
     22  struct kevent *__ke_vec; 
     23  unsigned int __ke_vec_a; 
     24  unsigned int __ke_vec_used; 
     25} * kqs_t; 
     26 
     27static pthread_mutex_t kqs_lock; 
     28static kqs_t master_kqs = NULL; 
     29static pthread_key_t kqueue_setup_key; 
     30#define KQUEUE_DECL kqs_t kqs 
     31#define KQUEUE_SETUP kqs = (kqs_t) pthread_getspecific(kqueue_setup_key) 
     32#define ke_vec kqs->__ke_vec 
     33#define ke_vec_a kqs->__ke_vec_a 
     34#define ke_vec_used kqs->__ke_vec_used 
     35 
     36static void 
     37ke_change (register int const ident, 
     38           register int const filter, 
     39           register int const flags, 
     40           register void *const udata) { 
     41  enum { initial_alloc = 64 }; 
     42  register struct kevent *kep; 
     43  KQUEUE_DECL; 
     44 
     45  KQUEUE_SETUP; 
     46  if (!ke_vec_a) { 
     47    ke_vec_a = initial_alloc; 
     48    ke_vec = (struct kevent *) malloc(ke_vec_a * sizeof (struct kevent)); 
     49  } 
     50  else if (ke_vec_used == ke_vec_a) { 
     51    ke_vec_a <<= 1; 
     52    ke_vec = (struct kevent *) realloc(ke_vec, 
     53                                       ke_vec_a * sizeof (struct kevent)); 
     54  } 
     55  kep = &ke_vec[ke_vec_used++]; 
     56 
     57  EV_SET(kep, ident, filter, flags, 0, 0, udata); 
     58} 
    1059 
    1160static int eventer_kqueue_impl_init() { 
     61  struct rlimit rlim; 
     62  kqueue_fd = kqueue(); 
     63  if(kqueue_fd == -1) { 
     64    return -1; 
     65  } 
     66  pthread_mutex_init(&kqs_lock, NULL); 
     67  master_kqs = calloc(1, sizeof(*master_kqs)); 
     68  getrlimit(RLIMIT_NOFILE, &rlim); 
     69  maxfds = rlim.rlim_cur; 
     70  master_fds = calloc(maxfds, sizeof(*master_fds)); 
    1271  return 0; 
    1372} 
  • src/noit_config.h.in

    r01751d3 rcd1ab55  
    4646#undef HAVE_TIME_H 
    4747#undef HAVE_SYS_STAT_H 
     48#undef HAVE_LIBKERN_OSATOMIC_H 
    4849#define IFS_CH '/' 
    4950 
  • src/noitd.c

    r01751d3 rcd1ab55  
    1010    exit(-1); 
    1111  } 
    12  
     12  if(eventer_init() == -1) { 
     13    fprintf(stderr, "Cannot init kqueue\n"); 
     14    exit(-1); 
     15  } 
    1316  return 0; 
    1417}