WIP: deploy new logging flags in backend
This commit is contained in:
parent
16ebdd65b1
commit
65142d9cae
15 changed files with 131 additions and 118 deletions
|
|
@ -19,6 +19,7 @@
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "common/logging.h"
|
||||||
#include "lib/safeclib.h"
|
#include "lib/safeclib.h"
|
||||||
|
|
||||||
#include "backend/backend.h"
|
#include "backend/backend.h"
|
||||||
|
|
@ -31,20 +32,20 @@
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
|
||||||
//NOBUG_DEFINE_FLAG_PARENT (backend, lumiera); TODO
|
//NOBUG_DEFINE_FLAG_PARENT (backend, lumiera); TODO
|
||||||
NOBUG_DEFINE_FLAG (backend);
|
//NOBUG_DEFINE_FLAG (backend);
|
||||||
NOBUG_DEFINE_FLAG_PARENT (file_all, backend);
|
//NOBUG_DEFINE_FLAG_PARENT (file_all, backend);
|
||||||
NOBUG_DEFINE_FLAG_PARENT (filehandle, file_all);
|
//NOBUG_DEFINE_FLAG_PARENT (filehandle, file_all);
|
||||||
|
|
||||||
NOBUG_DEFINE_FLAG_PARENT (mmapings, mmap_all);
|
//NOBUG_DEFINE_FLAG_PARENT (mmapings, mmap_all);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NOBUG_DECLARE_FLAG (file);
|
//NOBUG_DECLARE_FLAG (file);
|
||||||
|
|
||||||
NOBUG_DECLARE_FLAG (mmap_all);
|
//NOBUG_DECLARE_FLAG (mmap_all);
|
||||||
NOBUG_DECLARE_FLAG (mmap);
|
//NOBUG_DECLARE_FLAG (mmap);
|
||||||
NOBUG_DECLARE_FLAG (mmapings);
|
//NOBUG_DECLARE_FLAG (mmapings);
|
||||||
NOBUG_DECLARE_FLAG (mmapcache);
|
//NOBUG_DECLARE_FLAG (mmapcache);
|
||||||
|
|
||||||
|
|
||||||
size_t lumiera_backend_pagesize;
|
size_t lumiera_backend_pagesize;
|
||||||
|
|
@ -52,16 +53,16 @@ size_t lumiera_backend_pagesize;
|
||||||
int
|
int
|
||||||
lumiera_backend_init (void)
|
lumiera_backend_init (void)
|
||||||
{
|
{
|
||||||
NOBUG_INIT_FLAG (backend);
|
//NOBUG_INIT_FLAG (backend);
|
||||||
NOBUG_INIT_FLAG (file_all);
|
//NOBUG_INIT_FLAG (file_all);
|
||||||
NOBUG_INIT_FLAG (file);
|
//NOBUG_INIT_FLAG (file);
|
||||||
NOBUG_INIT_FLAG (filehandle);
|
//NOBUG_INIT_FLAG (filehandle);
|
||||||
NOBUG_INIT_FLAG (mmap_all);
|
//NOBUG_INIT_FLAG (mmap_all);
|
||||||
NOBUG_INIT_FLAG (mmap);
|
//NOBUG_INIT_FLAG (mmap);
|
||||||
NOBUG_INIT_FLAG (mmapings);
|
//NOBUG_INIT_FLAG (mmapings);
|
||||||
NOBUG_INIT_FLAG (mmapcache);
|
//NOBUG_INIT_FLAG (mmapcache);
|
||||||
|
|
||||||
TRACE (backend);
|
TRACE (backend_dbg);
|
||||||
lumiera_filedescriptor_registry_init ();
|
lumiera_filedescriptor_registry_init ();
|
||||||
|
|
||||||
lumiera_backend_pagesize = sysconf(_SC_PAGESIZE);
|
lumiera_backend_pagesize = sysconf(_SC_PAGESIZE);
|
||||||
|
|
@ -107,7 +108,7 @@ lumiera_backend_init (void)
|
||||||
void
|
void
|
||||||
lumiera_backend_destroy (void)
|
lumiera_backend_destroy (void)
|
||||||
{
|
{
|
||||||
TRACE (backend);
|
TRACE (backend_dbg);
|
||||||
lumiera_mmapcache_delete ();
|
lumiera_mmapcache_delete ();
|
||||||
lumiera_filehandlecache_delete ();
|
lumiera_filehandlecache_delete ();
|
||||||
lumiera_filedescriptor_registry_destroy ();
|
lumiera_filedescriptor_registry_destroy ();
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
#include <nobug.h>
|
#include <nobug.h>
|
||||||
|
|
||||||
NOBUG_DECLARE_FLAG (backend);
|
//NOBUG_DECLARE_FLAG (backend);
|
||||||
|
|
||||||
extern size_t lumiera_backend_pagesize;
|
extern size_t lumiera_backend_pagesize;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "common/logging.h"
|
||||||
#include "lib/mutex.h"
|
#include "lib/mutex.h"
|
||||||
#include "lib/safeclib.h"
|
#include "lib/safeclib.h"
|
||||||
|
|
||||||
|
|
@ -28,7 +29,7 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
NOBUG_DEFINE_FLAG_PARENT (file, file_all);
|
//NOBUG_DEFINE_FLAG_PARENT (file, file_all);
|
||||||
|
|
||||||
LUMIERA_ERROR_DEFINE (FILE_CHANGED, "File changed unexpected");
|
LUMIERA_ERROR_DEFINE (FILE_CHANGED, "File changed unexpected");
|
||||||
LUMIERA_ERROR_DEFINE (FILE_NOCHUNKSIZE, "Chunksize not set");
|
LUMIERA_ERROR_DEFINE (FILE_NOCHUNKSIZE, "Chunksize not set");
|
||||||
|
|
@ -37,7 +38,7 @@ LUMIERA_ERROR_DEFINE (FILE_NOCHUNKSIZE, "Chunksize not set");
|
||||||
LumieraFile
|
LumieraFile
|
||||||
lumiera_file_init (LumieraFile self, const char* name, int flags)
|
lumiera_file_init (LumieraFile self, const char* name, int flags)
|
||||||
{
|
{
|
||||||
TRACE (file);
|
TRACE (file_dbg);
|
||||||
|
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
|
|
@ -55,7 +56,7 @@ lumiera_file_init (LumieraFile self, const char* name, int flags)
|
||||||
LumieraFile
|
LumieraFile
|
||||||
lumiera_file_destroy (LumieraFile self)
|
lumiera_file_destroy (LumieraFile self)
|
||||||
{
|
{
|
||||||
TRACE (file);
|
TRACE (file_dbg);
|
||||||
|
|
||||||
lumiera_filedescriptor_release (self->descriptor, self->name, &self->node);
|
lumiera_filedescriptor_release (self->descriptor, self->name, &self->node);
|
||||||
lumiera_free (self->name);
|
lumiera_free (self->name);
|
||||||
|
|
@ -66,7 +67,9 @@ lumiera_file_destroy (LumieraFile self)
|
||||||
LumieraFile
|
LumieraFile
|
||||||
lumiera_file_new (const char* name, int flags)
|
lumiera_file_new (const char* name, int flags)
|
||||||
{
|
{
|
||||||
TRACE (file);
|
TRACE (file_dbg);
|
||||||
|
TRACE (file, "opening file '%s' with flags '%x'", name, flags);
|
||||||
|
|
||||||
LumieraFile self = lumiera_malloc (sizeof (lumiera_file));
|
LumieraFile self = lumiera_malloc (sizeof (lumiera_file));
|
||||||
if (!lumiera_file_init (self, name, flags))
|
if (!lumiera_file_init (self, name, flags))
|
||||||
{
|
{
|
||||||
|
|
@ -80,7 +83,8 @@ lumiera_file_new (const char* name, int flags)
|
||||||
void
|
void
|
||||||
lumiera_file_delete (LumieraFile self)
|
lumiera_file_delete (LumieraFile self)
|
||||||
{
|
{
|
||||||
TRACE (file);
|
TRACE (file_dbg);
|
||||||
|
TRACE (file, "close file '%s'", self->name);
|
||||||
lumiera_free (lumiera_file_destroy (self));
|
lumiera_free (lumiera_file_destroy (self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +92,7 @@ lumiera_file_delete (LumieraFile self)
|
||||||
int
|
int
|
||||||
lumiera_file_handle_acquire (LumieraFile self)
|
lumiera_file_handle_acquire (LumieraFile self)
|
||||||
{
|
{
|
||||||
TRACE (file);
|
TRACE (file_dbg);
|
||||||
REQUIRE (self);
|
REQUIRE (self);
|
||||||
REQUIRE (self->descriptor);
|
REQUIRE (self->descriptor);
|
||||||
REQUIRE (lumiera_fhcache);
|
REQUIRE (lumiera_fhcache);
|
||||||
|
|
@ -100,7 +104,7 @@ lumiera_file_handle_acquire (LumieraFile self)
|
||||||
void
|
void
|
||||||
lumiera_file_handle_release (LumieraFile self)
|
lumiera_file_handle_release (LumieraFile self)
|
||||||
{
|
{
|
||||||
TRACE (file);
|
TRACE (file_dbg);
|
||||||
REQUIRE (self);
|
REQUIRE (self);
|
||||||
REQUIRE (self->descriptor);
|
REQUIRE (self->descriptor);
|
||||||
REQUIRE (lumiera_fhcache);
|
REQUIRE (lumiera_fhcache);
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
#include "lib/llist.h"
|
#include "lib/llist.h"
|
||||||
#include "lib/error.h"
|
#include "lib/error.h"
|
||||||
|
|
||||||
NOBUG_DECLARE_FLAG (file);
|
//NOBUG_DECLARE_FLAG (file);
|
||||||
|
|
||||||
LUMIERA_ERROR_DECLARE(FILE_CHANGED);
|
LUMIERA_ERROR_DECLARE(FILE_CHANGED);
|
||||||
LUMIERA_ERROR_DECLARE(FILE_NOCHUNKSIZE);
|
LUMIERA_ERROR_DECLARE(FILE_NOCHUNKSIZE);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "common/logging.h"
|
||||||
#include "lib/mutex.h"
|
#include "lib/mutex.h"
|
||||||
#include "lib/safeclib.h"
|
#include "lib/safeclib.h"
|
||||||
|
|
||||||
|
|
@ -34,7 +35,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
NOBUG_DEFINE_FLAG_PARENT (filedescriptor, file_all);
|
//NOBUG_DEFINE_FLAG_PARENT (filedescriptor, file_all);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Filedescriptor registry
|
Filedescriptor registry
|
||||||
|
|
@ -89,24 +90,24 @@ key_fn (const PSplaynode node)
|
||||||
void
|
void
|
||||||
lumiera_filedescriptor_registry_init (void)
|
lumiera_filedescriptor_registry_init (void)
|
||||||
{
|
{
|
||||||
NOBUG_INIT_FLAG (filedescriptor);
|
//NOBUG_INIT_FLAG (filedescriptor);
|
||||||
TRACE (filedescriptor);
|
TRACE (filedescriptor_dbg);
|
||||||
REQUIRE (!registry);
|
REQUIRE (!registry);
|
||||||
|
|
||||||
registry = psplay_new (cmp_fn, key_fn, delete_fn);
|
registry = psplay_new (cmp_fn, key_fn, delete_fn);
|
||||||
if (!registry)
|
if (!registry)
|
||||||
LUMIERA_DIE (NO_MEMORY);
|
LUMIERA_DIE (NO_MEMORY);
|
||||||
|
|
||||||
lumiera_mutex_init (®istry_mutex, "filedescriptor_registry", &NOBUG_FLAG (filedescriptor));
|
lumiera_mutex_init (®istry_mutex, "filedescriptor_registry", &NOBUG_FLAG (mutex_dbg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
lumiera_filedescriptor_registry_destroy (void)
|
lumiera_filedescriptor_registry_destroy (void)
|
||||||
{
|
{
|
||||||
TRACE (filedescriptor);
|
TRACE (filedescriptor_dbg);
|
||||||
REQUIRE (!psplay_nelements (registry));
|
REQUIRE (!psplay_nelements (registry));
|
||||||
|
|
||||||
lumiera_mutex_destroy (®istry_mutex, &NOBUG_FLAG (filedescriptor));
|
lumiera_mutex_destroy (®istry_mutex, &NOBUG_FLAG (mutex_dbg));
|
||||||
|
|
||||||
if (registry)
|
if (registry)
|
||||||
psplay_destroy (registry);
|
psplay_destroy (registry);
|
||||||
|
|
@ -117,13 +118,13 @@ lumiera_filedescriptor_registry_destroy (void)
|
||||||
LumieraFiledescriptor
|
LumieraFiledescriptor
|
||||||
lumiera_filedescriptor_acquire (const char* name, int flags, LList filenode)
|
lumiera_filedescriptor_acquire (const char* name, int flags, LList filenode)
|
||||||
{
|
{
|
||||||
TRACE (filedescriptor, "%s", name);
|
TRACE (filedescriptor_dbg, "%s", name);
|
||||||
REQUIRE (registry, "not initialized");
|
REQUIRE (registry, "not initialized");
|
||||||
REQUIRE (llist_is_empty (filenode));
|
REQUIRE (llist_is_empty (filenode));
|
||||||
|
|
||||||
LumieraFiledescriptor dest = NULL;
|
LumieraFiledescriptor dest = NULL;
|
||||||
|
|
||||||
LUMIERA_MUTEX_SECTION (filedescriptor, ®istry_mutex)
|
LUMIERA_MUTEX_SECTION (mutex_sync, ®istry_mutex)
|
||||||
{
|
{
|
||||||
lumiera_filedescriptor fdesc;
|
lumiera_filedescriptor fdesc;
|
||||||
fdesc.flags = flags;
|
fdesc.flags = flags;
|
||||||
|
|
@ -138,28 +139,28 @@ lumiera_filedescriptor_acquire (const char* name, int flags, LList filenode)
|
||||||
while ((slash = strchr (slash+1, '/')))
|
while ((slash = strchr (slash+1, '/')))
|
||||||
{
|
{
|
||||||
*slash = '\0';
|
*slash = '\0';
|
||||||
INFO (filedescriptor, "try creating dir: %s", dir);
|
INFO (filedescriptor_dbg, "try creating dir: %s", dir);
|
||||||
if (mkdir (dir, 0777) == -1 && errno != EEXIST)
|
if (mkdir (dir, 0777) == -1 && errno != EEXIST)
|
||||||
{
|
{
|
||||||
LUMIERA_ERROR_SET_CRITICAL (filedescriptor, ERRNO, name);
|
LUMIERA_ERROR_SET_CRITICAL (file, ERRNO, name);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
*slash = '/';
|
*slash = '/';
|
||||||
}
|
}
|
||||||
int fd;
|
int fd;
|
||||||
INFO (filedescriptor, "try creating file: %s", name);
|
INFO (filedescriptor_dbg, "try creating file: %s", name);
|
||||||
TODO ("creat mode from config");
|
TODO ("creat mode from config");
|
||||||
fd = creat (name, 0666);
|
fd = creat (name, 0666);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
LUMIERA_ERROR_SET_CRITICAL (filedescriptor, ERRNO, name);
|
LUMIERA_ERROR_SET_CRITICAL (file, ERRNO, name);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
close (fd);
|
close (fd);
|
||||||
if (stat (name, &fdesc.stat) != 0)
|
if (stat (name, &fdesc.stat) != 0)
|
||||||
{
|
{
|
||||||
/* finally, no luck */
|
/* finally, no luck */
|
||||||
LUMIERA_ERROR_SET_CRITICAL (filedescriptor, ERRNO, name);
|
LUMIERA_ERROR_SET_CRITICAL (file, ERRNO, name);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -188,10 +189,10 @@ lumiera_filedescriptor_acquire (const char* name, int flags, LList filenode)
|
||||||
void
|
void
|
||||||
lumiera_filedescriptor_release (LumieraFiledescriptor self, const char* name, LList filenode)
|
lumiera_filedescriptor_release (LumieraFiledescriptor self, const char* name, LList filenode)
|
||||||
{
|
{
|
||||||
TRACE (filedescriptor);
|
TRACE (filedescriptor_dbg);
|
||||||
|
|
||||||
if (filenode)
|
if (filenode)
|
||||||
LUMIERA_MUTEX_SECTION (filedescriptor, &self->lock)
|
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
|
||||||
{
|
{
|
||||||
REQUIRE (llist_is_member (&self->files, filenode));
|
REQUIRE (llist_is_member (&self->files, filenode));
|
||||||
llist_unlink (filenode);
|
llist_unlink (filenode);
|
||||||
|
|
@ -205,11 +206,11 @@ lumiera_filedescriptor_release (LumieraFiledescriptor self, const char* name, LL
|
||||||
int
|
int
|
||||||
lumiera_filedescriptor_handle_acquire (LumieraFiledescriptor self)
|
lumiera_filedescriptor_handle_acquire (LumieraFiledescriptor self)
|
||||||
{
|
{
|
||||||
TRACE (filedescriptor);
|
TRACE (filedescriptor_dbg);
|
||||||
|
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
|
|
||||||
LUMIERA_MUTEX_SECTION (filedescriptor, &self->lock)
|
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
|
||||||
{
|
{
|
||||||
if (!self->handle)
|
if (!self->handle)
|
||||||
/* no handle yet, get a new one */
|
/* no handle yet, get a new one */
|
||||||
|
|
@ -227,10 +228,10 @@ lumiera_filedescriptor_handle_acquire (LumieraFiledescriptor self)
|
||||||
void
|
void
|
||||||
lumiera_filedescriptor_handle_release (LumieraFiledescriptor self)
|
lumiera_filedescriptor_handle_release (LumieraFiledescriptor self)
|
||||||
{
|
{
|
||||||
TRACE (filedescriptor);
|
TRACE (filedescriptor_dbg);
|
||||||
REQUIRE (self->handle);
|
REQUIRE (self->handle);
|
||||||
|
|
||||||
LUMIERA_MUTEX_SECTION (filedescriptor, &self->lock)
|
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
|
||||||
lumiera_filehandlecache_checkin (lumiera_fhcache, self->handle);
|
lumiera_filehandlecache_checkin (lumiera_fhcache, self->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -265,7 +266,7 @@ LumieraFiledescriptor
|
||||||
lumiera_filedescriptor_new (LumieraFiledescriptor template)
|
lumiera_filedescriptor_new (LumieraFiledescriptor template)
|
||||||
{
|
{
|
||||||
LumieraFiledescriptor self = lumiera_malloc (sizeof (lumiera_filedescriptor));
|
LumieraFiledescriptor self = lumiera_malloc (sizeof (lumiera_filedescriptor));
|
||||||
TRACE (filedescriptor, "at %p", self);
|
TRACE (filedescriptor_dbg, "at %p", self);
|
||||||
|
|
||||||
psplaynode_init (&self->node);
|
psplaynode_init (&self->node);
|
||||||
self->stat = template->stat;
|
self->stat = template->stat;
|
||||||
|
|
@ -276,7 +277,7 @@ lumiera_filedescriptor_new (LumieraFiledescriptor template)
|
||||||
self->mmapings = NULL;
|
self->mmapings = NULL;
|
||||||
llist_init (&self->files);
|
llist_init (&self->files);
|
||||||
|
|
||||||
lumiera_mutex_init (&self->lock, "filedescriptor", &NOBUG_FLAG (filedescriptor));
|
lumiera_mutex_init (&self->lock, "filedescriptor", &NOBUG_FLAG (mutex_dbg));
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
@ -285,9 +286,9 @@ lumiera_filedescriptor_new (LumieraFiledescriptor template)
|
||||||
void
|
void
|
||||||
lumiera_filedescriptor_delete (LumieraFiledescriptor self, const char* name)
|
lumiera_filedescriptor_delete (LumieraFiledescriptor self, const char* name)
|
||||||
{
|
{
|
||||||
TRACE (filedescriptor, "%p %s", self, name);
|
TRACE (filedescriptor_dbg, "%p %s", self, name);
|
||||||
|
|
||||||
LUMIERA_MUTEX_SECTION (filedescriptor, ®istry_mutex)
|
LUMIERA_MUTEX_SECTION (mutex_sync, ®istry_mutex)
|
||||||
{
|
{
|
||||||
REQUIRE (llist_is_empty (&self->files));
|
REQUIRE (llist_is_empty (&self->files));
|
||||||
|
|
||||||
|
|
@ -297,7 +298,7 @@ lumiera_filedescriptor_delete (LumieraFiledescriptor self, const char* name)
|
||||||
|
|
||||||
if (self->handle && name && ((self->flags & O_RDWR) == O_RDWR))
|
if (self->handle && name && ((self->flags & O_RDWR) == O_RDWR))
|
||||||
{
|
{
|
||||||
TRACE (filedescriptor, "truncate %s to %lld", name, self->realsize);
|
TRACE (filedescriptor_dbg, "truncate %s to %lld", name, self->realsize);
|
||||||
lumiera_filehandlecache_checkout (lumiera_fhcache, self->handle);
|
lumiera_filehandlecache_checkout (lumiera_fhcache, self->handle);
|
||||||
int dummy = ftruncate (lumiera_filehandle_handle (self->handle), self->realsize);
|
int dummy = ftruncate (lumiera_filehandle_handle (self->handle), self->realsize);
|
||||||
(void) dummy; /* this is present to silence a warning */
|
(void) dummy; /* this is present to silence a warning */
|
||||||
|
|
@ -309,7 +310,7 @@ lumiera_filedescriptor_delete (LumieraFiledescriptor self, const char* name)
|
||||||
|
|
||||||
TODO ("release filehandle");
|
TODO ("release filehandle");
|
||||||
|
|
||||||
lumiera_mutex_destroy (&self->lock, &NOBUG_FLAG (filedescriptor));
|
lumiera_mutex_destroy (&self->lock, &NOBUG_FLAG (mutex_dbg));
|
||||||
lumiera_free (self);
|
lumiera_free (self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "common/logging.h"
|
||||||
#include "lib/llist.h"
|
#include "lib/llist.h"
|
||||||
#include "lib/safeclib.h"
|
#include "lib/safeclib.h"
|
||||||
|
|
||||||
|
|
@ -31,7 +32,7 @@
|
||||||
LumieraFilehandle
|
LumieraFilehandle
|
||||||
lumiera_filehandle_init (LumieraFilehandle self, LumieraFiledescriptor desc)
|
lumiera_filehandle_init (LumieraFilehandle self, LumieraFiledescriptor desc)
|
||||||
{
|
{
|
||||||
TRACE (filehandle, "%p", self);
|
TRACE (filehandle_dbg, "%p", self);
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
llist_init (&self->cachenode);
|
llist_init (&self->cachenode);
|
||||||
|
|
@ -54,7 +55,7 @@ lumiera_filehandle_new (LumieraFiledescriptor desc)
|
||||||
void*
|
void*
|
||||||
lumiera_filehandle_destroy_node (LList node)
|
lumiera_filehandle_destroy_node (LList node)
|
||||||
{
|
{
|
||||||
TRACE (filehandle);
|
TRACE (filehandle_dbg);
|
||||||
REQUIRE (llist_is_empty (node));
|
REQUIRE (llist_is_empty (node));
|
||||||
LumieraFilehandle self = (LumieraFilehandle)node;
|
LumieraFilehandle self = (LumieraFilehandle)node;
|
||||||
REQUIRE (self->use_cnt == 0);
|
REQUIRE (self->use_cnt == 0);
|
||||||
|
|
@ -76,7 +77,7 @@ lumiera_filehandle_get (LumieraFilehandle self)
|
||||||
int
|
int
|
||||||
lumiera_filehandle_handle (LumieraFilehandle self)
|
lumiera_filehandle_handle (LumieraFilehandle self)
|
||||||
{
|
{
|
||||||
TRACE (filehandle);
|
TRACE (filehandle_dbg);
|
||||||
|
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
if (self->fd == -1)
|
if (self->fd == -1)
|
||||||
|
|
@ -85,7 +86,7 @@ lumiera_filehandle_handle (LumieraFilehandle self)
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
FIXME ("Handle EMFILE etc with the resourcecollector");
|
FIXME ("Handle EMFILE etc with the resourcecollector");
|
||||||
LUMIERA_ERROR_SET_CRITICAL (filehandle, ERRNO, lumiera_filedescriptor_name (self->descriptor));
|
LUMIERA_ERROR_SET_CRITICAL (file, ERRNO, lumiera_filedescriptor_name (self->descriptor));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -94,14 +95,14 @@ lumiera_filehandle_handle (LumieraFilehandle self)
|
||||||
{
|
{
|
||||||
close (fd);
|
close (fd);
|
||||||
fd = -1;
|
fd = -1;
|
||||||
LUMIERA_ERROR_SET_CRITICAL (filehandle, ERRNO, lumiera_filedescriptor_name (self->descriptor));
|
LUMIERA_ERROR_SET_CRITICAL (file, ERRNO, lumiera_filedescriptor_name (self->descriptor));
|
||||||
}
|
}
|
||||||
else if (!lumiera_filedescriptor_samestat (self->descriptor, &st))
|
else if (!lumiera_filedescriptor_samestat (self->descriptor, &st))
|
||||||
{
|
{
|
||||||
close (fd);
|
close (fd);
|
||||||
fd = -1;
|
fd = -1;
|
||||||
/* Woops this is not the file we expected to use */
|
/* Woops this is not the file we expected to use */
|
||||||
LUMIERA_ERROR_SET_CRITICAL (filehandle, FILE_CHANGED, lumiera_filedescriptor_name (self->descriptor));
|
LUMIERA_ERROR_SET_CRITICAL (file, FILE_CHANGED, lumiera_filedescriptor_name (self->descriptor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self->fd = fd;
|
self->fd = fd;
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ typedef lumiera_filehandle* LumieraFilehandle;
|
||||||
|
|
||||||
#include "backend/filedescriptor.h"
|
#include "backend/filedescriptor.h"
|
||||||
|
|
||||||
NOBUG_DECLARE_FLAG (filehandle);
|
//NOBUG_DECLARE_FLAG (filehandle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,13 @@
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "common/logging.h"
|
||||||
#include "lib/safeclib.h"
|
#include "lib/safeclib.h"
|
||||||
|
|
||||||
#include "backend/file.h"
|
#include "backend/file.h"
|
||||||
#include "backend/filehandlecache.h"
|
#include "backend/filehandlecache.h"
|
||||||
|
|
||||||
NOBUG_DEFINE_FLAG_PARENT (filehandlecache, file_all);
|
//NOBUG_DEFINE_FLAG_PARENT (filehandlecache, file_all);
|
||||||
|
|
||||||
/* errors */
|
/* errors */
|
||||||
|
|
||||||
|
|
@ -39,12 +40,12 @@ lumiera_filehandlecache_new (int max_entries)
|
||||||
{
|
{
|
||||||
REQUIRE (!lumiera_fhcache, "Filehandlecache already initialized");
|
REQUIRE (!lumiera_fhcache, "Filehandlecache already initialized");
|
||||||
|
|
||||||
NOBUG_INIT_FLAG (filehandlecache);
|
//NOBUG_INIT_FLAG (filehandlecache);
|
||||||
lumiera_fhcache = lumiera_malloc (sizeof (lumiera_filehandlecache));
|
lumiera_fhcache = lumiera_malloc (sizeof (lumiera_filehandlecache));
|
||||||
lumiera_mrucache_init (&lumiera_fhcache->cache, lumiera_filehandle_destroy_node);
|
lumiera_mrucache_init (&lumiera_fhcache->cache, lumiera_filehandle_destroy_node);
|
||||||
lumiera_fhcache->available = max_entries;
|
lumiera_fhcache->available = max_entries;
|
||||||
lumiera_fhcache->checked_out = 0;
|
lumiera_fhcache->checked_out = 0;
|
||||||
lumiera_mutex_init (&lumiera_fhcache->lock, "filehandlecache", &NOBUG_FLAG (filehandlecache));
|
lumiera_mutex_init (&lumiera_fhcache->lock, "filehandlecache", &NOBUG_FLAG (mutex_dbg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -55,7 +56,7 @@ lumiera_filehandlecache_delete (void)
|
||||||
{
|
{
|
||||||
REQUIRE (!lumiera_fhcache->checked_out, "Filehandles in use at shutdown");
|
REQUIRE (!lumiera_fhcache->checked_out, "Filehandles in use at shutdown");
|
||||||
lumiera_mrucache_destroy (&lumiera_fhcache->cache);
|
lumiera_mrucache_destroy (&lumiera_fhcache->cache);
|
||||||
lumiera_mutex_destroy (&lumiera_fhcache->lock, &NOBUG_FLAG (filehandlecache));
|
lumiera_mutex_destroy (&lumiera_fhcache->lock, &NOBUG_FLAG (mutex_dbg));
|
||||||
lumiera_free (lumiera_fhcache);
|
lumiera_free (lumiera_fhcache);
|
||||||
lumiera_fhcache = NULL;
|
lumiera_fhcache = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -65,10 +66,10 @@ lumiera_filehandlecache_delete (void)
|
||||||
LumieraFilehandle
|
LumieraFilehandle
|
||||||
lumiera_filehandlecache_handle_acquire (LumieraFilehandlecache self, LumieraFiledescriptor desc)
|
lumiera_filehandlecache_handle_acquire (LumieraFilehandlecache self, LumieraFiledescriptor desc)
|
||||||
{
|
{
|
||||||
TRACE (filehandlecache);
|
TRACE (filehandlecache_dbg);
|
||||||
LumieraFilehandle ret = NULL;
|
LumieraFilehandle ret = NULL;
|
||||||
|
|
||||||
LUMIERA_MUTEX_SECTION (filehandlecache, &self->lock)
|
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
|
||||||
{
|
{
|
||||||
if (self->available <= 0 && self->cache.cached)
|
if (self->available <= 0 && self->cache.cached)
|
||||||
{
|
{
|
||||||
|
|
@ -82,11 +83,11 @@ lumiera_filehandlecache_handle_acquire (LumieraFilehandlecache self, LumieraFile
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* allocate new filehandle if we are below the limit or no cached handles are available (overallocating) */
|
/* allocate new filehandle if we are below the limit or no cached handles are available (overallocating) */
|
||||||
NOTICE (filehandlecache, "overallocating filehandle");
|
NOTICE (file, "overallocating filehandle");
|
||||||
ret = lumiera_filehandle_new (desc);
|
ret = lumiera_filehandle_new (desc);
|
||||||
TODO ("use resourcecollector here");
|
TODO ("use resourcecollector here");
|
||||||
if (!ret)
|
if (!ret)
|
||||||
LUMIERA_ERROR_SET_ALERT (filehandlecache, FILEHANDLECACHE_NOHANDLE, lumiera_filedescriptor_name (desc));
|
LUMIERA_ERROR_SET_ALERT (file, FILEHANDLECACHE_NOHANDLE, lumiera_filedescriptor_name (desc));
|
||||||
else
|
else
|
||||||
--self->available;
|
--self->available;
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +107,7 @@ lumiera_filehandlecache_checkout (LumieraFilehandlecache self, LumieraFilehandle
|
||||||
if (!handle->use_cnt)
|
if (!handle->use_cnt)
|
||||||
{
|
{
|
||||||
/* lock cache and checkout */
|
/* lock cache and checkout */
|
||||||
LUMIERA_MUTEX_SECTION (filehandlecache, &self->lock)
|
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
|
||||||
{
|
{
|
||||||
lumiera_mrucache_checkout (&self->cache, &handle->cachenode);
|
lumiera_mrucache_checkout (&self->cache, &handle->cachenode);
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +130,7 @@ lumiera_filehandlecache_checkin (LumieraFilehandlecache self, LumieraFilehandle
|
||||||
if (!--handle->use_cnt)
|
if (!--handle->use_cnt)
|
||||||
{
|
{
|
||||||
/* lock cache and checin */
|
/* lock cache and checin */
|
||||||
LUMIERA_MUTEX_SECTION (filehandlecache, &self->lock)
|
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
|
||||||
{
|
{
|
||||||
--self->checked_out;
|
--self->checked_out;
|
||||||
lumiera_mrucache_checkin (&self->cache, &handle->cachenode);
|
lumiera_mrucache_checkin (&self->cache, &handle->cachenode);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "common/logging.h"
|
||||||
#include "lib/safeclib.h"
|
#include "lib/safeclib.h"
|
||||||
|
|
||||||
#include "backend/mmap.h"
|
#include "backend/mmap.h"
|
||||||
|
|
@ -34,8 +35,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
NOBUG_DEFINE_FLAG_PARENT (mmap_all, backend);
|
//NOBUG_DEFINE_FLAG_PARENT (mmap_all, backend);
|
||||||
NOBUG_DEFINE_FLAG_PARENT (mmap, mmap_all);
|
//NOBUG_DEFINE_FLAG_PARENT (mmap, mmap_all);
|
||||||
|
|
||||||
|
|
||||||
LUMIERA_ERROR_DEFINE (MMAP_NWRITE, "Backing file not writable");
|
LUMIERA_ERROR_DEFINE (MMAP_NWRITE, "Backing file not writable");
|
||||||
|
|
@ -51,7 +52,7 @@ LUMIERA_ERROR_DEFINE (MMAP_SPACE, "Address space exhausted");
|
||||||
LumieraMMap
|
LumieraMMap
|
||||||
lumiera_mmap_init (LumieraMMap self, LumieraFile file, off_t start, size_t size)
|
lumiera_mmap_init (LumieraMMap self, LumieraFile file, off_t start, size_t size)
|
||||||
{
|
{
|
||||||
TRACE (mmap);
|
TRACE (mmap_dbg);
|
||||||
|
|
||||||
REQUIRE (self);
|
REQUIRE (self);
|
||||||
REQUIRE (file);
|
REQUIRE (file);
|
||||||
|
|
@ -80,7 +81,7 @@ lumiera_mmap_init (LumieraMMap self, LumieraFile file, off_t start, size_t size)
|
||||||
LumieraFiledescriptor descriptor = file->descriptor;
|
LumieraFiledescriptor descriptor = file->descriptor;
|
||||||
|
|
||||||
int fd = lumiera_file_handle_acquire (file);
|
int fd = lumiera_file_handle_acquire (file);
|
||||||
TRACE (mmap, "got fd %d", fd);
|
TRACE (mmap_dbg, "got fd %d", fd);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
goto efile;
|
goto efile;
|
||||||
|
|
||||||
|
|
@ -128,7 +129,7 @@ lumiera_mmap_init (LumieraMMap self, LumieraFile file, off_t start, size_t size)
|
||||||
switch (strategy++)
|
switch (strategy++)
|
||||||
{
|
{
|
||||||
case FIRST_TRY:
|
case FIRST_TRY:
|
||||||
TRACE (mmap, "FIRST_TRY");
|
TRACE (mmap_dbg, "FIRST_TRY");
|
||||||
/* align begin and end to chunk boundaries */
|
/* align begin and end to chunk boundaries */
|
||||||
begin = start & ~(chunksize-1);
|
begin = start & ~(chunksize-1);
|
||||||
length = ((start+size+chunksize-1) & ~(chunksize-1)) - begin;
|
length = ((start+size+chunksize-1) & ~(chunksize-1)) - begin;
|
||||||
|
|
@ -159,17 +160,17 @@ lumiera_mmap_init (LumieraMMap self, LumieraFile file, off_t start, size_t size)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DROP_FROM_CACHE:
|
case DROP_FROM_CACHE:
|
||||||
TRACE (mmap, "drop a mapping from cache");
|
TRACE (mmap_dbg, "drop a mapping from cache");
|
||||||
UNIMPLEMENTED ("mmap cache drop");
|
UNIMPLEMENTED ("mmap cache drop");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REDUCE_WINDOW:
|
case REDUCE_WINDOW:
|
||||||
NOTICE (mmap, "mmaping window reduced to NN MB");
|
NOTICE (mmap_dbg, "mmaping window reduced to NN MB");
|
||||||
UNIMPLEMENTED ("mmap window reduce");
|
UNIMPLEMENTED ("mmap window reduce");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REDUCE_IN_USE:
|
case REDUCE_IN_USE:
|
||||||
NOTICE (mmap, "reduce mmapings in use");
|
NOTICE (mmap_dbg, "reduce mmapings in use");
|
||||||
UNIMPLEMENTED ("mmapings in use reduce");
|
UNIMPLEMENTED ("mmapings in use reduce");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -185,7 +186,7 @@ lumiera_mmap_init (LumieraMMap self, LumieraFile file, off_t start, size_t size)
|
||||||
fd,
|
fd,
|
||||||
begin);
|
begin);
|
||||||
|
|
||||||
INFO_IF (addr==(void*)-1, mmap, "mmap failed %s", strerror (errno));
|
INFO_IF (addr==(void*)-1, mmap_dbg, "mmap failed %s", strerror (errno));
|
||||||
ENSURE (errno == 0 || errno == ENOMEM, "unexpected mmap error %s", strerror (errno));
|
ENSURE (errno == 0 || errno == ENOMEM, "unexpected mmap error %s", strerror (errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -213,7 +214,7 @@ lumiera_mmap_init (LumieraMMap self, LumieraFile file, off_t start, size_t size)
|
||||||
LumieraMMap
|
LumieraMMap
|
||||||
lumiera_mmap_new (LumieraFile file, off_t start, size_t size)
|
lumiera_mmap_new (LumieraFile file, off_t start, size_t size)
|
||||||
{
|
{
|
||||||
TRACE (mmap);
|
TRACE (mmap_dbg);
|
||||||
|
|
||||||
LumieraMMap self = lumiera_mmapcache_mmap_acquire (lumiera_mcache);
|
LumieraMMap self = lumiera_mmapcache_mmap_acquire (lumiera_mcache);
|
||||||
|
|
||||||
|
|
@ -230,7 +231,7 @@ lumiera_mmap_new (LumieraFile file, off_t start, size_t size)
|
||||||
void
|
void
|
||||||
lumiera_mmap_delete (LumieraMMap self)
|
lumiera_mmap_delete (LumieraMMap self)
|
||||||
{
|
{
|
||||||
TRACE (mmap);
|
TRACE (mmap_dbg);
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
lumiera_mmapcache_forget (lumiera_mcache, self);
|
lumiera_mmapcache_forget (lumiera_mcache, self);
|
||||||
|
|
@ -238,7 +239,7 @@ lumiera_mmap_delete (LumieraMMap self)
|
||||||
/* The matching mappings->lock must be hold or being irrelevant (mappings destructor) here, we can't asset this from here, good luck */
|
/* The matching mappings->lock must be hold or being irrelevant (mappings destructor) here, we can't asset this from here, good luck */
|
||||||
llist_unlink (&self->searchnode);
|
llist_unlink (&self->searchnode);
|
||||||
|
|
||||||
TRACE (mmap, "unmap at %p with size %zd", self->address, self->size);
|
TRACE (mmap_dbg, "unmap at %p with size %zd", self->address, self->size);
|
||||||
munmap (self->address, self->size);
|
munmap (self->address, self->size);
|
||||||
lumiera_free (self->refmap);
|
lumiera_free (self->refmap);
|
||||||
lumiera_free (self);
|
lumiera_free (self);
|
||||||
|
|
@ -249,7 +250,7 @@ lumiera_mmap_delete (LumieraMMap self)
|
||||||
void*
|
void*
|
||||||
lumiera_mmap_destroy_node (LList node)
|
lumiera_mmap_destroy_node (LList node)
|
||||||
{
|
{
|
||||||
TRACE (mmap);
|
TRACE (mmap_dbg);
|
||||||
REQUIRE (llist_is_empty (node));
|
REQUIRE (llist_is_empty (node));
|
||||||
LumieraMMap self = (LumieraMMap)node;
|
LumieraMMap self = (LumieraMMap)node;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ typedef lumiera_mmap* LumieraMMap;
|
||||||
#include <nobug.h>
|
#include <nobug.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
NOBUG_DECLARE_FLAG (mmap);
|
//NOBUG_DECLARE_FLAG (mmap);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "common/logging.h"
|
||||||
#include "lib/safeclib.h"
|
#include "lib/safeclib.h"
|
||||||
|
|
||||||
#include "backend/mmapcache.h"
|
#include "backend/mmapcache.h"
|
||||||
|
|
@ -28,7 +29,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
NOBUG_DEFINE_FLAG_PARENT (mmapcache, mmap_all);
|
//NOBUG_DEFINE_FLAG_PARENT (mmapcache, mmap_all);
|
||||||
|
|
||||||
LumieraMMapcache lumiera_mcache = NULL;
|
LumieraMMapcache lumiera_mcache = NULL;
|
||||||
|
|
||||||
|
|
@ -36,7 +37,7 @@ LumieraMMapcache lumiera_mcache = NULL;
|
||||||
void
|
void
|
||||||
lumiera_mmapcache_new (size_t limit)
|
lumiera_mmapcache_new (size_t limit)
|
||||||
{
|
{
|
||||||
TRACE (mmapcache);
|
TRACE (mmapcache_dbg);
|
||||||
lumiera_mcache = lumiera_malloc (sizeof (*lumiera_mcache));
|
lumiera_mcache = lumiera_malloc (sizeof (*lumiera_mcache));
|
||||||
|
|
||||||
lumiera_mrucache_init (&lumiera_mcache->cache, lumiera_mmap_destroy_node);
|
lumiera_mrucache_init (&lumiera_mcache->cache, lumiera_mmap_destroy_node);
|
||||||
|
|
@ -45,19 +46,19 @@ lumiera_mmapcache_new (size_t limit)
|
||||||
lumiera_mcache->total = 0;
|
lumiera_mcache->total = 0;
|
||||||
lumiera_mcache->cached = 0;
|
lumiera_mcache->cached = 0;
|
||||||
|
|
||||||
lumiera_mutex_init (&lumiera_mcache->lock, "mmapcache", &NOBUG_FLAG (mmapcache));
|
lumiera_mutex_init (&lumiera_mcache->lock, "mmapcache", &NOBUG_FLAG (mutex_dbg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
lumiera_mmapcache_delete (void)
|
lumiera_mmapcache_delete (void)
|
||||||
{
|
{
|
||||||
TRACE (mmapcache);
|
TRACE (mmapcache_dbg);
|
||||||
if (lumiera_mcache)
|
if (lumiera_mcache)
|
||||||
{
|
{
|
||||||
REQUIRE (lumiera_mcache->total == lumiera_mcache->cached, "MMaps still checked out at shutdown");
|
REQUIRE (lumiera_mcache->total == lumiera_mcache->cached, "MMaps still checked out at shutdown");
|
||||||
lumiera_mrucache_destroy (&lumiera_mcache->cache);
|
lumiera_mrucache_destroy (&lumiera_mcache->cache);
|
||||||
lumiera_mutex_destroy (&lumiera_mcache->lock, &NOBUG_FLAG (mmapcache));
|
lumiera_mutex_destroy (&lumiera_mcache->lock, &NOBUG_FLAG (mutex_dbg));
|
||||||
free (lumiera_mcache);
|
free (lumiera_mcache);
|
||||||
lumiera_mcache = NULL;
|
lumiera_mcache = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -67,10 +68,10 @@ lumiera_mmapcache_delete (void)
|
||||||
void*
|
void*
|
||||||
lumiera_mmapcache_mmap_acquire (LumieraMMapcache self)
|
lumiera_mmapcache_mmap_acquire (LumieraMMapcache self)
|
||||||
{
|
{
|
||||||
TRACE (mmapcache);
|
TRACE (mmapcache_dbg);
|
||||||
void* map = NULL;
|
void* map = NULL;
|
||||||
|
|
||||||
LUMIERA_MUTEX_SECTION (mmapcache, &self->lock)
|
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
|
||||||
{
|
{
|
||||||
map = lumiera_mrucache_pop (&self->cache);
|
map = lumiera_mrucache_pop (&self->cache);
|
||||||
}
|
}
|
||||||
|
|
@ -78,11 +79,11 @@ lumiera_mmapcache_mmap_acquire (LumieraMMapcache self)
|
||||||
if (!map)
|
if (!map)
|
||||||
{
|
{
|
||||||
map = lumiera_malloc (sizeof (*self));
|
map = lumiera_malloc (sizeof (*self));
|
||||||
TRACE (mmapcache, "allocated new mmap");
|
TRACE (mmapcache_dbg, "allocated new mmap");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TRACE (mmapcache, "poped mmap from cache");
|
TRACE (mmapcache_dbg, "poped mmap from cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
|
|
@ -92,8 +93,8 @@ lumiera_mmapcache_mmap_acquire (LumieraMMapcache self)
|
||||||
void
|
void
|
||||||
lumiera_mmapcache_announce (LumieraMMapcache self, LumieraMMap map)
|
lumiera_mmapcache_announce (LumieraMMapcache self, LumieraMMap map)
|
||||||
{
|
{
|
||||||
TRACE (mmapcache);
|
TRACE (mmapcache_dbg);
|
||||||
LUMIERA_MUTEX_SECTION (mmapcache, &self->lock)
|
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
|
||||||
{
|
{
|
||||||
self->total += map->size;
|
self->total += map->size;
|
||||||
}
|
}
|
||||||
|
|
@ -103,8 +104,8 @@ lumiera_mmapcache_announce (LumieraMMapcache self, LumieraMMap map)
|
||||||
void
|
void
|
||||||
lumiera_mmapcache_forget (LumieraMMapcache self, LumieraMMap map)
|
lumiera_mmapcache_forget (LumieraMMapcache self, LumieraMMap map)
|
||||||
{
|
{
|
||||||
TRACE (mmapcache);
|
TRACE (mmapcache_dbg);
|
||||||
LUMIERA_MUTEX_SECTION (mmapcache, &self->lock)
|
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
|
||||||
{
|
{
|
||||||
if (!llist_is_empty (&map->cachenode))
|
if (!llist_is_empty (&map->cachenode))
|
||||||
{
|
{
|
||||||
|
|
@ -120,7 +121,7 @@ lumiera_mmapcache_forget (LumieraMMapcache self, LumieraMMap map)
|
||||||
int
|
int
|
||||||
lumiera_mmapcache_age (LumieraMMapcache self)
|
lumiera_mmapcache_age (LumieraMMapcache self)
|
||||||
{
|
{
|
||||||
TRACE (mmapcache);
|
TRACE (mmapcache_dbg);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
LUMIERA_MUTEX_SECTION (mmapcache, &self->lock)
|
LUMIERA_MUTEX_SECTION (mmapcache, &self->lock)
|
||||||
|
|
@ -135,9 +136,9 @@ lumiera_mmapcache_age (LumieraMMapcache self)
|
||||||
LumieraMMap
|
LumieraMMap
|
||||||
lumiera_mmapcache_checkout (LumieraMMapcache self, LumieraMMap handle)
|
lumiera_mmapcache_checkout (LumieraMMapcache self, LumieraMMap handle)
|
||||||
{
|
{
|
||||||
TRACE (mmapcache);
|
TRACE (mmapcache_dbg);
|
||||||
|
|
||||||
LUMIERA_MUTEX_SECTION (mmapcache, &self->lock)
|
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
|
||||||
{
|
{
|
||||||
TODO ("cached stats");
|
TODO ("cached stats");
|
||||||
lumiera_mrucache_checkout (&self->cache, &handle->cachenode);
|
lumiera_mrucache_checkout (&self->cache, &handle->cachenode);
|
||||||
|
|
@ -151,9 +152,9 @@ lumiera_mmapcache_checkout (LumieraMMapcache self, LumieraMMap handle)
|
||||||
void
|
void
|
||||||
lumiera_mmapcache_checkin (LumieraMMapcache self, LumieraMMap handle)
|
lumiera_mmapcache_checkin (LumieraMMapcache self, LumieraMMap handle)
|
||||||
{
|
{
|
||||||
TRACE (mmapcache);
|
TRACE (mmapcache_dbg);
|
||||||
|
|
||||||
LUMIERA_MUTEX_SECTION (mmapcache, &self->lock)
|
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
|
||||||
{
|
{
|
||||||
TODO ("cached stats");
|
TODO ("cached stats");
|
||||||
--handle->refcnt;
|
--handle->refcnt;
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "common/logging.h"
|
||||||
#include "lib/mutex.h"
|
#include "lib/mutex.h"
|
||||||
#include "lib/safeclib.h"
|
#include "lib/safeclib.h"
|
||||||
|
|
||||||
|
|
@ -36,14 +37,14 @@
|
||||||
LumieraMMapings
|
LumieraMMapings
|
||||||
lumiera_mmapings_init (LumieraMMapings self, LumieraFile file, size_t chunksize)
|
lumiera_mmapings_init (LumieraMMapings self, LumieraFile file, size_t chunksize)
|
||||||
{
|
{
|
||||||
TRACE (mmapings);
|
TRACE (mmapings_dbg);
|
||||||
REQUIRE (!file->descriptor->mmapings);
|
REQUIRE (!file->descriptor->mmapings);
|
||||||
|
|
||||||
llist_init (&self->mmaps);
|
llist_init (&self->mmaps);
|
||||||
self->descriptor = file->descriptor;
|
self->descriptor = file->descriptor;
|
||||||
self->chunksize = chunksize;
|
self->chunksize = chunksize;
|
||||||
|
|
||||||
lumiera_mutex_init (&self->lock, "mmapings", &NOBUG_FLAG(mmapings));
|
lumiera_mutex_init (&self->lock, "mmapings", &NOBUG_FLAG(mutex_dbg));
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
@ -52,7 +53,7 @@ lumiera_mmapings_init (LumieraMMapings self, LumieraFile file, size_t chunksize)
|
||||||
LumieraMMapings
|
LumieraMMapings
|
||||||
lumiera_mmapings_destroy (LumieraMMapings self)
|
lumiera_mmapings_destroy (LumieraMMapings self)
|
||||||
{
|
{
|
||||||
TRACE (mmapings);
|
TRACE (mmapings_dbg);
|
||||||
if (!self)
|
if (!self)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
@ -62,7 +63,7 @@ lumiera_mmapings_destroy (LumieraMMapings self)
|
||||||
lumiera_mmap_delete (mmap);
|
lumiera_mmap_delete (mmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
lumiera_mutex_destroy (&self->lock, &NOBUG_FLAG(mmapings));
|
lumiera_mutex_destroy (&self->lock, &NOBUG_FLAG(mutex_dbg));
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
@ -71,6 +72,7 @@ lumiera_mmapings_destroy (LumieraMMapings self)
|
||||||
LumieraMMapings
|
LumieraMMapings
|
||||||
lumiera_mmapings_new (LumieraFile file, size_t chunksize)
|
lumiera_mmapings_new (LumieraFile file, size_t chunksize)
|
||||||
{
|
{
|
||||||
|
TRACE (mmapings_dbg);
|
||||||
LumieraMMapings self = lumiera_malloc (sizeof (*self));
|
LumieraMMapings self = lumiera_malloc (sizeof (*self));
|
||||||
return lumiera_mmapings_init (self, file, chunksize);
|
return lumiera_mmapings_init (self, file, chunksize);
|
||||||
}
|
}
|
||||||
|
|
@ -79,7 +81,7 @@ lumiera_mmapings_new (LumieraFile file, size_t chunksize)
|
||||||
void
|
void
|
||||||
lumiera_mmapings_delete (LumieraMMapings self)
|
lumiera_mmapings_delete (LumieraMMapings self)
|
||||||
{
|
{
|
||||||
TRACE (mmapings);
|
TRACE (mmapings_dbg);
|
||||||
free (lumiera_mmapings_destroy (self));
|
free (lumiera_mmapings_destroy (self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,11 +89,11 @@ lumiera_mmapings_delete (LumieraMMapings self)
|
||||||
LumieraMMap
|
LumieraMMap
|
||||||
lumiera_mmapings_mmap_acquire (LumieraMMapings self, LumieraFile file, LList acquirer, off_t start, size_t size)
|
lumiera_mmapings_mmap_acquire (LumieraMMapings self, LumieraFile file, LList acquirer, off_t start, size_t size)
|
||||||
{
|
{
|
||||||
TRACE (mmapings);
|
TRACE (mmapings_dbg);
|
||||||
|
|
||||||
LumieraMMap ret = NULL;
|
LumieraMMap ret = NULL;
|
||||||
|
|
||||||
LUMIERA_MUTEX_SECTION (mmapings, &self->lock)
|
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
|
||||||
{
|
{
|
||||||
REQUIRE (llist_is_empty (acquirer));
|
REQUIRE (llist_is_empty (acquirer));
|
||||||
|
|
||||||
|
|
@ -119,7 +121,7 @@ lumiera_mmapings_mmap_acquire (LumieraMMapings self, LumieraFile file, LList acq
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* create new mmap */
|
/* create new mmap */
|
||||||
TRACE (mmapings, "mmap not found, creating", mmap);
|
TRACE (mmapings_dbg, "mmap not found, creating", mmap);
|
||||||
ret = lumiera_mmap_new (file, start, size);
|
ret = lumiera_mmap_new (file, start, size);
|
||||||
|
|
||||||
llist_insert_head (&self->mmaps, &ret->searchnode);
|
llist_insert_head (&self->mmaps, &ret->searchnode);
|
||||||
|
|
@ -137,13 +139,14 @@ lumiera_mmapings_mmap_acquire (LumieraMMapings self, LumieraFile file, LList acq
|
||||||
void
|
void
|
||||||
lumiera_mmapings_release_mmap (LumieraMMapings self, LList acquirer, LumieraMMap map)
|
lumiera_mmapings_release_mmap (LumieraMMapings self, LList acquirer, LumieraMMap map)
|
||||||
{
|
{
|
||||||
TRACE (mmapings);
|
TRACE (mmapings_dbg);
|
||||||
LUMIERA_MUTEX_SECTION (mmapings, &self->lock)
|
|
||||||
|
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
|
||||||
{
|
{
|
||||||
llist_unlink (acquirer);
|
llist_unlink (acquirer);
|
||||||
if (llist_is_empty (&map->cachenode))
|
if (llist_is_empty (&map->cachenode))
|
||||||
{
|
{
|
||||||
TRACE (mmapings, "checkin");
|
TRACE (mmapcache_dbg, "checkin");
|
||||||
lumiera_mmapcache_checkin (lumiera_mcache, map);
|
lumiera_mmapcache_checkin (lumiera_mcache, map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ typedef lumiera_mmapings* LumieraMMapings;
|
||||||
|
|
||||||
#include <nobug.h>
|
#include <nobug.h>
|
||||||
|
|
||||||
NOBUG_DECLARE_FLAG (mmapings);
|
//NOBUG_DECLARE_FLAG (mmapings);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
#define LIB_THREADWRAPPER_H
|
#define LIB_THREADWRAPPER_H
|
||||||
|
|
||||||
|
|
||||||
#include "include/nobugcfg.h"
|
#include "common/logging.h"
|
||||||
#include "lib/sync.hpp"
|
#include "lib/sync.hpp"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
@ -74,7 +74,7 @@ namespace lib {
|
||||||
static void
|
static void
|
||||||
run (void* arg)
|
run (void* arg)
|
||||||
{
|
{
|
||||||
ASSERT (arg);
|
REQUIRE (arg);
|
||||||
Thread* startingWrapper = reinterpret_cast<Thread*>(arg);
|
Thread* startingWrapper = reinterpret_cast<Thread*>(arg);
|
||||||
Operation _doIt_(startingWrapper->operation_);
|
Operation _doIt_(startingWrapper->operation_);
|
||||||
{
|
{
|
||||||
|
|
@ -88,7 +88,7 @@ namespace lib {
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Thread (Literal& purpose, Operation const& operation, struct nobug_flag *logging_flag = &NOBUG_FLAG(operate))
|
Thread (Literal& purpose, Operation const& operation, struct nobug_flag *logging_flag = &NOBUG_FLAG(thread))
|
||||||
: started_(false),
|
: started_(false),
|
||||||
operation_(operation)
|
operation_(operation)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
NOBUG_DEFINE_FLAG_PARENT (threads, lumiera); /*TODO insert a suitable/better parent flag here */
|
//NOBUG_DEFINE_FLAG_PARENT (threads, lumiera); /*TODO insert a suitable/better parent flag here */
|
||||||
|
|
||||||
|
|
||||||
//code goes here//
|
//code goes here//
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue