root/src/eventer/eventer_jobq.h

Revision 3b3b432b41dd3bfb80c144aa7ba28e75daa2337f, 1.9 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

asynchronous job queues

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  */
5
6 #ifndef _NOIT_JOBQUEUE_H
7 #define _NOIT_JOBQUEUE_H
8
9 #include "noit_defines.h"
10 #include "eventer/eventer.h"
11 #include "utils/noit_atomic.h"
12 #include "utils/noit_sem.h"
13
14 #include <pthread.h>
15 #include <setjmp.h>
16
17 /*
18  * This is for jobs that would block and need more forceful timeouts.
19  */
20
21 typedef struct _eventer_job_t {
22   pthread_mutex_t         lock;
23   struct timeval          create_time;
24   struct timeval          start_time;
25   struct timeval          finish_time;
26   pthread_t               executor;
27   eventer_t               timeout_event;
28   eventer_t               fd_event;
29   int                     timeout_triggered; /* set, if it expires in-flight */
30   noit_atomic32_t         inflight;
31   noit_atomic32_t         has_cleanedup;
32   void                  (*cleanup)(struct _eventer_job_t *);
33   struct _eventer_job_t  *next;
34 } eventer_job_t;
35
36 typedef struct _eventer_jobq_t {
37   pthread_mutex_t         lock;
38   sem_t                   semaphore;
39   noit_atomic32_t         concurrency;
40   eventer_job_t          *headq;
41   eventer_job_t          *tailq;
42   pthread_key_t           threadenv;
43   pthread_key_t           activejob;
44   struct _eventer_jobq_t *backq;
45 } eventer_jobq_t;
46
47 int eventer_jobq_init(eventer_jobq_t *jobq);
48 void eventer_jobq_enqueue(eventer_jobq_t *jobq, eventer_job_t *job);
49 eventer_job_t *eventer_jobq_dequeue(eventer_jobq_t *jobq);
50 eventer_job_t *eventer_jobq_dequeue_nowait(eventer_jobq_t *jobq);
51 void eventer_jobq_destroy(eventer_jobq_t *jobq);
52 int eventer_jobq_execute_timeout(eventer_t e, int mask, void *closure,
53                                  struct timeval *now);
54 int eventer_jobq_consume_available(eventer_t e, int mask, void *closure,
55                                    struct timeval *now);
56 void eventer_jobq_increase_concurrency(eventer_jobq_t *jobq);
57 void eventer_jobq_decrease_concurrency(eventer_jobq_t *jobq);
58 void *eventer_jobq_consumer(eventer_jobq_t *jobq);
59
60 #endif
Note: See TracBrowser for help on using the browser.