Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

FdCache.H

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 //
00020 // FdCache.H
00021 // Last modified on Wed Apr  7 13:50:58 EDT 2004 by ken@xorian.net
00022 //      modified on Wed Feb 10 20:19:09 PST 1999 by mann
00023 //
00024 // Cache of open file descriptors for files named by ShortId
00025 //
00026 
00027 #ifndef _FD_CACHE
00028 #define _FD_CACHE 1
00029 
00030 #include "Basics.H"
00031 #include "SourceOrDerived.H"
00032 #include "ShortIdKey.H"
00033 
00034 namespace FdCache
00035 {
00036     enum OFlag { ro, rw, any };
00037 
00038     // Obtain an open file descriptor, and reserve it so that other
00039     // threads can't use it concurrently.  The descriptor's seek
00040     // pointer location is unspecified.  If -1 is returned, a standard
00041     // error code is in errno.  The mode may be specified as
00042     // read/write, read-only, or any.  In the "any" case, modeOut must
00043     // be supplied to receive the actual mode type returned.
00044     int open(ShortId sid, OFlag ofl, OFlag* oflOut =NULL) throw();
00045 
00046     // Like open, but if there is no open file descriptor already
00047     // available in the cache, returns -1 rather than attempting to
00048     // open a file descriptor.  (If a value other than -1 is returned,
00049     // the caller is responsible for calling FdCache::close.)
00050     int tryopen(ShortId sid, OFlag ofl, OFlag* oflOut =NULL) throw();
00051 
00052     // Return an open file descriptor to the cache.  The descriptor
00053     // need not have been obtained via FdCache::open, but the correct
00054     // mode must be specified ("any" is not permitted).
00055     void close(ShortId sid, int fd, OFlag ofl) throw();
00056 
00057     // Flush a ShortId from the cache.  If mode is specified as
00058     // read-only or read/write, only descriptors in that mode are
00059     // flushed; if it is specified as any, all descriptors are
00060     // flushed.
00061     void flush(ShortId sid, OFlag ofl) throw();
00062 
00063     // Get statistics from the file descriptor cache. "n_in_cache" is
00064     // set to the number of file descriptors currently in the cache.
00065     // "hits" is set to the total number of requests for a file
00066     // descriptor that found a matching one in the cache.
00067     // "open_misses" is set to the total number of requests for a file
00068     // descriptor that failed to find a matching one in the cache and
00069     // subsequently opened a new file descriptor.  "try_misses" is set
00070     // to the total number of requests for a file descriptor that
00071     // failed to find a matching one in the cache and caused calling
00072     // code to proceed without a file descriptor.  "evictions" is set
00073     // to the total number of times that a file descriptor has been
00074     // evicted from the cache to make room for another one.
00075     // "expirations" is set to the number of times that a file
00076     // descriptor has been removed by the janitor thread (after being
00077     // unused for some time).
00078     void getStats(/*OUT*/ Basics::uint32 &n_in_cache,
00079                   /*OUT*/ Basics::uint64 &hits,
00080                   /*OUT*/ Basics::uint64 &open_misses,
00081                   /*OUT*/ Basics::uint64 &try_misses,
00082                   /*OUT*/ Basics::uint64 &evictions,
00083                   /*OUT*/ Basics::uint64 &expirations);
00084 }
00085 
00086 #endif

Generated on Mon May 8 00:48:44 2006 for Vesta by  doxygen 1.4.2