Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 236972d825
Fetching contributors…

Cannot retrieve contributors at this time

file 57 lines (47 sloc) 1.996 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
// -*- c++ -*-
// Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef FOLVE_PROCESSOR_POOL_
#define FOLVE_PROCESSOR_POOL_

#include <map>
#include <deque>
#include <string>

#include "util.h"

class SoundProcessor;

// An object pool for SoundProcessors. They are expensive to create, in
// particular on slow machines, but they only change if the configuration
// file is touched. Good candidates for re-use.
class ProcessorPool {
public:
  // Create a processor pool. Stores at most "max_per_config" processors in
  // pool per configuration file.
  ProcessorPool(int max_per_config);

  // Get a new SoundProcesor from this pool with the given configuration.
  // If this isn't possible, NULL is returned an an error message stored in
  // "errmsg".
  SoundProcessor *GetOrCreate(const std::string &base_dir,
                              int sampling_rate, int channels, int bits,
                              std::string *errmsg);

  // Return a processor pack to the pool.
  void Return(SoundProcessor *processor);

private:
  typedef std::deque<SoundProcessor*> ProcessorList;
  typedef std::map<std::string, ProcessorList*> PoolMap;

  SoundProcessor *CheckOutOfPool(const std::string &config_path);

  const size_t max_per_config_;
  folve::Mutex pool_mutex_;
  PoolMap pool_;
};

#endif // FOLVE_PROCESSOR_POOL_
Something went wrong with that request. Please try again.