Threaded execution support interface added. Optional built-in threading implementatio...
[ode.git] / ode / src / threading_base.cpp
blob3de86ce35e92a30133db3da1b847036aeef6ee5f
1 /*************************************************************************
2 * *
3 * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. *
4 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
5 * *
6 * Threading base wrapper class implementation 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 *************************************************************************/
28 * Threading base class to be used for inheritance by dxWorld, dxSpace and others
29 * to take advantage of threaded execution.
33 #include <ode/common.h>
34 #include "config.h"
35 #include "threading_base.h"
38 void dxThreadingBase::PostThreadedCallsGroup(int *out_summary_fault/*=NULL*/,
39 ddependencycount_t member_count, dCallReleaseeID dependent_releasee/*=NULL*/,
40 dThreadedCallFunction *call_func, void *call_context,
41 const char *call_name/*=NULL*/) const
43 dThreadingImplementationID impl;
44 const dxThreadingFunctionsInfo *functions = FindThreadingImpl(impl);
46 for (unsigned member_index = 0; member_index != member_count; ++member_index) {
47 // Post individual group member jobs
48 functions->post_call(impl, out_summary_fault, NULL, 0, dependent_releasee, NULL, call_func, call_context, member_index, call_name);
52 void dxThreadingBase::PostThreadedCallForUnawareReleasee(int *out_summary_fault/*=NULL*/,
53 dCallReleaseeID *out_post_releasee/*=NULL*/, ddependencycount_t dependencies_count, dCallReleaseeID dependent_releasee/*=NULL*/,
54 dCallWaitID call_wait/*=NULL*/,
55 dThreadedCallFunction *call_func, void *call_context, dcallindex_t instance_index,
56 const char *call_name/*=NULL*/) const
58 dThreadingImplementationID impl;
59 const dxThreadingFunctionsInfo *functions = FindThreadingImpl(impl);
61 functions->alter_call_dependencies_count(impl, dependent_releasee, 1);
62 functions->post_call(impl, out_summary_fault, out_post_releasee, dependencies_count, dependent_releasee, call_wait, call_func, call_context, instance_index, call_name);
65 const dxThreadingFunctionsInfo *dxThreadingBase::FindThreadingImpl(dThreadingImplementationID &out_impl_found) const
67 const dxThreadingFunctionsInfo *functions_found = GetFunctionsInfo();
69 if (functions_found != NULL)
71 out_impl_found = GetThreadingImpl();
73 else
75 functions_found = m_default_impl_provider->RetrieveThreadingDefaultImpl(out_impl_found);
78 return functions_found;