projects
/
ardour.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix and improve MTC-slave
[ardour.git]
/
libs
/
pbd
/
file_manager.cc
diff --git
a/libs/pbd/file_manager.cc
b/libs/pbd/file_manager.cc
index 1ababb79bbdbbd413781168679aac9a5114cb499..a71ffca190259be5c24c66706d95bd6da7694e19 100644
(file)
--- a/
libs/pbd/file_manager.cc
+++ b/
libs/pbd/file_manager.cc
@@
-23,8
+23,12
@@
#include <sys/stat.h>
#include <fcntl.h>
#include <cassert>
#include <sys/stat.h>
#include <fcntl.h>
#include <cassert>
-#include <iostream>
#include <cstdio>
#include <cstdio>
+
+#ifdef __APPLE__
+#include <mach/mach_time.h>
+#endif
+
#include "pbd/compose.h"
#include "pbd/file_manager.h"
#include "pbd/debug.h"
#include "pbd/compose.h"
#include "pbd/file_manager.h"
#include "pbd/debug.h"
@@
-53,7
+57,7
@@
FileManager::FileManager ()
void
FileManager::add (FileDescriptor* d)
{
void
FileManager::add (FileDescriptor* d)
{
- Glib::Mutex::Lock lm (_mutex);
+ Glib::
Threads::
Mutex::Lock lm (_mutex);
_files.push_back (d);
}
_files.push_back (d);
}
@@
-61,7
+65,7
@@
FileManager::add (FileDescriptor* d)
bool
FileManager::allocate (FileDescriptor* d)
{
bool
FileManager::allocate (FileDescriptor* d)
{
- Glib::Mutex::Lock lm (_mutex);
+ Glib::
Threads::
Mutex::Lock lm (_mutex);
if (!d->is_open()) {
if (!d->is_open()) {
@@
-95,24
+99,28
@@
FileManager::allocate (FileDescriptor* d)
DEBUG::FileManager,
string_compose (
"closed file for %1 to release file handle; now have %2 of %3 open\n",
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 ()) {
)
);
}
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++;
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;
struct timespec t;
clock_gettime (CLOCK_MONOTONIC, &t);
d->_last_used = t.tv_sec + (double) t.tv_nsec / 10e9;
+#endif
d->_refcount++;
d->_refcount++;
@@
-123,7
+131,7
@@
FileManager::allocate (FileDescriptor* d)
void
FileManager::release (FileDescriptor* d)
{
void
FileManager::release (FileDescriptor* d)
{
- Glib::Mutex::Lock lm (_mutex);
+ Glib::
Threads::
Mutex::Lock lm (_mutex);
d->_refcount--;
assert (d->_refcount >= 0);
d->_refcount--;
assert (d->_refcount >= 0);
@@
-133,13
+141,13
@@
FileManager::release (FileDescriptor* d)
void
FileManager::remove (FileDescriptor* d)
{
void
FileManager::remove (FileDescriptor* d)
{
- Glib::Mutex::Lock lm (_mutex);
+ Glib::
Threads::
Mutex::Lock lm (_mutex);
if (d->is_open ()) {
close (d);
DEBUG_TRACE (
DEBUG::FileManager,
if (d->is_open ()) {
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
+167,7
@@
FileManager::close (FileDescriptor* d)
FileDescriptor::FileDescriptor (string const & n, bool w)
: _refcount (0)
, _last_used (0)
FileDescriptor::FileDescriptor (string const & n, bool w)
: _refcount (0)
, _last_used (0)
- , _
name
(n)
+ , _
path
(n)
, _writeable (w)
{
, _writeable (w)
{
@@
-184,15
+192,15
@@
FileDescriptor::release ()
-/** @param
n
Filename.
- * @param w true to open writeable, otherwise false.
- * @param m Open mode for the file.
+/** @param
file_name
Filename.
+ * @param w
riteable
true to open writeable, otherwise false.
+ * @param m
ode
Open mode for the file.
*/
*/
-FdFileDescriptor::FdFileDescriptor (string const &
n, bool w, mode_t m
)
- : FileDescriptor (
n, w
)
+FdFileDescriptor::FdFileDescriptor (string const &
file_name, bool writeable, mode_t mode
)
+ : FileDescriptor (
file_name, writeable
)
, _fd (-1)
, _fd (-1)
- , _mode (m)
+ , _mode (m
ode
)
{
manager()->add (this);
}
{
manager()->add (this);
}
@@
-215,7
+223,7
@@
FdFileDescriptor::open ()
{
/* we must have a lock on the FileManager's mutex */
{
/* 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);
}
return (_fd == -1);
}
@@
-244,14
+252,20
@@
FdFileDescriptor::allocate ()
}
}
-/** @param n Filename.
- * @param w true to open writeable, otherwise false.
+void
+FileDescriptor::set_path (const string& p)
+{
+ _path = p;
+}
+
+/** @param file_name Filename.
+ * @param mode Mode to pass to fopen.
*/
*/
-StdioFileDescriptor::StdioFileDescriptor (string const &
n, std::string const & m
)
- : FileDescriptor (
n
, false)
+StdioFileDescriptor::StdioFileDescriptor (string const &
file_name, std::string const & mode
)
+ : FileDescriptor (
file_name
, false)
, _file (0)
, _file (0)
- , _mode (m)
+ , _mode (m
ode
)
{
manager()->add (this);
}
{
manager()->add (this);
}
@@
-274,7
+288,7
@@
StdioFileDescriptor::open ()
{
/* we must have a lock on the FileManager's mutex */
{
/* 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);
}
return (_file == 0);
}