server.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #pragma once
  38. struct queue_st {
  39. void *_context;
  40. gearman_queue_add_fn *_add_fn;
  41. gearman_queue_flush_fn *_flush_fn;
  42. gearman_queue_done_fn *_done_fn;
  43. gearman_queue_replay_fn *_replay_fn;
  44. queue_st() :
  45. _context(NULL),
  46. _add_fn(NULL),
  47. _flush_fn(NULL),
  48. _done_fn(NULL),
  49. _replay_fn(NULL)
  50. {
  51. }
  52. };
  53. enum queue_version_t {
  54. QUEUE_VERSION_NONE,
  55. QUEUE_VERSION_FUNCTION,
  56. QUEUE_VERSION_CLASS
  57. };
  58. namespace gearmand { namespace queue { class Context; } }
  59. struct Queue_st {
  60. struct queue_st* functions{};
  61. gearmand::queue::Context* object{};
  62. };
  63. struct gearman_server_st
  64. {
  65. struct Flags {
  66. /*
  67. Sets the round-robin mode on the server object. RR will distribute work
  68. fairly among every function assigned to a worker, instead of draining
  69. each function before moving on to the next.
  70. */
  71. bool round_robin;
  72. bool threaded;
  73. } flags;
  74. struct State {
  75. bool queue_startup;
  76. } state;
  77. bool shutdown{};
  78. bool shutdown_graceful{};
  79. bool proc_wakeup{};
  80. bool proc_shutdown{};
  81. uint32_t job_retries{}; // Set maximum job retry count.
  82. uint8_t worker_wakeup{}; // Set maximum number of workers to wake up per job.
  83. uint32_t job_handle_count{};
  84. uint32_t thread_count{};
  85. uint32_t function_count{};
  86. uint32_t job_count{};
  87. uint32_t unique_count{};
  88. uint32_t free_packet_count{};
  89. uint32_t free_job_count{};
  90. uint32_t free_client_count{};
  91. uint32_t free_worker_count{};
  92. gearman_server_thread_st *thread_list{nullptr};
  93. gearman_server_function_st **function_hash{nullptr};
  94. gearman_server_packet_st *free_packet_list{nullptr};
  95. gearman_server_job_st *free_job_list{nullptr};
  96. gearman_server_client_st *free_client_list{nullptr};
  97. gearman_server_worker_st *free_worker_list{nullptr};
  98. enum queue_version_t queue_version{};
  99. struct Queue_st queue{};
  100. pthread_mutex_t proc_lock{};
  101. pthread_cond_t proc_cond{};
  102. pthread_t proc_id{};
  103. char job_handle_prefix[GEARMAND_JOB_HANDLE_SIZE];
  104. uint32_t hashtable_buckets{};
  105. gearman_server_job_st **job_hash{nullptr};
  106. gearman_server_job_st **unique_hash{nullptr};
  107. gearman_server_st()
  108. {
  109. }
  110. ~gearman_server_st()
  111. {
  112. }
  113. };