Esempio n. 1
0
File: lwan.c Progetto: lpereira/lwan
static ALWAYS_INLINE unsigned int schedule_client(struct lwan *l, int fd)
{
    struct lwan_thread *thread = l->conns[fd].thread;

    lwan_thread_add_client(thread, fd);

    return (unsigned int)(thread - l->thread.threads);
}
Esempio n. 2
0
static ALWAYS_INLINE void
schedule_client(lwan_t *l, int fd)
{
    int thread;
#ifdef __x86_64__
    static_assert(sizeof(lwan_connection_t) == 32,
                                        "Two connections per cache line");
    /* Since lwan_connection_t is guaranteed to be 32-byte long, two of them
     * can fill up a cache line.  This formula will group two connections
     * per thread in a way that false-sharing is avoided.  This gives wrong
     * results when fd=0, but this shouldn't happen (as 0 is either the
     * standard input or the main socket, but even if that changes,
     * scheduling will still work).  */
    thread = ((fd - 1) / 2) % l->thread.count;
#else
    static int counter = 0;
    thread = counter++ % l->thread.count;
#endif
    lwan_thread_t *t = &l->thread.threads[thread];
    lwan_thread_add_client(t, fd);
}