pike.git / src / modules / HTTPLoop / timeout.c

version» Context lines:

pike.git/src/modules/HTTPLoop/timeout.c:4:   || for more information.   */      #include "config.h"   #if !defined(__NT__) && !defined(__WIN32__)   #include <global.h>   #include <threads.h>   #include <signal.h>      #ifdef _REENTRANT - #include <stdlib.h> +    #include <errno.h> - #ifdef HAVE_UNISTD_H - #include <unistd.h> - #endif - #include <sys/types.h> +    #ifdef HAVE_SYS_SOCKET_H   #include <sys/socket.h>   #endif   #ifdef HAVE_NETINET_IN_H   #include <netinet/in.h>   #endif   #ifdef HAVE_ARPA_INET_H   #include <arpa/inet.h>   #endif   
pike.git/src/modules/HTTPLoop/timeout.c:37:   #include <poll.h>   #else /* !HAVE_POLL_H */   #ifdef HAVE_SYS_POLL_H   #include <sys/poll.h>   #else /* !HAVE_SYS_POLL_H */   #undef HAVE_POLL   #endif /* HAVE_SYS_POLL_H */   #endif /* HAVE_POLL_H */   #endif /* HAVE_POLL */    + #ifdef AAP_DEBUG + #define DWERROR(...) fprintf(stderr, __VA_ARGS__) + #else + #define DWERROR(...) + #endif    - MUTEX_T aap_timeout_mutex; + static PIKE_MUTEX_T aap_timeout_mutex;      struct timeout   {    int raised;    int when;    struct timeout *next;    THREAD_T thr;   } *first_timeout;         #define FATAL(X) do{fprintf(stderr,"%s:%d: %s",__FILE__,__LINE__,X);abort();}while(0)         #define CHUNK 100 - int num_timeouts; + static int num_timeouts;      static struct timeout *new_timeout(THREAD_T thr, int secs) /* running locked */   { -  struct timeout *t = aap_malloc(sizeof(struct timeout)); +  struct timeout *t = malloc(sizeof(struct timeout));    num_timeouts++;    t->thr = thr;    t->raised = 0;    t->next = NULL;    t->when = aap_get_time()+secs;       if( !first_timeout )    {    first_timeout = t;    }
pike.git/src/modules/HTTPLoop/timeout.c:81:    while( p->next )    p = p->next;    p->next = t;    }    return t;   }      static void free_timeout( struct timeout *t ) /* running locked */   {    num_timeouts--; -  aap_free( t ); +  free( t );   }      int *aap_add_timeout_thr(THREAD_T thr, int secs)   {    struct timeout *to;    mt_lock( &aap_timeout_mutex );    to = new_timeout( thr, secs );    mt_unlock( &aap_timeout_mutex );    return &to->raised;   }
pike.git/src/modules/HTTPLoop/timeout.c:180:    {    t->raised++;    th_kill( t->thr, SIGCHLD );    }    t = t->next;    }    mt_unlock( &aap_timeout_mutex );   #ifdef HAVE_POLL    {    /* MacOS X is stupid, and requires a non-NULL pollfd pointer. */ -  struct pollfd sentinel; -  poll(&sentinel,0,1000); +  struct pollfd sentinel[1]; +  poll(sentinel, 0, 1000);    }   #else    sleep(1);   #endif    }    /*    * Now we're dead...    */ - #ifdef AAP_DEBUG -  fprintf(stderr, "AAP: handle_timeout() is now dead.\n"); - #endif /* AAP_DEBUG */ +  DWERROR("AAP: handle_timeout() is now dead.\n");    return(NULL);   }      static THREAD_T aap_timeout_thread;      void aap_init_timeouts(void)   { - #ifdef AAP_DEBUG -  fprintf(stderr, "AAP: aap_init_timeouts.\n"); - #endif /* AAP_DEBUG */ +  DWERROR("AAP: aap_init_timeouts.\n");    mt_init(&aap_timeout_mutex);    co_init (&aap_timeout_thread_is_dead);    th_create_small(&aap_timeout_thread, handle_timeouts, 0); - #ifdef AAP_DEBUG -  fprintf(stderr, "AAP: handle_timeouts started.\n"); - #endif /* AAP_DEBUG */ +  DWERROR("AAP: handle_timeouts started.\n");   }      void aap_exit_timeouts(void)   {    void *res; - #ifdef AAP_DEBUG -  fprintf(stderr, "AAP: aap_exit_timeouts.\n"); - #endif /* AAP_DEBUG */ +  DWERROR("AAP: aap_exit_timeouts.\n");    THREADS_ALLOW();    mt_lock (&aap_timeout_mutex);    aap_time_to_die = 1;    co_wait (&aap_timeout_thread_is_dead, &aap_timeout_mutex);    mt_unlock (&aap_timeout_mutex);    THREADS_DISALLOW();    mt_destroy (&aap_timeout_mutex);    co_destroy (&aap_timeout_thread_is_dead); - #ifdef AAP_DEBUG -  fprintf(stderr, "AAP: aap_exit_timeouts done.\n"); - #endif /* AAP_DEBUG */ +  DWERROR("AAP: aap_exit_timeouts done.\n");   }   #endif   #endif