odeinit.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*************************************************************************
  2. * *
  3. * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
  4. * All rights reserved. Email: [email protected] Web: www.q12.org *
  5. * *
  6. * This library is free software; you can redistribute it and/or *
  7. * modify it under the terms of EITHER: *
  8. * (1) The GNU Lesser General Public License as published by the Free *
  9. * Software Foundation; either version 2.1 of the License, or (at *
  10. * your option) any later version. The text of the GNU Lesser *
  11. * General Public License is included with this library in the *
  12. * file LICENSE.TXT. *
  13. * (2) The BSD-style license that is included with this library in *
  14. * the file LICENSE-BSD.TXT. *
  15. * *
  16. * This library is distributed in the hope that it will be useful, *
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
  19. * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
  20. * *
  21. *************************************************************************/
  22. /* Library initialization/finalization functions. */
  23. #ifndef _ODE_ODEINIT_H_
  24. #define _ODE_ODEINIT_H_
  25. #include <ode/common.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /* ************************************************************************ */
  30. /* Library initialization */
  31. /**
  32. * @defgroup init Library Initialization
  33. *
  34. * Library initialization functions prepare ODE internal data structures for use
  35. * and release allocated resources after ODE is not needed any more.
  36. */
  37. /**
  38. * @brief Library initialization flags.
  39. *
  40. * These flags define ODE library initialization options.
  41. *
  42. * @c dInitFlagManualThreadCleanup indicates that resources allocated in TLS for threads
  43. * using ODE are to be cleared by library client with explicit call to @c dCleanupODEAllDataForThread.
  44. * If this flag is not specified the automatic resource tracking algorithm is used.
  45. *
  46. * With automatic resource tracking, On Windows, memory allocated for a thread may
  47. * remain not freed for some time after the thread exits. The resources may be
  48. * released when one of other threads calls @c dAllocateODEDataForThread. Ultimately,
  49. * the resources are released when library is closed with @c dCloseODE. On other
  50. * operating systems resources are always released by the thread itself on its exit
  51. * or on library closure with @c dCloseODE.
  52. *
  53. * If @c dInitFlagManualThreadCleanup was not specified during initialization,
  54. * calls to @c dCleanupODEAllDataForThread are not allowed.
  55. *
  56. * @see dInitODE2
  57. * @see dAllocateODEDataForThread
  58. * @see dCloseODE
  59. * @ingroup init
  60. */
  61. enum dInitODEFlags {
  62. dInitFlagManualThreadCleanup = 0x00000001, //@< Thread local data is to be cleared explicitly on @c dCleanupODEAllDataForThread function call
  63. };
  64. /**
  65. * @brief Initializes ODE library.
  66. *
  67. * @c dInitODE is obsolete. @c dInitODE2 is to be used for library initialization.
  68. *
  69. * A call to @c dInitODE is equal to the following initialization sequence
  70. * @code
  71. * dInitODE2(0);
  72. * dAllocateODEDataForThread(dAllocateMaskAll);
  73. * @endcode
  74. *
  75. * @see dInitODE2
  76. * @see dAllocateODEDataForThread
  77. * @ingroup init
  78. */
  79. ODE_API void dInitODE(void);
  80. /**
  81. * @brief Initializes ODE library.
  82. * @param uiInitFlags Initialization options bitmask
  83. * @return A nonzero if initialization succeeded and zero otherwise.
  84. *
  85. * This function must be called to initialize ODE library before first use. If
  86. * initialization succeeds the function may not be called again until library is
  87. * closed with a call to @c dCloseODE.
  88. *
  89. * The @a uiInitFlags parameter specifies initialization options to be used. These
  90. * can be combination of zero or more @c dInitODEFlags flags.
  91. *
  92. * @see dInitODEFlags
  93. * @see dCloseODE
  94. * @ingroup init
  95. */
  96. ODE_API int dInitODE2(unsigned int uiInitFlags/*=0*/);
  97. /**
  98. * @brief ODE data allocation flags.
  99. *
  100. * These flags are used to indicate which data is to be pre-allocated in call to
  101. * @c dAllocateODEDataForThread.
  102. *
  103. * @c dAllocateFlagBasicData tells to allocate the basic data set required for
  104. * normal library operation. This flag is equal to zero and is always implicitly
  105. * included.
  106. *
  107. * @c dAllocateFlagCollisionData tells that collision detection data is to be allocated.
  108. * Collision detection functions may not be called if the data has not be allocated
  109. * in advance. If collision detection is not going to be used, it is not necessary
  110. * to specify this flag.
  111. *
  112. * @c dAllocateMaskAll is a mask that can be used for for allocating all possible
  113. * data in cases when it is not known what exactly features of ODE will be used.
  114. * The mask may not be used in combination with other flags. It is guaranteed to
  115. * include all the current and future legal allocation flags. However, mature
  116. * applications should use explicit flags they need rather than allocating everything.
  117. *
  118. * @see dAllocateODEDataForThread
  119. * @ingroup init
  120. */
  121. enum dAllocateODEDataFlags {
  122. dAllocateFlagBasicData = 0, //@< Allocate basic data required for library to operate
  123. dAllocateFlagCollisionData = 0x00000001, //@< Allocate data for collision detection
  124. dAllocateMaskAll = ~0U, //@< Allocate all the possible data that is currently defined or will be defined in the future.
  125. };
  126. /**
  127. * @brief Allocate thread local data to allow the thread calling ODE.
  128. * @param uiAllocateFlags Allocation options bitmask.
  129. * @return A nonzero if allocation succeeded and zero otherwise.
  130. *
  131. * The function is required to be called for every thread that is going to use
  132. * ODE. This function allocates the data that is required for accessing ODE from
  133. * current thread along with optional data required for particular ODE subsystems.
  134. *
  135. * @a uiAllocateFlags parameter can contain zero or more flags from @c dAllocateODEDataFlags
  136. * enumerated type. Multiple calls with different allocation flags are allowed.
  137. * The flags that are already allocated are ignored in subsequent calls. If zero
  138. * is passed as the parameter, it means to only allocate the set of most important
  139. * data the library can not operate without.
  140. *
  141. * If the function returns failure status it means that none of the requested
  142. * data has been allocated. The client may retry allocation attempt with the same
  143. * flags when more system resources are available.
  144. *
  145. * @see dAllocateODEDataFlags
  146. * @see dCleanupODEAllDataForThread
  147. * @ingroup init
  148. */
  149. ODE_API int dAllocateODEDataForThread(unsigned int uiAllocateFlags);
  150. /**
  151. * @brief Free thread local data that was allocated for current thread.
  152. *
  153. * If library was initialized with @c dInitFlagManualThreadCleanup flag the function
  154. * is required to be called on exit of every thread that was calling @c dAllocateODEDataForThread.
  155. * Failure to call @c dCleanupODEAllDataForThread may result in some resources remaining
  156. * not freed until program exit. The function may also be called when ODE is still
  157. * being used to release resources allocated for all the current subsystems and
  158. * possibly proceed with data pre-allocation for other subsystems.
  159. *
  160. * The function can safely be called several times in a row. The function can be
  161. * called without prior invocation of @c dAllocateODEDataForThread. The function
  162. * may not be called before ODE is initialized with @c dInitODE2 or after library
  163. * has been closed with @c dCloseODE. A call to @c dCloseODE implicitly releases
  164. * all the thread local resources that might be allocated for all the threads that
  165. * were using ODE.
  166. *
  167. * If library was initialized without @c dInitFlagManualThreadCleanup flag
  168. * @c dCleanupODEAllDataForThread must not be called.
  169. *
  170. * @see dAllocateODEDataForThread
  171. * @see dInitODE2
  172. * @see dCloseODE
  173. * @ingroup init
  174. */
  175. ODE_API void dCleanupODEAllDataForThread();
  176. /**
  177. * @brief Close ODE after it is not needed any more.
  178. *
  179. * The function is required to be called when program does not need ODE features any more.
  180. * The call to @c dCloseODE releases all the resources allocated for library
  181. * including all the thread local data that might be allocated for all the threads
  182. * that were using ODE.
  183. *
  184. * @c dCloseODE is a paired function for @c dInitODE2 and must only be called
  185. * after successful library initialization.
  186. *
  187. * @note Important!
  188. * Make sure that all the threads that were using ODE have already terminated
  189. * before calling @c dCloseODE. In particular it is not allowed to call
  190. * @c dCleanupODEAllDataForThread after @c dCloseODE.
  191. *
  192. * @see dInitODE2
  193. * @see dCleanupODEAllDataForThread
  194. * @ingroup init
  195. */
  196. ODE_API void dCloseODE(void);
  197. #ifdef __cplusplus
  198. }; // extern "C"
  199. #endif
  200. #endif // _ODE_ODEINIT_H_