thread.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #pragma once
  9. #include <libgearman-server/struct/thread.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #include <pthread.h>
  14. /**
  15. * @addtogroup gearman_server_thread Thread Declarations
  16. * @ingroup gearman_server
  17. *
  18. * This is the interface gearman servers should use for creating threads.
  19. *
  20. * @{
  21. */
  22. /**
  23. * Initialize a thread structure. This cannot fail if the caller supplies a
  24. * thread structure.
  25. * @param server Server structure previously initialized with
  26. * gearman_server_create.
  27. * @param thread Caller allocated thread structure, or NULL to allocate one.
  28. * @return Pointer to an allocated thread structure if thread parameter was
  29. * NULL, or the thread parameter pointer if it was not NULL.
  30. */
  31. GEARMAN_API
  32. bool gearman_server_thread_init(gearman_server_st *server,
  33. gearman_server_thread_st *thread,
  34. gearman_log_server_fn *function,
  35. gearmand_thread_st *context,
  36. gearmand_event_watch_fn *event_watch);
  37. /**
  38. * Free resources used by a thread structure.
  39. * @param thread Thread structure previously initialized with
  40. * gearman_server_thread_init.
  41. */
  42. GEARMAN_API
  43. void gearman_server_thread_free(gearman_server_thread_st *thread);
  44. /**
  45. * Set thread run callback.
  46. * @param thread Thread structure previously initialized with
  47. * gearman_server_thread_init.
  48. * @param run_fn Function to call when thread should be run.
  49. * @param run_arg Argument to pass along with run_fn.
  50. */
  51. GEARMAN_API
  52. void gearman_server_thread_set_run(gearman_server_thread_st *thread,
  53. gearman_server_thread_run_fn *run_fn,
  54. void *run_arg);
  55. /**
  56. * Process server thread connections.
  57. * @param thread Thread structure previously initialized with
  58. * gearman_server_thread_init.
  59. * @param ret_ptr Pointer to hold a standard gearman return value.
  60. * @return On error, the server connection that encountered the error.
  61. */
  62. GEARMAN_API
  63. gearmand_con_st *
  64. gearman_server_thread_run(gearman_server_thread_st *thread,
  65. gearmand_error_t *ret_ptr);
  66. /** @} */
  67. #ifdef __cplusplus
  68. }
  69. #endif