start_worker.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Gearman server and library
  2. * Copyright (C) 2008 Brian Aker, Eric Day
  3. * All rights reserved.
  4. *
  5. * Use and distribution licensed under the BSD license. See
  6. * the COPYING file in the parent directory for full text.
  7. */
  8. #include <sys/types.h>
  9. #include <pthread.h>
  10. #include <libgearman/gearman.h>
  11. #include <libtest/visibility.h>
  12. struct worker_handle_st
  13. {
  14. pthread_t thread;
  15. bool _shutdown;
  16. pthread_mutex_t _shutdown_lock;
  17. std::string _fully_shutdown_function;
  18. std::string _shutdown_function;
  19. std::string _name;
  20. in_port_t _port;
  21. gearman_worker_st *_worker_ptr;
  22. in_port_t port() const
  23. {
  24. return _port;
  25. }
  26. const std::string& shutdown_function(bool fully_qualified= false) const
  27. {
  28. if (fully_qualified)
  29. return _fully_shutdown_function;
  30. return _shutdown_function;
  31. }
  32. const std::string& name() const
  33. {
  34. return _name;
  35. }
  36. worker_handle_st(const char *namespace_key, const std::string& name_arg, in_port_t);
  37. ~worker_handle_st();
  38. void set_shutdown()
  39. {
  40. pthread_mutex_lock(&_shutdown_lock);
  41. _shutdown= true;
  42. pthread_mutex_unlock(&_shutdown_lock);
  43. }
  44. bool is_shutdown();
  45. bool shutdown();
  46. };
  47. #pragma once
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. LIBTEST_API
  52. struct worker_handle_st *test_worker_start(in_port_t port,
  53. const char *namespace_key,
  54. const char *function_name,
  55. gearman_function_t &worker_fn,
  56. void *context,
  57. gearman_worker_options_t options);
  58. LIBTEST_API
  59. bool test_worker_stop(struct worker_handle_st *);
  60. #ifdef __cplusplus
  61. }
  62. #endif