ODE  0.13.1
 All Data Structures Functions Variables Typedefs Enumerations Groups
threading.h
1 /*************************************************************************
2  * *
3  * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
4  * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5  * *
6  * Threading support header file. *
7  * Copyright (C) 2011-2012 Oleh Derevenko. All rights reserved. *
8  * e-mail: odar@eleks.com (change all "a" to "e") *
9  * *
10  * This library is free software; you can redistribute it and/or *
11  * modify it under the terms of EITHER: *
12  * (1) The GNU Lesser General Public License as published by the Free *
13  * Software Foundation; either version 2.1 of the License, or (at *
14  * your option) any later version. The text of the GNU Lesser *
15  * General Public License is included with this library in the *
16  * file LICENSE.TXT. *
17  * (2) The BSD-style license that is included with this library in *
18  * the file LICENSE-BSD.TXT. *
19  * *
20  * This library is distributed in the hope that it will be useful, *
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
23  * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
24  * *
25  *************************************************************************/
26 
27 /*
28  * ODE threading support interfaces
29  */
30 
31 
32 #ifndef _ODE_THREADING_H_
33 #define _ODE_THREADING_H_
34 
35 #include <ode/odeconfig.h>
36 // Include <time.h> since time_t is used and it is not available by default in some OSes
37 #include <time.h>
38 
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 
45 struct dxThreadingImplementation;
46 typedef struct dxThreadingImplementation *dThreadingImplementationID;
47 
48 typedef unsigned dmutexindex_t;
49 struct dxMutexGroup;
50 typedef struct dxMutexGroup *dMutexGroupID;
51 
69 typedef dMutexGroupID dMutexGroupAllocFunction (dThreadingImplementationID impl, dmutexindex_t Mutex_count, const char *const *Mutex_names_ptr/*=NULL*/);
70 
82 typedef void dMutexGroupFreeFunction (dThreadingImplementationID impl, dMutexGroupID mutex_group);
83 
101 typedef void dMutexGroupMutexLockFunction (dThreadingImplementationID impl, dMutexGroupID mutex_group, dmutexindex_t mutex_index);
102 
123 /* typedef int dMutexGroupMutexTryLockFunction (dThreadingImplementationID impl, dMutexGroupID mutex_group, dmutexindex_t mutex_index);*/
124 
139 typedef void dMutexGroupMutexUnlockFunction (dThreadingImplementationID impl, dMutexGroupID mutex_group, dmutexindex_t mutex_index);
140 
141 
142 struct dxCallReleasee;
143 typedef struct dxCallReleasee *dCallReleaseeID;
144 
145 struct dxCallWait;
146 typedef struct dxCallWait *dCallWaitID;
147 
148 typedef size_t ddependencycount_t;
149 typedef ptrdiff_t ddependencychange_t;
150 typedef size_t dcallindex_t;
151 typedef int dThreadedCallFunction(void *call_context, dcallindex_t instance_index,
152  dCallReleaseeID this_releasee);
153 
154 typedef struct dxThreadedWaitTime
155 {
156  time_t wait_sec;
157  unsigned long wait_nsec;
158 
160 
161 
174 typedef dCallWaitID dThreadedCallWaitAllocFunction(dThreadingImplementationID impl);
175 
188 typedef void dThreadedCallWaitResetFunction(dThreadingImplementationID impl, dCallWaitID call_wait);
189 
201 typedef void dThreadedCallWaitFreeFunction(dThreadingImplementationID impl, dCallWaitID call_wait);
202 
203 
265 typedef void dThreadedCallPostFunction(dThreadingImplementationID impl, int *out_summary_fault/*=NULL*/,
266  dCallReleaseeID *out_post_releasee/*=NULL*/, ddependencycount_t dependencies_count, dCallReleaseeID dependent_releasee/*=NULL*/,
267  dCallWaitID call_wait/*=NULL*/,
268  dThreadedCallFunction *call_func, void *call_context, dcallindex_t instance_index,
269  const char *call_name/*=NULL*/);
270 
292 typedef void dThreadedCallDependenciesCountAlterFunction(dThreadingImplementationID impl, dCallReleaseeID target_releasee,
293  ddependencychange_t dependencies_count_change);
294 
327 typedef void dThreadedCallWaitFunction(dThreadingImplementationID impl, int *out_wait_status/*=NULL*/,
328  dCallWaitID call_wait, const dThreadedWaitTime *timeout_time_ptr/*=NULL*/,
329  const char *wait_name/*=NULL*/);
330 
339 typedef unsigned dThreadingImplThreadCountRetrieveFunction(dThreadingImplementationID impl);
340 
363 typedef int dThreadingImplResourcesForCallsPreallocateFunction(dThreadingImplementationID impl,
364  ddependencycount_t max_simultaneous_calls_estimate);
365 
366 
371 {
372  unsigned struct_size;
373 
374  dMutexGroupAllocFunction *alloc_mutex_group;
375  dMutexGroupFreeFunction *free_mutex_group;
376  dMutexGroupMutexLockFunction *lock_group_mutex;
377  dMutexGroupMutexUnlockFunction *unlock_group_mutex;
378 
379  dThreadedCallWaitAllocFunction *alloc_call_wait;
380  dThreadedCallWaitResetFunction *reset_call_wait;
381  dThreadedCallWaitFreeFunction *free_call_wait;
382 
383  dThreadedCallPostFunction *post_call;
384  dThreadedCallDependenciesCountAlterFunction *alter_call_dependencies_count;
385  dThreadedCallWaitFunction *wait_call;
386 
387  dThreadingImplThreadCountRetrieveFunction *retrieve_thread_count;
388  dThreadingImplResourcesForCallsPreallocateFunction *preallocate_resources_for_calls;
389 
390  /*
391  * Beware of Jon Watte's anger if you dare to uncomment this!
392  * May cryptic text below be you a warning!
393  * Стародавні легенди розказують, що кожного сміливця, хто наважиться порушити табу
394  * і відкрити заборонений код, спіткає страшне прокляття і він відразу почне робити
395  * одні лиш помилки.
396  *
397  * dMutexGroupMutexTryLockFunction *trylock_group_mutex;
398  */
399 
401 
402 
403 #ifdef __cplusplus
404 }
405 #endif
406 
407 #endif /* #ifndef _ODE_THREADING_H_ */
Definition: threading.h:154
An interface structure with function pointers to be provided by threading implementation.
Definition: threading.h:370