BasicQueueLinkPool_T.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #ifndef OPENDDS_DCPS_BASICQUEUELINKPOOL_T_H
00009 #define OPENDDS_DCPS_BASICQUEUELINKPOOL_T_H
00010 
00011 #include "BasicQueueLink_T.h"
00012 #include "BasicQueueLinkAllocator_T.h"
00013 #include "ace/Malloc_T.h"
00014 
00015 namespace OpenDDS {
00016 namespace DCPS {
00017 
00018 template <typename T>
00019 class BasicQueueLinkPool {
00020 private:
00021 
00022   typedef BasicQueueLinkAllocator<T> AllocatorType;
00023 
00024 public:
00025 
00026   typedef BasicQueueLink<T> LinkType;
00027 
00028   // TMB: links_per_pool == CHUNK_SIZE in Mike's code
00029   //      num_pools      == 1 in Mike's code.
00030   BasicQueueLinkPool(size_t links_per_pool, size_t num_pools) {
00031     this->allocator_ = new AllocatorType(links_per_pool, num_pools);
00032   }
00033 
00034   ~BasicQueueLinkPool() {
00035     delete this->allocator_;
00036   }
00037 
00038   LinkType* obtain(T* elem) {
00039     LinkType* link;
00040 
00041     ACE_NEW_MALLOC_RETURN(
00042       link,
00043       (LinkType*)this->allocator_->malloc(sizeof(LinkType)),
00044       LinkType(elem),
00045       0);
00046 
00047     return link;
00048   }
00049 
00050   void release(LinkType* link) {
00051     link->reset();
00052     this->allocator_->free(link);
00053   }
00054 
00055 private:
00056 
00057   ACE_Allocator* allocator_;
00058 };
00059 
00060 } // namespace DCPS
00061 } // namespace OpenDDS
00062 
00063 #endif  /* OPENDDS_DCPS_BASICQUEUELINKPOOL_T_H */

Generated on Fri Feb 12 20:05:19 2016 for OpenDDS by  doxygen 1.4.7