1 /*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2  *
3  *  Gearmand client and server library.
4  *
5  *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
6  *  All rights reserved.
7  *
8  *  Redistribution and use in source and binary forms, with or without
9  *  modification, are permitted provided that the following conditions are
10  *  met:
11  *
12  *      * Redistributions of source code must retain the above copyright
13  *  notice, this list of conditions and the following disclaimer.
14  *
15  *      * Redistributions in binary form must reproduce the above
16  *  copyright notice, this list of conditions and the following disclaimer
17  *  in the documentation and/or other materials provided with the
18  *  distribution.
19  *
20  *      * The names of its contributors may not be used to endorse or
21  *  promote products derived from this software without specific prior
22  *  written permission.
23  *
24  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #pragma once
39 
40 struct queue_st {
41   void *_context;
42   gearman_queue_add_fn *_add_fn;
43   gearman_queue_flush_fn *_flush_fn;
44   gearman_queue_done_fn *_done_fn;
45   gearman_queue_replay_fn *_replay_fn;
46 
queue_stqueue_st47   queue_st() :
48     _context(NULL),
49     _add_fn(NULL),
50     _flush_fn(NULL),
51     _done_fn(NULL),
52     _replay_fn(NULL)
53   {
54   }
55 };
56 
57 enum queue_version_t {
58   QUEUE_VERSION_NONE,
59   QUEUE_VERSION_FUNCTION,
60   QUEUE_VERSION_CLASS
61 };
62 
63 namespace gearmand { namespace queue { class Context; } }
64 
65 struct Queue_st {
66   struct queue_st* functions;
67   gearmand::queue::Context* object;
68 };
69 
70 struct gearman_server_st
71 {
72   struct Flags {
73     /*
74       Sets the round-robin mode on the server object. RR will distribute work
75       fairly among every function assigned to a worker, instead of draining
76       each function before moving on to the next.
77     */
78     bool round_robin;
79     bool threaded;
80   } flags;
81   struct State {
82     bool queue_startup;
83   } state;
84   bool shutdown;
85   bool shutdown_graceful;
86   bool proc_wakeup;
87   bool proc_shutdown;
88   uint32_t job_retries; // Set maximum job retry count.
89   uint8_t worker_wakeup; // Set maximum number of workers to wake up per job.
90   uint32_t job_handle_count;
91   uint32_t thread_count;
92   uint32_t function_count;
93   uint32_t job_count;
94   uint32_t unique_count;
95   uint32_t free_packet_count;
96   uint32_t free_job_count;
97   uint32_t free_client_count;
98   uint32_t free_worker_count;
99   gearman_server_thread_st *thread_list;
100   gearman_server_function_st **function_hash;
101   gearman_server_packet_st *free_packet_list;
102   gearman_server_job_st *free_job_list;
103   gearman_server_client_st *free_client_list;
104   gearman_server_worker_st *free_worker_list;
105   enum queue_version_t queue_version;
106   struct Queue_st queue;
107   pthread_mutex_t proc_lock;
108   pthread_cond_t proc_cond;
109   pthread_t proc_id;
110   char job_handle_prefix[GEARMAND_JOB_HANDLE_SIZE];
111   uint32_t hashtable_buckets;
112   gearman_server_job_st **job_hash;
113   gearman_server_job_st **unique_hash;
114 
gearman_server_stgearman_server_st115   gearman_server_st()
116   {
117   }
118 
~gearman_server_stgearman_server_st119   ~gearman_server_st()
120   {
121   }
122 };
123