GNU CommonC++
Public Member Functions
ost::ThreadFile Class Reference

This class defines a database I/O file service that can be shared by multiple threads. More...

#include <file.h>

Inheritance diagram for ost::ThreadFile:
ost::RandomFile ost::Mutex ost::File

List of all members.

Public Member Functions

 ThreadFile (const char *path)
 Open or create a new database file.
virtual ~ThreadFile ()
 Close and finish a database file.
Error restart (void)
 Restart an existing database; close and re-open.
Error fetch (caddr_t address=NULL, ccxx_size_t length=0, off_t position=-1)
 Fetch a portion of the file into physical memory.
Error update (caddr_t address=NULL, ccxx_size_t length=0, off_t position=-1)
 Update a portion of a file from physical memory.
Error append (caddr_t address=NULL, ccxx_size_t length=0)
 Add new data to the end of the file.
off_t getPosition (void)
 Fetch the current file position marker for this thread.
bool operator++ (void)
bool operator-- (void)
- Public Member Functions inherited from ost::RandomFile
virtual ~RandomFile ()
 Destroy a random access file or it's derived class.
bool initial (void)
 This method should be called right after a RandomFile derived object has been created.
off_t getCapacity (void)
 Get current file capacity.
Error getErrorNumber (void)
 Return current error id.
char * getErrorString (void)
 Return current error string.
bool operator! (void)

Additional Inherited Members

- Protected Member Functions inherited from ost::RandomFile
 RandomFile (const char *name=NULL)
 Create an unopened random access file.
 RandomFile (const RandomFile &rf)
 Default copy constructor.
Error error (Error errid, char *errstr=NULL)
 Post an error event.
Error error (char *err)
 Post an extended string error message.
void setError (bool enable)
 Used to enable or disable throwing of exceptions on errors.
Error setCompletion (Complete mode)
 Used to set file completion modes.
void setTemporary (bool enable)
 Used to set the temporary attribute for the file.
virtual Attr initialize (void)
 This method is used to initialize a newly created file as indicated by the "initial" flag.
void final (void)
 Close the file.
- Protected Member Functions inherited from ost::Mutex
 Mutex (const char *name=NULL)
 The mutex is always initialized as a recursive entity.
virtual ~Mutex ()
 Destroying the mutex removes any system resources associated with it.
void nameMutex (const char *name)
 Enable setting of mutex name for deadlock debug.
void enterMutex (void)
 Entering a Mutex locks the mutex for the current thread.
void enter (void)
 Future abi will use enter/leave/test members.
void leave (void)
 Future abi will use enter/leave/test members.
bool test (void)
 Future abi will use enter/leave/test members.
bool tryEnterMutex (void)
 Tries to lock the mutex for the current thread.
void leaveMutex (void)
 Leaving a mutex frees that mutex for use by another thread.
- Protected Attributes inherited from ost::RandomFile
int fd
Access access
char * pathname
struct {
   unsigned   count: 16
   bool   thrown: 1
   bool   initial: 1
   bool   immediate: 1
   bool   temp: 1
flags

Detailed Description

This class defines a database I/O file service that can be shared by multiple threads.

All threads access a global copy of the database object, and mutex locks can be used to preserve transaction integrety. pread/pwrite calls can be used for optimized I/O when supported.

ThreadFile is meant for use by a threaded database server where multiple threads may each perform semi-independent operations on a given database table stored on disk. A special "fcb" structure is used to hold file "state", and pread/pwrite is used whenever possible for optimized I/O. On systems that do not offer pwread/pwrite, a Mutex lock is used to protect concurrent lseek and read/write operations. ThreadFile managed databases are assumed to be used only by the local server and through a single file descriptor.

Author:
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m This class defines a database I/O file service that can be shared by multiple threads.

Constructor & Destructor Documentation

ost::ThreadFile::ThreadFile ( const char *  path)

Open or create a new database file.

You should also use Initial.

Parameters:
pathpathname of database to open.
virtual ost::ThreadFile::~ThreadFile ( )
virtual

Close and finish a database file.


Member Function Documentation

Error ost::ThreadFile::append ( caddr_t  address = NULL,
ccxx_size_t  length = 0 
)

Add new data to the end of the file.

Parameters:
addressaddress to use, or NULL if same as last I/O.
lengthlength to use, or 0 if same as last I/O.
Error ost::ThreadFile::fetch ( caddr_t  address = NULL,
ccxx_size_t  length = 0,
off_t  position = -1 
)

Fetch a portion of the file into physical memory.

This can use state information to fetch the current record multiple times.

Returns:
errSuccess on success.
Parameters:
addressaddress to use, or NULL if same as last I/O.
lengthlength to use, or 0 if same as last I/O.
positionfile position to use -1 if same as last I/O.
off_t ost::ThreadFile::getPosition ( void  )

Fetch the current file position marker for this thread.

Returns:
file position offset.
bool ost::ThreadFile::operator++ ( void  )
bool ost::ThreadFile::operator-- ( void  )
Error ost::ThreadFile::restart ( void  )
virtual

Restart an existing database; close and re-open.

Returns:
errSuccess if successful.

Reimplemented from ost::RandomFile.

Error ost::ThreadFile::update ( caddr_t  address = NULL,
ccxx_size_t  length = 0,
off_t  position = -1 
)

Update a portion of a file from physical memory.

This can use state information to commit the last read record.

Returns:
errSuccess on success.
Parameters:
addressaddress to use, or NULL if same as last I/O.
lengthlength to use, or 0 if same as last I/O.
positionfile position to use or -1 if same as last I/O.

The documentation for this class was generated from the following file: