예제 #1
0
파일: pool.hpp 프로젝트: Airphrame/mapnik
    HolderType borrowObject()
    {
#ifdef MAPNIK_THREADSAFE
        mapnik::scoped_lock lock(mutex_);
#endif

        typename ContType::iterator itr=pool_.begin();
        while ( itr!=pool_.end())
        {
            if (!itr->unique())
            {
                ++itr;
            }
            else if ((*itr)->isOK())
            {
                return *itr;
            }
            else
            {
                itr=pool_.erase(itr);
            }
        }
        // all connection have been taken, check if we allowed to grow pool
        if (pool_.size() < maxSize_)
        {
            HolderType conn(creator_());
            if (conn->isOK())
            {
                pool_.push_back(conn);
                return conn;
            }
        }
        return HolderType();
    }
예제 #2
0
         HolderType borrowObject()
         {	
#ifdef MAPNIK_THREADSAFE    
            mutex::scoped_lock lock(mutex_);
#endif
            typename ContType::iterator itr=unusedPool_.begin();
            if (itr!=unusedPool_.end())
            { 
#ifdef MAPNIK_DEBUG
               std::clog<<"borrow "<<(*itr).get()<<"\n";
#endif
               usedPool_.push_back(*itr);
               itr=unusedPool_.erase(itr);
               return usedPool_[usedPool_.size()-1];
            }
            else if (unusedPool_.size() < maxSize_)
            {
               HolderType conn(creator_());
               if (conn->isOK())
               {
                  usedPool_.push_back(conn);
#ifdef MAPNIK_DEBUG
                  std::clog << "create << " << conn.get() << "\n";
#endif
                  return conn;
               }
            }
            return HolderType();
         } 
예제 #3
0
    void returnObject(HolderType obj)
    {
#ifdef MAPNIK_THREADSAFE
        mutex::scoped_lock lock(mutex_);
#endif
        typename ContType::iterator itr=usedPool_.begin();
        while (itr != usedPool_.end())
        {
            if (obj.get()==(*itr).get()) 
            {
#ifdef MAPNIK_DEBUG
                std::clog<<"return "<<(*itr).get()<<"\n";
#endif
                unusedPool_.push_back(*itr);
                usedPool_.erase(itr);
                return;
            }
            ++itr;
        }
    }