Handle overlaps better when executing DiffCommands.
[ardour.git] / libs / pbd / file_manager.cc
index 1ababb79bbdbbd413781168679aac9a5114cb499..50f0f2b22d63407a5798fedb07fe2cb71f0d371c 100644 (file)
 #include <cassert>
 #include <iostream>
 #include <cstdio>
+
+#ifdef __APPLE__
+#include <mach/mach_time.h>
+#endif
+
 #include "pbd/compose.h"
 #include "pbd/file_manager.h"
 #include "pbd/debug.h"
@@ -95,24 +100,28 @@ FileManager::allocate (FileDescriptor* d)
                                DEBUG::FileManager,
                                string_compose (
                                        "closed file for %1 to release file handle; now have %2 of %3 open\n",
-                                       (*oldest)->_name, _open, _max_open
+                                       (*oldest)->_path, _open, _max_open
                                        )
                                );
                }
 
                if (d->open ()) {
-                       DEBUG_TRACE (DEBUG::FileManager, string_compose ("open of %1 failed.\n", d->_name));
+                       DEBUG_TRACE (DEBUG::FileManager, string_compose ("open of %1 failed.\n", d->_path));
                        return true;
                }
 
                _open++;
 
-               DEBUG_TRACE (DEBUG::FileManager, string_compose ("opened file for %1; now have %2 of %3 open.\n", d->_name, _open, _max_open));
+               DEBUG_TRACE (DEBUG::FileManager, string_compose ("opened file for %1; now have %2 of %3 open.\n", d->_path, _open, _max_open));
        }
 
+#ifdef __APPLE__
+       d->_last_used = mach_absolute_time();
+#else
        struct timespec t;
        clock_gettime (CLOCK_MONOTONIC, &t);
        d->_last_used = t.tv_sec + (double) t.tv_nsec / 10e9;
+#endif
 
        d->_refcount++;
        
@@ -139,7 +148,7 @@ FileManager::remove (FileDescriptor* d)
                close (d);
                DEBUG_TRACE (
                        DEBUG::FileManager,
-                       string_compose ("closed file for %1; file is being removed; now have %2 of %3 open\n", d->_name, _open, _max_open)
+                       string_compose ("closed file for %1; file is being removed; now have %2 of %3 open\n", d->_path, _open, _max_open)
                        );
        }
 
@@ -159,7 +168,7 @@ FileManager::close (FileDescriptor* d)
 FileDescriptor::FileDescriptor (string const & n, bool w)
        : _refcount (0)
        , _last_used (0)
-       , _name (n)
+       , _path (n)
        , _writeable (w)
 {
 
@@ -215,7 +224,7 @@ FdFileDescriptor::open ()
 {
        /* we must have a lock on the FileManager's mutex */
        
-       _fd = ::open (_name.c_str(), _writeable ? (O_RDWR | O_CREAT) : O_RDONLY, _mode);
+       _fd = ::open (_path.c_str(), _writeable ? (O_RDWR | O_CREAT) : O_RDONLY, _mode);
        return (_fd == -1);
 }
 
@@ -244,6 +253,12 @@ FdFileDescriptor::allocate ()
 }
 
 
+void
+FileDescriptor::set_path (const string& p)
+{
+        _path = p;
+}
+
 /** @param n Filename.
  *  @param w true to open writeable, otherwise false.
  */
@@ -274,7 +289,7 @@ StdioFileDescriptor::open ()
 {
        /* we must have a lock on the FileManager's mutex */
        
-       _file = fopen (_name.c_str(), _mode.c_str());
+       _file = fopen (_path.c_str(), _mode.c_str());
        return (_file == 0);
 }