odeinit.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. * With manual thread data cleanup mode every collision space object must be
  54. * explicitly switched to manual cleanup mode with @c dSpaceSetManualCleanup
  55. * after creation. See description of the function for more details.
  56. *
  57. * If @c dInitFlagManualThreadCleanup was not specified during initialization,
  58. * calls to @c dCleanupODEAllDataForThread are not allowed.
  59. *
  60. * @see dInitODE2
  61. * @see dAllocateODEDataForThread
  62. * @see dSpaceSetManualCleanup
  63. * @see dCloseODE
  64. * @ingroup init
  65. */
  66. enum dInitODEFlags {
  67. dInitFlagManualThreadCleanup = 0x00000001 //@< Thread local data is to be cleared explicitly on @c dCleanupODEAllDataForThread function call
  68. };
  69. /**
  70. * @brief Initializes ODE library.
  71. *
  72. * @c dInitODE is obsolete. @c dInitODE2 is to be used for library initialization.
  73. *
  74. * A call to @c dInitODE is equal to the following initialization sequence
  75. * @code
  76. * dInitODE2(0);
  77. * dAllocateODEDataForThread(dAllocateMaskAll);
  78. * @endcode
  79. *
  80. * @see dInitODE2
  81. * @see dAllocateODEDataForThread
  82. * @ingroup init
  83. */
  84. ODE_API void dInitODE(void);
  85. /**
  86. * @brief Initializes ODE library.
  87. * @param uiInitFlags Initialization options bitmask
  88. * @return A nonzero if initialization succeeded and zero otherwise.
  89. *
  90. * This function must be called to initialize ODE library before first use. If
  91. * initialization succeeds the function may not be called again until library is
  92. * closed with a call to @c dCloseODE.
  93. *
  94. * The @a uiInitFlags parameter specifies initialization options to be used. These
  95. * can be combination of zero or more @c dInitODEFlags flags.
  96. *
  97. * @note
  98. * If @c dInitFlagManualThreadCleanup flag is used for initialization,
  99. * @c dSpaceSetManualCleanup must be called to set manual cleanup mode for every
  100. * space object right after creation. Failure to do so may lead to resource leaks.
  101. *
  102. * @see dInitODEFlags
  103. * @see dCloseODE
  104. * @see dSpaceSetManualCleanup
  105. * @ingroup init
  106. */
  107. ODE_API int dInitODE2(unsigned int uiInitFlags/*=0*/);
  108. /**
  109. * @brief ODE data allocation flags.
  110. *
  111. * These flags are used to indicate which data is to be pre-allocated in call to
  112. * @c dAllocateODEDataForThread.
  113. *
  114. * @c dAllocateFlagBasicData tells to allocate the basic data set required for
  115. * normal library operation. This flag is equal to zero and is always implicitly
  116. * included.
  117. *
  118. * @c dAllocateFlagCollisionData tells that collision detection data is to be allocated.
  119. * Collision detection functions may not be called if the data has not be allocated
  120. * in advance. If collision detection is not going to be used, it is not necessary
  121. * to specify this flag.
  122. *
  123. * @c dAllocateMaskAll is a mask that can be used for for allocating all possible
  124. * data in cases when it is not known what exactly features of ODE will be used.
  125. * The mask may not be used in combination with other flags. It is guaranteed to
  126. * include all the current and future legal allocation flags. However, mature
  127. * applications should use explicit flags they need rather than allocating everything.
  128. *
  129. * @see dAllocateODEDataForThread
  130. * @ingroup init
  131. */
  132. enum dAllocateODEDataFlags {
  133. dAllocateFlagBasicData = 0, //@< Allocate basic data required for library to operate
  134. dAllocateFlagCollisionData = 0x00000001, //@< Allocate data for collision detection
  135. dAllocateMaskAll = ~0U //@< Allocate all the possible data that is currently defined or will be defined in the future.
  136. };
  137. /**
  138. * @brief Allocate thread local data to allow the thread calling ODE.
  139. * @param uiAllocateFlags Allocation options bitmask.
  140. * @return A nonzero if allocation succeeded and zero otherwise.
  141. *
  142. * The function is required to be called for every thread that is going to use
  143. * ODE. This function allocates the data that is required for accessing ODE from
  144. * current thread along with optional data required for particular ODE subsystems.
  145. *
  146. * @a uiAllocateFlags parameter can contain zero or more flags from @c dAllocateODEDataFlags
  147. * enumerated type. Multiple calls with different allocation flags are allowed.
  148. * The flags that are already allocated are ignored in subsequent calls. If zero
  149. * is passed as the parameter, it means to only allocate the set of most important
  150. * data the library can not operate without.
  151. *
  152. * If the function returns failure status it means that none of the requested
  153. * data has been allocated. The client may retry allocation attempt with the same
  154. * flags when more system resources are available.
  155. *
  156. * @see dAllocateODEDataFlags
  157. * @see dCleanupODEAllDataForThread
  158. * @ingroup init
  159. */
  160. ODE_API int dAllocateODEDataForThread(unsigned int uiAllocateFlags);
  161. /**
  162. * @brief Free thread local data that was allocated for current thread.
  163. *
  164. * If library was initialized with @c dInitFlagManualThreadCleanup flag the function
  165. * is required to be called on exit of every thread that was calling @c dAllocateODEDataForThread.
  166. * Failure to call @c dCleanupODEAllDataForThread may result in some resources remaining
  167. * not freed until program exit. The function may also be called when ODE is still
  168. * being used to release resources allocated for all the current subsystems and
  169. * possibly proceed with data pre-allocation for other subsystems.
  170. *
  171. * The function can safely be called several times in a row. The function can be
  172. * called without prior invocation of @c dAllocateODEDataForThread. The function
  173. * may not be called before ODE is initialized with @c dInitODE2 or after library
  174. * has been closed with @c dCloseODE. A call to @c dCloseODE implicitly releases
  175. * all the thread local resources that might be allocated for all the threads that
  176. * were using ODE.
  177. *
  178. * If library was initialized without @c dInitFlagManualThreadCleanup flag
  179. * @c dCleanupODEAllDataForThread must not be called.
  180. *
  181. * @see dAllocateODEDataForThread
  182. * @see dInitODE2
  183. * @see dCloseODE
  184. * @ingroup init
  185. */
  186. ODE_API void dCleanupODEAllDataForThread();
  187. /**
  188. * @brief Close ODE after it is not needed any more.
  189. *
  190. * The function is required to be called when program does not need ODE features any more.
  191. * The call to @c dCloseODE releases all the resources allocated for library
  192. * including all the thread local data that might be allocated for all the threads
  193. * that were using ODE.
  194. *
  195. * @c dCloseODE is a paired function for @c dInitODE2 and must only be called
  196. * after successful library initialization.
  197. *
  198. * @note Important!
  199. * Make sure that all the threads that were using ODE have already terminated
  200. * before calling @c dCloseODE. In particular it is not allowed to call
  201. * @c dCleanupODEAllDataForThread after @c dCloseODE.
  202. *
  203. * @see dInitODE2
  204. * @see dCleanupODEAllDataForThread
  205. * @ingroup init
  206. */
  207. ODE_API void dCloseODE(void);
  208. #ifdef __cplusplus
  209. } // extern "C"
  210. #endif
  211. #endif // _ODE_ODEINIT_H_