diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-12-10 18:28:55 -0500 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-12-10 18:28:55 -0500 |
commit | 294b99aabf3eb96323a3159b7a5e1b4bfc1ff04a (patch) | |
tree | dbb6bfba564d2979c8cebbfebe162a9659dff5aa /libs/pbd/pbd | |
parent | 17707b9674958391949e59a724a264cdcc2d65ff (diff) |
remove file manager LRU cache from code.
This was a very clever attempt to fix a non-problem. If the platform doesn't have enough file descriptors available
then the platform is broken and we're not going to hack around trying to fix it.
Diffstat (limited to 'libs/pbd/pbd')
-rw-r--r-- | libs/pbd/pbd/file_manager.h | 157 | ||||
-rw-r--r-- | libs/pbd/pbd/sndfile_manager.h | 58 |
2 files changed, 0 insertions, 215 deletions
diff --git a/libs/pbd/pbd/file_manager.h b/libs/pbd/pbd/file_manager.h deleted file mode 100644 index d85c88fa46..0000000000 --- a/libs/pbd/pbd/file_manager.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - Copyright (C) 2010 Paul Davis - - 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 2 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef __pbd_file_manager_h__ -#define __pbd_file_manager_h__ - -#include <sys/types.h> -#include <string> -#include <map> -#include <list> -#include <glibmm/threads.h> - -#include "pbd/libpbd_visibility.h" -#include "pbd/signals.h" - -namespace PBD { - -class LIBPBD_API FileManager; - -/** Parent class for FileDescriptors. - * - * When a subclass is instantiated, the file it describes is added to a - * list. The FileDescriptor can be `allocated', meaning that its - * file will be opened on the filesystem, and can then be `released'. - * FileDescriptors are reference counted as they are allocated and - * released. When a descriptor's refcount is 0, the file on the - * filesystem is eligible to be closed if necessary to free up file - * handles for other files. - * - * The upshot of all this is that Ardour can manage the number of - * open files to stay within limits imposed by the operating system. - */ - -class LIBPBD_API FileDescriptor -{ -public: - FileDescriptor (std::string const &, bool); - virtual ~FileDescriptor () {} - - const std::string& path() const { return _path; } - - void release (); - virtual void set_path (const std::string&); - - /** Emitted when the file is closed */ - PBD::Signal0<void> Closed; - -protected: - - friend class FileManager; - - /* These methods and variables must be called / accessed - with a lock held on the FileManager's mutex - */ - - /** @return false on success, true on failure */ - virtual bool open () = 0; - virtual void close () = 0; - virtual bool is_open () const = 0; - - int _refcount; ///< number of active users of this file - double _last_used; ///< monotonic time that this file was last allocated - std::string _path; ///< file path - bool _writeable; ///< true if it should be opened writeable, otherwise false - - FileManager* manager (); - -private: - - static FileManager* _manager; -}; - - -/** FileDescriptor for a file to be opened using POSIX open */ -class LIBPBD_API FdFileDescriptor : public FileDescriptor -{ -public: - FdFileDescriptor (std::string const & file_name, bool writeable, mode_t mode); - ~FdFileDescriptor (); - - int allocate (); - -private: - - friend class FileManager; - - bool open (); - void close (); - bool is_open () const; - - int _fd; ///< file descriptor, or -1 if the file is closed - mode_t _mode; ///< mode to use when creating files -}; - -/** FileDescriptor for a file opened using stdio */ -class LIBPBD_API StdioFileDescriptor : public FileDescriptor -{ -public: - StdioFileDescriptor (std::string const & file_name, std::string const & mode); - ~StdioFileDescriptor (); - - FILE* allocate (); - -private: - - friend class FileManager; - - bool open (); - void close (); - bool is_open () const; - - FILE* _file; - std::string _mode; -}; - - -/** Class to limit the number of files held open */ -class LIBPBD_API FileManager -{ -public: - FileManager (); - - void add (FileDescriptor *); - void remove (FileDescriptor *); - - void release (FileDescriptor *); - bool allocate (FileDescriptor *); - -private: - - void close (FileDescriptor *); - - std::list<FileDescriptor*> _files; ///< files we know about - Glib::Threads::Mutex _mutex; ///< mutex for _files, _open and FileDescriptor contents - int _open; ///< number of open files - int _max_open; ///< maximum number of open files -}; - -} - -#endif diff --git a/libs/pbd/pbd/sndfile_manager.h b/libs/pbd/pbd/sndfile_manager.h deleted file mode 100644 index 7abc8ea3d6..0000000000 --- a/libs/pbd/pbd/sndfile_manager.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - Copyright (C) 2010 Paul Davis - - 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 2 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef __pbd_sndfile_manager_h__ -#define __pbd_sndfile_manager_h__ - -#include <sys/types.h> -#include <string> -#include <map> -#include <sndfile.h> -#include <glibmm/threads.h> - -#include "pbd/libpbd_visibility.h" -#include "pbd/signals.h" -#include "pbd/file_manager.h" - -namespace PBD { - -/** FileDescriptor for a file to be opened using libsndfile */ -class LIBPBD_API SndFileDescriptor : public FileDescriptor -{ -public: - SndFileDescriptor (std::string const & file_name, bool writeable, SF_INFO* info); - ~SndFileDescriptor (); - - SNDFILE* allocate (); - -private: - - friend class FileManager; - - bool open (); - void close (); - bool is_open () const; - - SNDFILE* _sndfile; ///< SNDFILE* pointer, or 0 if the file is closed - SF_INFO* _info; ///< libsndfile's info for this file -}; - -} - -#endif /* __pbd_sndfile_manager_h__ */ |