BRL-CAD
Collaboration diagram for Memory-mapped Files:

Files

file  mappedfile.c
 

Data Structures

struct  bu_mapped_file
 

Macros

#define BU_MAPPED_FILE_NULL   ((struct bu_mapped_file *)0)
 
#define BU_CK_MAPPED_FILE(_mf)   BU_CKMAG(_mf, BU_MAPPED_FILE_MAGIC, "bu_mapped_file")
 
#define BU_MAPPED_FILE_INIT(_mf)
 
#define BU_MAPPED_FILE_INIT_ZERO   { {BU_MAPPED_FILE_MAGIC, BU_LIST_NULL, BU_LIST_NULL}, NULL, NULL, 0, 0, NULL, NULL, 0, 0, 0, 0 }
 
#define BU_MAPPED_FILE_IS_INITIALIZED(_hp)   (((struct bu_mapped_file *)(_hp) != BU_MAPPED_FILE_NULL) && LIKELY((_hp)->l.magic == BU_MAPPED_FILE_MAGIC))
 

Typedefs

typedef struct bu_mapped_file bu_mapped_file_t
 

Functions

struct bu_mapped_filebu_open_mapped_file (const char *name, const char *appl)
 
void bu_close_mapped_file (struct bu_mapped_file *mp)
 
void bu_pr_mapped_file (const char *title, const struct bu_mapped_file *mp)
 
void bu_free_mapped_files (int verbose)
 
struct bu_mapped_filebu_open_mapped_file_with_path (char *const *path, const char *name, const char *appl)
 

Detailed Description

Macro Definition Documentation

#define BU_MAPPED_FILE_NULL   ((struct bu_mapped_file *)0)

Definition at line 96 of file mapped_file.h.

#define BU_MAPPED_FILE_INIT (   _mf)
Value:
{ \
(_mf)->name = (_mf)->buf = NULL; \
(_mf)->buflen = (_mf)->is_mapped = 0; \
(_mf)->appl = (_mf)->apbuf = NULL; \
(_mf)->apbuflen = (_mf)->modtime = (_mf)->uses = (_mf)->dont_restat = 0; \
}
Definition: clone.c:90
#define BU_LIST_INIT_MAGIC(_hp, _magic)
Definition: list.h:156
#define BU_MAPPED_FILE_MAGIC
Definition: magic.h:57

initialize a bu_mapped_file struct without allocating any memory.

Definition at line 106 of file mapped_file.h.

#define BU_MAPPED_FILE_INIT_ZERO   { {BU_MAPPED_FILE_MAGIC, BU_LIST_NULL, BU_LIST_NULL}, NULL, NULL, 0, 0, NULL, NULL, 0, 0, 0, 0 }

macro suitable for declaration statement initialization of a bu_mapped_file struct. does not allocate memory.

Definition at line 118 of file mapped_file.h.

#define BU_MAPPED_FILE_IS_INITIALIZED (   _hp)    (((struct bu_mapped_file *)(_hp) != BU_MAPPED_FILE_NULL) && LIKELY((_hp)->l.magic == BU_MAPPED_FILE_MAGIC))

returns truthfully whether a bu_mapped_file has been initialized via BU_MAPPED_FILE_INIT() or BU_MAPPED_FILE_INIT_ZERO.

Definition at line 124 of file mapped_file.h.

Typedef Documentation

Definition at line 95 of file mapped_file.h.

Function Documentation

struct bu_mapped_file* bu_open_mapped_file ( const char *  name,
const char *  appl 
)

Provides a standardized interface for acquiring the entire contents of an existing file mapped into the current address space, using the virtual memory capabilities of the operating system (such as mmap()) where available, or by allocating sufficient dynamic memory and reading the entire file.

If the file can not be opened, as descriptive an error message as possible will be printed, to simplify code handling in the caller.

Mapped files are always opened read-only.

If the system does not support mapped files, the data is read into memory.

Definition at line 56 of file mappedfile.c.

References bu_mapped_file::appl, BU_ALLOC, bu_calloc(), BU_CK_MAPPED_FILE, bu_debug, BU_DEBUG_MAPPED_FILE, bu_free(), BU_LIST_APPEND, BU_LIST_FOR, BU_LIST_INIT, BU_LIST_IS_INITIALIZED, bu_log(), BU_MAPPED_FILE_MAGIC, bu_pr_mapped_file(), bu_realpath(), BU_SEM_MAPPEDFILE, BU_SEM_SYSCALL, bu_semaphore_acquire(), bu_semaphore_release(), BU_STR_EQUAL, bu_strdup, bu_mapped_file::buf, bu_mapped_file::buflen, bu_mapped_file::dont_restat, bu_mapped_file::is_mapped, bu_mapped_file::l, bu_list::magic, bu_mapped_file::modtime, bu_mapped_file::name, UNLIKELY, and bu_mapped_file::uses.

Referenced by bu_open_mapped_file_with_path(), build_comb(), db_open(), ext_setup(), prj_setup(), rt_hf_import4(), rt_mk_binunif(), temp_setup(), and tthrm_setup().

Here is the call graph for this function:

void bu_close_mapped_file ( struct bu_mapped_file mp)

Release a use of a mapped file. Because it may be re-used shortly, e.g. by the next frame of an animation, don't release the memory even on final close, so that it's available when next needed.

Call bu_free_mapped_files() after final close to reclaim space. But only do that if you're SURE that ALL these files will never again need to be mapped by this process. Such as when running multi-frame animations.

Definition at line 339 of file mappedfile.c.

References BU_CK_MAPPED_FILE, bu_debug, BU_DEBUG_MAPPED_FILE, bu_log(), bu_pr_mapped_file(), BU_SEM_MAPPEDFILE, bu_semaphore_acquire(), bu_semaphore_release(), UNLIKELY, and bu_mapped_file::uses.

Referenced by build_comb(), db_close(), db_open(), ext_setup(), prj_free(), prj_setup(), rt_dsp_bbox(), rt_dsp_free(), rt_dsp_ifree(), rt_ebm_free(), rt_ebm_ifree(), rt_hf_free(), rt_hf_ifree(), rt_mk_binunif(), temp_free(), tthrm_setup(), and txt_free().

Here is the call graph for this function:

void bu_pr_mapped_file ( const char *  title,
const struct bu_mapped_file mp 
)

Definition at line 358 of file mappedfile.c.

References BU_CK_MAPPED_FILE, bu_log(), bu_mapped_file::buf, bu_mapped_file::buflen, bu_mapped_file::is_mapped, bu_mapped_file::name, UNLIKELY, and bu_mapped_file::uses.

Referenced by bu_close_mapped_file(), bu_free_mapped_files(), and bu_open_mapped_file().

Here is the call graph for this function:

void bu_free_mapped_files ( int  verbose)

Release storage being used by mapped files with no remaining users. This entire routine runs inside a critical section, for parallel protection. Only call this routine if you're SURE that ALL these files will never again need to be mapped by this process. Such as when running multi-frame animations.

Definition at line 373 of file mappedfile.c.

References bu_mapped_file::apbuf, bu_mapped_file::appl, BU_CK_MAPPED_FILE, bu_debug, BU_DEBUG_MAPPED_FILE, bu_free(), BU_LIST_DEQUEUE, BU_LIST_FIRST, BU_LIST_NEXT, BU_LIST_NOT_HEAD, bu_log(), bu_pr_mapped_file(), BU_SEM_MAPPEDFILE, BU_SEM_SYSCALL, bu_semaphore_acquire(), bu_semaphore_release(), bu_mapped_file::buf, bu_mapped_file::buflen, bu_mapped_file::is_mapped, bu_mapped_file::l, bu_mapped_file::name, UNLIKELY, and bu_mapped_file::uses.

Referenced by db_close(), and db_open().

Here is the call graph for this function:

struct bu_mapped_file* bu_open_mapped_file_with_path ( char *const *  path,
const char *  name,
const char *  appl 
)

A wrapper for bu_open_mapped_file() which uses a search path to locate the file.

The search path is specified as a normal C argv array, terminated by a null string pointer. If the file name begins with a slash ('/') the path is not used.

Definition at line 430 of file mappedfile.c.

References BU_ASSERT_PTR, bu_open_mapped_file(), bu_vls_addr(), bu_vls_free(), BU_VLS_INIT_ZERO, bu_vls_putc(), bu_vls_strcat(), and bu_vls_strcpy().

Referenced by get_file_data(), img_load_datasource(), new_image(), rt_ebm_import4(), rt_ebm_import5(), and txt_load_datasource().

Here is the call graph for this function: