(file) Return to SCMOClassCache.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 thilo.boehm 1.2 //%LICENSE////////////////////////////////////////////////////////////////
  2                 //
  3                 // Licensed to The Open Group (TOG) under one or more contributor license
  4                 // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5                 // this work for additional information regarding copyright ownership.
  6                 // Each contributor licenses this file to you under the OpenPegasus Open
  7                 // Source License; you may not use this file except in compliance with the
  8                 // License.
  9                 //
 10                 // Permission is hereby granted, free of charge, to any person obtaining a
 11                 // copy of this software and associated documentation files (the "Software"),
 12                 // to deal in the Software without restriction, including without limitation
 13                 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14                 // and/or sell copies of the Software, and to permit persons to whom the
 15                 // Software is furnished to do so, subject to the following conditions:
 16                 //
 17                 // The above copyright notice and this permission notice shall be included
 18                 // in all copies or substantial portions of the Software.
 19                 //
 20                 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21                 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 thilo.boehm 1.2 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23                 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24                 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25                 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26                 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27                 //
 28                 //////////////////////////////////////////////////////////////////////////
 29                 //
 30                 //%/////////////////////////////////////////////////////////////////////////////
 31                 #ifndef _SCMOClassCache_H_
 32                 #define _SCMOClassCache_H_
 33                 
 34                 #include <Pegasus/Common/Linkage.h>
 35                 #include <Pegasus/Common/Config.h>
 36                 #include <Pegasus/Common/CIMClass.h>
 37                 #include <Pegasus/Common/ReadWriteSem.h>
 38                 #include <Pegasus/Common/SCMOClass.h>
 39                 
 40                 PEGASUS_NAMESPACE_BEGIN
 41                 
 42                 typedef SCMOClass (*SCMOClassCacheCallbackPtr)(
 43 thilo.boehm 1.2         const CIMNamespaceName& nameSpace,
 44                         const CIMName& className);
 45                 
 46 marek       1.3 #define PEGASUS_SCMO_CLASS_CACHE_SIZE 32
 47 thilo.boehm 1.2 
 48                 struct SCMBClassCacheEntry
 49                 {
 50                     // Spin-lock to serialize the access to the entry
 51                     AtomicInt lock;
 52                     // The key to identify the entry
 53                     Uint64    key;
 54                     // Pointer to the cached SCMOClass
 55                     SCMOClass* data;
 56                 };
 57                 
 58                 class PEGASUS_COMMON_LINKAGE SCMOClassCache
 59                 {
 60                 
 61                 public:
 62                 
 63                     /**
 64                      * This function returns the SCMOClass for the given class name and
 65                      * name space.
 66                      * @param ndName The UTF8 encoded name space. '\0' terminated
 67                      * @param nsNameLan The strlen of ndName ( without '\0')
 68 thilo.boehm 1.2      * @param className The UTF8 encoded class name. '\0' terminated
 69                      * @param nsNameLan The strlen of className ( without '\0')
 70                      * @return A pointer to SCMOClass. If the class was not found, an empty
 71                      *         SCMOClass is returned.  This can be checked by using the
 72                      *         SCMOClass.isEmpty() method.
 73                      **/
 74                     SCMOClass getSCMOClass(
 75                         const char* nsName,
 76                         Uint32 nsNameLen,
 77                         const char* className,
 78                         Uint32 classNameLen);
 79                 
 80                     /**
 81                      * Removes the named SCMOClass from the cache.
 82                      * @param cimNameSpace The name space name of the SCMOClass to remove.
 83                      * @param cimClassName The class name of the SCMOClass to remove.
 84                      **/
 85                     void removeSCMOClass(CIMNamespaceName cimNameSpace,CIMName cimClassName);
 86                 
 87                     /**
 88                      * Clears the whole cache.
 89 thilo.boehm 1.2      * This should be only done at modification of a class.
 90                      * This may invalidate subclass definitions in the cache.
 91                      * Since class modification is relatively rare, we just flush the entire
 92                      * cache rather than specifically evicting subclass definitions.
 93                      **/
 94                     void clear();
 95                 
 96                     /**
 97                      * Returns the pointer to an instance of SCMOClassCache.
 98                      */
 99                     static SCMOClassCache* getInstance();
100                 
101                     /**
102                      * Set the call back function for the SCMOClass to retrieve CIMClasses.
103                      * @param clb The static call back function.
104                      */
105                     void setCallBack(SCMOClassCacheCallbackPtr clb)
106                     {
107                        _resolveCallBack = clb;
108                     }
109                 
110 thilo.boehm 1.2     static void destroy();
111                 
112                 #ifdef PEGASUS_DEBUG
113                 void DisplayCacheStatistics();
114                 #endif
115                 
116                 private:
117                 
118                     // Singleton instance pointer
119                     static SCMOClassCache* _theInstance;
120                 
121                     // The call back function pointer to get CIMClass's
122                     SCMOClassCacheCallbackPtr _resolveCallBack;
123                 
124                     // The cache array
125                     SCMBClassCacheEntry _theCache[PEGASUS_SCMO_CLASS_CACHE_SIZE];
126                 
127                     // Lock to prevent parallel modifications of the cache.
128                     ReadWriteSem _modifyCacheLock;
129                 
130                     // Last successful read index.
131 thilo.boehm 1.2     Uint32 _lastSuccessIndex;
132                 
133                     // Last successful written cache index.
134                     Uint32 _lastWrittenIndex;
135                 
136                     // Counter of used cache entries.
137                     Uint32 _fillingLevel;
138                 
139                     // Indicator for destruction of the cache.
140                     Boolean _dying;
141                 
142 marek       1.3 #ifdef PEGASUS_DEBUG
143 thilo.boehm 1.2     // Statistical data
144                     Uint32 _cacheReadHit;
145                     Uint32 _cacheReadMiss;
146                     Uint32 _cacheRemoveLRU;
147                     AtomicInt _contentionCount;
148 marek       1.3 #endif
149 thilo.boehm 1.2 
150                     SCMOClassCache()
151                         : _resolveCallBack(NULL),
152                           _lastSuccessIndex(0),
153                           _lastWrittenIndex(PEGASUS_SCMO_CLASS_CACHE_SIZE-1),
154                           _fillingLevel(0),
155                           _dying(false)
156                     {
157                         // intialize the the cache
158                         for (Uint32 i = 0 ; i < PEGASUS_SCMO_CLASS_CACHE_SIZE; i++)
159                         {
160                             _theCache[i].data = 0;
161                             _theCache[i].key = 0;
162                             // set the lock counter to 1 to allow one next user to enter.
163                             _theCache[i].lock.set(1);
164                         }
165 marek       1.3 #ifdef PEGASUS_DEBUG
166 thilo.boehm 1.2         // Statistical data
167                         _cacheReadHit = 0;
168                         _cacheReadMiss = 0;
169                         _cacheRemoveLRU = 0;
170                         _contentionCount.set(0);
171 marek       1.3 #endif
172 thilo.boehm 1.2 
173                     };
174                 
175                     // clean-up cache data
176                     ~SCMOClassCache();
177                 
178                     Uint64 _generateKey(
179                         const char* className,
180                         Uint32 classNameLen,
181                         const char* nameSpaceNameLen,
182                         Uint32 nameSpaceName);
183                 
184                     Boolean _sameSCMOClass(
185                         const char* nsName,
186                         Uint32 nsNameLen,
187                         const char* className,
188                         Uint32 classNameLen,
189                         SCMOClass* theClass);
190                 
191                     SCMOClass _addClassToCache(
192                             const char* nsName,
193 thilo.boehm 1.2             Uint32 nsNameLen,
194                             const char* className,
195                             Uint32 classNameLen,
196                             Uint64 theKey);
197                 
198                 
199                     /**
200                      * Get a lock on a cache entry.
201                      * @return true if the lock was optained
202                      *         false if the lock was NOT optained, give up !!!
203                      **/
204                     Boolean _lockEntry(Uint32 index);
205                 
206                     void _unlockEntry(Uint32 index)
207                     {
208                         // set the lock counter to 1 to allow one next user to enter
209                         // the critical section.
210                         _theCache[index].lock.set(1);
211                 
212                     };
213                 };
214 thilo.boehm 1.2 
215                 PEGASUS_NAMESPACE_END
216                 
217                 #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2