Cosmetic: Copyright years were updated
[ode.git] / ode / src / resource_control.h
blob7a6a591ca60396e4ce8574f535dc954f74534343
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 * 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 *************************************************************************/
24 * Resource accounting/preallocation class declarations
25 * Copyright (c) 2017-2022 Oleh Derevenko, odar@eleks.com (change all "a" to "e")
28 #ifndef _ODE__PRIVATE_RESOURCE_CONTRIOL_H_
29 #define _ODE__PRIVATE_RESOURCE_CONTRIOL_H_
32 #include "objects.h"
33 #include "threading_base.h"
34 #include "odeou.h"
35 #include "common.h"
36 #include "error.h"
39 using _OU_NAMESPACE::CSimpleFlags;
42 class dxResourceRequirementDescriptor:
43 public dBase
45 public:
46 explicit dxResourceRequirementDescriptor(dxThreadingBase *relatedThreading):
47 dBase(),
48 m_relatedThreading(relatedThreading),
49 m_memorySizeRequirement(0),
50 m_memoryAlignmentRequirement(0),
51 m_simultaneousCallRequirement(0),
52 m_featureRequirements()
56 ~dxResourceRequirementDescriptor();
58 enum
60 STOCK_CALLWAIT_REQUIRED = 0x00000001,
63 void mergeAnotherDescriptorIn(const dxResourceRequirementDescriptor &anotherDescriptor)
65 dIASSERT(getrelatedThreading() == anotherDescriptor.getrelatedThreading()); // m_simultaneousCallRequirement typically depends on threading used
67 CSimpleFlags::value_type allOtherFeatureFlags = anotherDescriptor.queryAllFeatureFlags();
68 mergeAnotherDescriptorIn(anotherDescriptor.m_memorySizeRequirement, anotherDescriptor.m_memoryAlignmentRequirement, anotherDescriptor.m_simultaneousCallRequirement, allOtherFeatureFlags);
71 void mergeAnotherDescriptorIn(sizeint memorySizeRequirement/*=0*/, unsigned memoryAlignmentRequirement,
72 unsigned simultaneousCallRequirement/*=0*/, unsigned featureRequirement/*=0*/)
74 m_memorySizeRequirement = dMACRO_MAX(m_memorySizeRequirement, memorySizeRequirement);
75 m_memoryAlignmentRequirement = dMACRO_MAX(m_memoryAlignmentRequirement, memoryAlignmentRequirement);
76 m_simultaneousCallRequirement = dMACRO_MAX(m_simultaneousCallRequirement, simultaneousCallRequirement);
77 mergeFeatureFlags(featureRequirement);
80 public:
81 dxThreadingBase *getrelatedThreading() const { return m_relatedThreading; }
82 sizeint getMemorySizeRequirement() const { return m_memorySizeRequirement; }
83 unsigned getMemoryAlignmentRequirement() const { return m_memoryAlignmentRequirement; }
85 unsigned getSimultaneousCallRequirement() const { return m_simultaneousCallRequirement; }
87 bool getIsStockCallWaitRequired() const { return getStockCallWaitRequiredFlag(); }
89 private:
90 enum
92 FL_STOCK_CALLWAIT_REQUIRED = STOCK_CALLWAIT_REQUIRED,
95 bool getStockCallWaitRequiredFlag() const { return m_featureRequirements.GetFlagsMaskValue(FL_STOCK_CALLWAIT_REQUIRED); }
97 CSimpleFlags::value_type queryAllFeatureFlags() const { return m_featureRequirements.QueryFlagsAllValues(); }
98 void mergeFeatureFlags(CSimpleFlags::value_type flagValues) { m_featureRequirements.SignalFlagsMaskValue(flagValues); }
100 private:
101 dxThreadingBase *m_relatedThreading;
102 sizeint m_memorySizeRequirement;
103 unsigned m_memoryAlignmentRequirement;
104 unsigned m_simultaneousCallRequirement;
105 CSimpleFlags m_featureRequirements;
108 static inline
109 dxResourceRequirementDescriptor *decodeResourceRequirementsID(dResourceRequirementsID requirements)
111 return (dxResourceRequirementDescriptor *)requirements;
115 class dxRequiredResourceContainer:
116 public dBase
118 public:
119 dxRequiredResourceContainer():
120 dBase(),
121 m_relatedThreading(NULL),
122 m_stockCallWait(NULL),
123 m_memoryAllocation()
127 ~dxRequiredResourceContainer();
129 bool allocateResources(const dxResourceRequirementDescriptor &requirementDescriptor);
130 void freeResources();
132 public:
133 dxThreadingBase *getThreadingInstance() const { return m_relatedThreading; }
134 dCallWaitID getStockCallWait() const { return m_stockCallWait; }
135 void *getMemoryBufferPointer() const { return m_memoryAllocation.getUserAreaPointer(); }
136 sizeint getMemoryBufferSize() const { return m_memoryAllocation.getUserAreaSize(); }
138 private:
139 dxThreadingBase *m_relatedThreading;
140 dCallWaitID m_stockCallWait;
141 dxAlignedAllocation m_memoryAllocation;
144 static inline
145 dxRequiredResourceContainer *decodeResourceContainerID(dResourceContainerID resources)
147 return (dxRequiredResourceContainer *)resources;
151 #endif // #ifndef _ODE__PRIVATE_RESOURCE_CONTRIOL_H_