[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1 File Caching

The file caching mechanism is embedded within BFD and allows the application to open as many BFDs as it wants without regard to the underlying operating system’s file descriptor limit (often as low as 20 open files). The module in cache.c maintains a least recently used list of BFD_CACHE_MAX_OPEN files, and exports the name bfd_cache_lookup which runs around and makes sure that the required BFD is open. If not, then it chooses a file to close, closes it and opens the one wanted, returning its file handle.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.0.1 BFD_CACHE_MAX_OPEN macro

Description
The maxiumum number of files which the cache will keep open at one time.

#define BFD_CACHE_MAX_OPEN 10


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.0.2 bfd_last_cache

Synopsis

extern bfd *bfd_last_cache;

Description
Zero, or a pointer to the topmost BFD on the chain. This is used by the bfd_cache_lookup macro in ‘libbfd.h’ to determine when it can avoid a function call.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.0.3 bfd_cache_lookup

Description
Checks to see if the required BFD is the same as the last one looked up. If so then it can use the iostream in the BFD with impunity, since it can’t have changed since the last lookup, otherwise it has to perform the complicated lookup function

#define bfd_cache_lookup(x) \
    ((x)==bfd_last_cache? \
      (FILE*)(bfd_last_cache->iostream): \
       bfd_cache_lookup_worker(x))


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.0.4 bfd_cache_init

Synopsis

void  bfd_cache_init (bfd *);

Description
Initialize a BFD by putting it on the cache LRU.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.0.5 bfd_cache_close

Description
Remove the BFD from the cache. If the attached file is open, then close it too.
Synopsis

void bfd_cache_close (bfd *);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.0.6 bfd_open_file

Description
Call the OS to open a file for this BFD. Returns the FILE * (possibly null) that results from this operation. Sets up the BFD so that future accesses know the file is open. If the FILE returned is null, then there is won’t have been put in the cache, so it won’t have to be removed from it.
Synopsis

FILE* bfd_open_file(bfd *);

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.0.7 bfd_cache_lookup_worker

Description
Called when the macro bfd_cache_lookup fails to find a quick answer. Finds a file descriptor for this BFD. If necessary, it open it. If there are already more than BFD_CACHE_MAX_OPEN files open, it trys to close one first, to avoid running out of file descriptors.
Synopsis

FILE *bfd_cache_lookup_worker(bfd *);

[Top] [Contents] [Index] [ ? ]

About This Document

This document was generated on December 11, 2024 using texi2html 5.0.

The buttons in the navigation panels have the following meaning:

Button Name Go to From 1.2.3 go to
[ << ] FastBack Beginning of this chapter or previous chapter 1
[ < ] Back Previous section in reading order 1.2.2
[ Up ] Up Up section 1.2
[ > ] Forward Next section in reading order 1.2.4
[ >> ] FastForward Next chapter 2
[Top] Top Cover (top) of document  
[Contents] Contents Table of contents  
[Index] Index Index  
[ ? ] About About (help)  

where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:


This document was generated on December 11, 2024 using texi2html 5.0.