Hdevthread.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*****************************************************************************
  2. * Hdevthread.h
  3. *****************************************************************************
  4. *
  5. * Project: HALCON/C
  6. * Description: generic HALCON/C thread interface for hdevelop's HALCON/C
  7. * export (for internal use only, signatures and functionality
  8. * may change )
  9. *
  10. * (c) 2014-2020 by MVTec Software GmbH
  11. * www.mvtec.com
  12. *
  13. ****************************************************************************/
  14. #ifndef HDEVTHREAD_H
  15. #define HDEVTHREAD_H
  16. #if defined(__cplusplus)
  17. extern "C" {
  18. #endif
  19. typedef Hlong Hdevthread;
  20. typedef Hlong Hdevthread_context;
  21. #define HDEVTHREAD_UNDEF 0
  22. #define HDEVTHREAD_CONTEXT_UNDEF 0
  23. /**************************************************************************
  24. * HALCON/C Hdevthread interface
  25. * This interface is for HDevelop C-Export only!
  26. **************************************************************************/
  27. /* A thread context marks for the started thread the period the father
  28. * (=caller) thread stays within the function in which the thread was
  29. * started. This period is equivalent to the period the output parameters of
  30. * procedure started within a thread are valid. I.e., a thread has to be
  31. * joined in the function where it was started if the output parameters
  32. * should be used.
  33. * The procedure that is starting a thread has to call create_hdevthread_context
  34. * after entering (at least before starting the first thread).
  35. * clear_hdevthread_contex must be called before leaving the calling procedure,
  36. * but at least after the last join call within this procedure (if present).
  37. */
  38. LIntExport Herror
  39. create_hdevthread_context( Hdevthread_context *H_RESTRICT context_handle);
  40. LIntExport Herror
  41. clear_hdevthread_context( Hdevthread_context context_handle);
  42. /* create_hdevthread allocates and initializes a HALCON/C thread handle
  43. * 'hthread_handle'. This handle will hold the input and output parameters
  44. * of the procedure that should be called as thread. Therefore, the basic
  45. * address of this procedure is passed in 'proc' (arbitrary sequence of
  46. * input/output HALCON/C types, return type void). Accordingly, the total
  47. * number of input object parameters (iop_num), output object parameters
  48. * (oop_num), input vector parameters (ivp_num), output vector parameters
  49. * (ovp_num), input control parameters (icp_num) and output control
  50. * parameters (ocp_num) of the procedure is passed. The thread instance will
  51. * be owned by the started thread and needn't be cleared by the calling
  52. * thread. */
  53. LIntExport Herror
  54. create_hdevthread( Hdevthread_context const context_handle, void const *proc,
  55. Hlong ip_num, Hlong op_num,
  56. Hdevthread *H_RESTRICT hthread_handle);
  57. /* exit thread is called at the end of the thread's execution and clears
  58. * the hthread handle. */
  59. LIntExport Herror
  60. exit_hdevthread( Hdevthread hthread_handle);
  61. /* clear_hdevthread frees all data hold by the hthread handle. Generally,
  62. * it will be called by exit_hdevthread implicitly and needn't be called
  63. * explicitly. */
  64. LIntExport Herror
  65. clear_hdevthread( Hdevthread hthread_handle);
  66. /* -------------------------------------------------------------------
  67. * Functions to set the input/output parameters of the procedure 'proc'
  68. * within the father thread before starting the new (child) thread:
  69. * -------------------------------------------------------------------*/
  70. /* set_hdevthread_iop sets a input object parameter of the procedure that should
  71. * be started as a thread. The object parameter
  72. * is copied (lazy copy). parpos denotes the x-th occurrence of an input
  73. * object parameter within the signature of proc, starting with 0.*/
  74. LIntExport Herror
  75. set_hdevthread_iop( Hdevthread hthread_handle, Hlong parpos, Hobject const obj);
  76. /* set_hdevthread_oop sets a reference on a output object parameter of the
  77. * procedure that should be started as a thread. parpos denotes the x-th
  78. * occurrence of an output object parameter within the signature of proc,
  79. * starting with 0.*/
  80. LIntExport Herror
  81. bind_hdevthread_oop( Hdevthread hthread_handle, Hlong parpos, HBOOL glb_flag,
  82. Hobject *obj);
  83. /* set_hdevthread_ivp sets a input vector parameter (Hvector) of the procedure
  84. * that should be started as a thread. The input parameter is copied
  85. * (deep copy). parpos denotes the x-th occurrence of the input vector
  86. * parameter within the signature of proc, starting with 0.*/
  87. LIntExport Herror
  88. set_hdevthread_ivp( Hdevthread hthread_handle, Hlong parpos,
  89. Hvector const vector);
  90. /* set_hdevthread_ovp sets the reference on a output vector parameter (Hvector*)
  91. * of the procedure that should be started as a thread. If a sub vector
  92. * should be set, the reference of the original vector is passed in vector,
  93. * the indices of the sub vector are passed in vec_idx.
  94. * parpos denotes the x-th occurrence of the output vector
  95. * parameter within the signature of proc, starting with 0.*/
  96. LIntExport Herror
  97. bind_hdevthread_ovp( Hdevthread hthread_handle, Hlong parpos, HBOOL glb_flag,
  98. Hvector *vector, Htuple const vec_idx);
  99. /* set_hdevthread_icp sets a input control parameter (Htuple) of the procedure
  100. * that should be started as a thread. The control parameter is copied
  101. * (deep copy). parpos denotes the x-th occurrence of the input
  102. * control parameter within the signature of proc, starting with 0.*/
  103. LIntExport Herror
  104. set_hdevthread_icp( Hdevthread hthread_handle, Hlong parpos,
  105. Htuple const tpl);
  106. /* bind_hdevthread_ocp sets a reference on a output control parameter (Htuple*)
  107. * of the procedure that should be started as a thread.
  108. * parpos denotes the x-th
  109. * occurrence of an output control parameter within the signature of proc,
  110. * starting with 0.*/
  111. LIntExport Herror
  112. bind_hdevthread_ocp( Hdevthread hthread_handle, Hlong parpos, HBOOL glb_flag,
  113. Htuple *H_RESTRICT tpl);
  114. /* -------------------------------------------------------------------
  115. * Functions to set the input/output parameters of the procedure 'proc'
  116. * within the child thread:
  117. * -------------------------------------------------------------------*/
  118. /* get_hdevthread_iop returns a reference on the copied object set with
  119. * set_hdevthread_iop. */
  120. LIntExport Herror
  121. get_hdevthread_iop( Hdevthread const hthread_handle, Hlong parpos,
  122. Hobject *H_RESTRICT* obj);
  123. /* overwrite_hdevthread_oop writes back the output object parameter on the
  124. * reference passed in set_hdevthread_oop. */
  125. LIntExport Herror
  126. store_hdevthread_oop( Hdevthread hthread_handle,Hlong parpos,Hobject const obj);
  127. /* get_hdevthread_ivp returns a reference on the copied vector parameter
  128. * set with set_hdevthread_ivp. */
  129. LIntExport Herror
  130. get_hdevthread_ivp( Hdevthread const hthread_handle,
  131. Hlong parpos, Hvector *H_RESTRICT* vec);
  132. /* store_hdevthread_ovp writes back the output (sub) vector parameter
  133. * (generated with create_hdevthread_ovp) on the reference passed in
  134. * set_hdevthread_ovp. */
  135. LIntExport Herror
  136. store_hdevthread_ovp( Hdevthread hthread_handle, Hlong parpos,
  137. Hvector const vector);
  138. /* get_hdevthread_icp returns a reference on the copied tuple control parameter
  139. * set with set_hdevthread_icp. */
  140. LIntExport Herror
  141. get_hdevthread_icp( Hdevthread const hthread_handle,
  142. Hlong parpos, Htuple *H_RESTRICT* tpl);
  143. /* store_hdevthread_ocp writes back the output control parameter on the
  144. * reference passed in set_hdevthread_ocp. */
  145. LIntExport Herror
  146. store_hdevthread_ocp( Hdevthread hthread_handle, Hlong parpos,
  147. Htuple const tpl);
  148. /* start_hdevthread is called by the father thread to start the thread after
  149. * the parameters are set. Contrary to par_start_hdevthread, start_hdevthread can
  150. * be used when no thread has to join with the started thread. No thread id
  151. * is returned, therefore.
  152. * Attention: Different to HDevelop, the child thread must not run anymore
  153. * when exiting the program or unloading the HALCON library. Violating this
  154. * rule might lead to a segmentation fault on exit/unload,
  155. * especially on unix systems. */
  156. LIntExport Herror
  157. start_hdevthread( Hdevthread const hthread_handle);
  158. /* par_start_hdevthread is called by the father thread to start the thread after
  159. * the parameters are set. Contrary to start_thread, a thread id (par_handle)
  160. * is returned that can be used by par_join to wait for the started thread
  161. * exiting.
  162. * Attention: Different to HDevelop, the child thread must not run anymore
  163. * when exiting the program or unloading the HALCON library. Violating this
  164. * rule might lead to a segmentation fault on exit/unload,
  165. * especially on unix systems. */
  166. LIntExport Herror
  167. par_start_hdevthread( Hdevthread const hthread_handle,
  168. Htuple *H_RESTRICT par_handle);
  169. /* call_hdevthread_proc calls the procedure specified in create_hdevthread
  170. * synchronously. This must be used for synchronous procedure calls, when
  171. * the procedure was started as thread with the same output parameters within
  172. * the same hthread context. */
  173. LIntExport Herror
  174. call_hdevthread_proc( Hdevthread const hthread_handle);
  175. /* T_par_join_hdevthread waits until all threads addressed by their thread id in
  176. * par_handle finished. */
  177. LIntExport Herror
  178. T_par_join_hdevthread( Htuple const par_handles);
  179. #if defined(__cplusplus)
  180. }
  181. #endif
  182. #endif