/[svn]/linuxsampler/trunk/src/common/ResourceManager.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/common/ResourceManager.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1320 by schoenebeck, Wed Feb 7 15:41:31 2007 UTC revision 1321 by schoenebeck, Tue Sep 4 01:12:49 2007 UTC
# Line 112  class ResourceManager { Line 112  class ResourceManager {
112              PERSISTENT     = 2  ///< Immediately create resource and keep it.              PERSISTENT     = 2  ///< Immediately create resource and keep it.
113          };          };
114    
     private:  
115          typedef std::set<ResourceConsumer<T_res>*> ConsumerSet;          typedef std::set<ResourceConsumer<T_res>*> ConsumerSet;
116    
117        private:
118          struct resource_entry_t {          struct resource_entry_t {
119              T_key       key;              T_key       key;
120              T_res*      resource;  ///< pointer to the resource              T_res*      resource;  ///< pointer to the resource
# Line 146  class ResourceManager { Line 147  class ResourceManager {
147          }          }
148    
149          /**          /**
150             * Returns a list of all consumers that use the resource given by
151             * \a Key .
152             *
153             * @e Caution: this is not thread safe! You might want to call
154             * @c Lock() and @c Unlock() respectively to avoid race conditions
155             * while using this method and its result set!
156             *
157             * @param Key - resource identifier
158             */
159            ConsumerSet ConsumersOf(T_key Key) {
160                // search for an entry for the given resource key
161                typename ResourceMap::iterator iterEntry = ResourceEntries.find(Key);
162                return (iterEntry == ResourceEntries.end()) ?
163                       ConsumerSet() : iterEntry->second.consumers;
164            }
165    
166            /**
167             * Returns a list of all consumers that use the resource given by
168             * \a pResource .
169             *
170             * @e Caution: this is not thread safe! You might want to call
171             * @c Lock() and @c Unlock() respectively to avoid race conditions
172             * while using this method and its result set!
173             *
174             * @param pResource - resource pointer
175             */
176            ConsumerSet ConsumersOf(T_res* pResource) {
177                // search for the entry associated with the given resource
178                typename ResourceMap::iterator iter = ResourceEntries.begin();
179                typename ResourceMap::iterator end  = ResourceEntries.end();
180                for (; iter != end; iter++) {
181                    if (iter->second.resource == pResource) { // found entry for resource
182                        return iter->second.consumers;
183                    }
184                }
185                // no entry found for resource ...
186                return ConsumerSet();
187            }
188    
189            /**
190           * Borrow a resource identified by \a Key. The ResourceManager will           * Borrow a resource identified by \a Key. The ResourceManager will
191           * mark the resource as in usage by the consumer given with           * mark the resource as in usage by the consumer given with
192           * \a pConsumer. If the Resource doesn't exist yet it will be           * \a pConsumer. If the Resource doesn't exist yet it will be
# Line 440  class ResourceManager { Line 481  class ResourceManager {
481    
482          /**          /**
483           * Prevent this ResourceManager instance to be used by another           * Prevent this ResourceManager instance to be used by another
484           * thread at the same time. All methods of this class are thread           * thread at the same time. Most methods of this class are thread
485           * safe by default. However sometimes you might need atomicity among           * safe by default. However sometimes you might need atomicity among
486           * a sequence of method calls. In this case you would first call           * a sequence of method calls. In this case you would first call
487           * this Lock() method, call the respective operational methods of           * this Lock() method, call the respective operational methods of
# Line 553  class ResourceManager { Line 594  class ResourceManager {
594              if (bLock) ResourceEntriesMutex.Unlock();              if (bLock) ResourceEntriesMutex.Unlock();
595              return result;              return result;
596          }          }
597    
598            /**
599             * Returns a list with all currently created / "living" resources.
600             * This method should be taken with great care in multi-threaded
601             * scenarios, since the returned resources might be destroyed by a
602             * concurrent HandBack() call.
603             *
604             * @param bLock - use thread safety mechanisms
605             */
606            std::vector<T_res*> Resources(bool bLock = true) {
607                if (bLock) ResourceEntriesMutex.Lock();
608                std::vector<T_res*> result;
609                typename ResourceMap::iterator iter = ResourceEntries.begin();
610                typename ResourceMap::iterator end  = ResourceEntries.end();
611                for (; iter != end; ++iter)
612                    if (iter->second.resource)
613                        result.push_back(iter->second.resource);
614                if (bLock) ResourceEntriesMutex.Unlock();
615                return result;
616            }
617  };  };
618    
619  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.1320  
changed lines
  Added in v.1321

  ViewVC Help
Powered by ViewVC