Cosmetic: Copyright years were updated
[ode.git] / ode / src / threading_base.cpp
blob38d677498724ecba36747c8060b5868bdbec0c6f
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-2022 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 "error.h"
36 #include "threading_base.h"
39 dxThreadingBase::~dxThreadingBase()
41 DoFreeStockCallWait();
45 void dxThreadingBase::PostThreadedCallsGroup(
46 int *out_summary_fault/*=NULL*/,
47 ddependencycount_t member_count, dCallReleaseeID dependent_releasee/*=NULL*/,
48 dThreadedCallFunction *call_func, void *call_context,
49 const char *call_name/*=NULL*/) const
51 dIASSERT(member_count != 0);
53 dThreadingImplementationID impl;
54 const dxThreadingFunctionsInfo *functions = FindThreadingImpl(impl);
56 for (unsigned member_index = 0; member_index != member_count; ++member_index) {
57 // Post individual group member jobs
58 functions->post_call(impl, out_summary_fault, NULL, 0, dependent_releasee, NULL, call_func, call_context, member_index, call_name);
62 void dxThreadingBase::PostThreadedCallsIndexOverridenGroup(int *out_summary_fault/*=NULL*/,
63 ddependencycount_t member_count, dCallReleaseeID dependent_releasee/*=NULL*/,
64 dThreadedCallFunction *call_func, void *call_context, unsigned index_override,
65 const char *call_name/*=NULL*/) const
67 dIASSERT(member_count != 0);
69 dThreadingImplementationID impl;
70 const dxThreadingFunctionsInfo *functions = FindThreadingImpl(impl);
72 for (unsigned member_index = 0; member_index != member_count; ++member_index) {
73 // Post individual group member jobs
74 functions->post_call(impl, out_summary_fault, NULL, 0, dependent_releasee, NULL, call_func, call_context, index_override, call_name);
78 void dxThreadingBase::PostThreadedCallForUnawareReleasee(
79 int *out_summary_fault/*=NULL*/,
80 dCallReleaseeID *out_post_releasee/*=NULL*/, ddependencycount_t dependencies_count, dCallReleaseeID dependent_releasee/*=NULL*/,
81 dCallWaitID call_wait/*=NULL*/,
82 dThreadedCallFunction *call_func, void *call_context, dcallindex_t instance_index,
83 const char *call_name/*=NULL*/) const
85 dThreadingImplementationID impl;
86 const dxThreadingFunctionsInfo *functions = FindThreadingImpl(impl);
88 functions->alter_call_dependencies_count(impl, dependent_releasee, 1);
89 functions->post_call(impl, out_summary_fault, out_post_releasee, dependencies_count, dependent_releasee, call_wait, call_func, call_context, instance_index, call_name);
93 const dxThreadingFunctionsInfo *dxThreadingBase::FindThreadingImpl(dThreadingImplementationID &out_impl_found) const
95 const dxThreadingFunctionsInfo *functions_found = GetFunctionsInfo();
97 if (functions_found != NULL)
99 out_impl_found = GetThreadingImpl();
101 else
103 functions_found = m_default_impl_provider->retrieveThreadingDefaultImpl(out_impl_found);
106 return functions_found;
110 dCallWaitID dxThreadingBase::DoAllocateStockCallWait()
112 dIASSERT(GetStockCallWait() == NULL);
114 dCallWaitID stock_wait_id = AllocThreadedCallWait();
116 if (stock_wait_id != NULL)
118 SetStockCallWait(stock_wait_id);
121 return stock_wait_id;
124 void dxThreadingBase::DoFreeStockCallWait()
126 dCallWaitID stock_wait_id = GetStockCallWait();
128 if (stock_wait_id != NULL)
130 FreeThreadedCallWait(stock_wait_id);
132 SetStockCallWait(NULL);