class SharedFile

Shared concurrent file access from multiple threads. More...

Definition#include <file.h>
InheritsFile, Mutex
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Members


Detailed Description

Locked files provide clean access to a database file that is shared between multiple processes via file locking. A seperate and more efficient methodology is provided here to enable multiple threads to access the same file descriptor concurrently. While shared files do not include thread exclusive file region locking, such locking can be established with in memory based tables rather than kernel file locks for speed if needed.

SharedFile (const char *fname, int access, int perm)

Create a new disk file that will be shared between multiple threads. A file name, access mode, and file permissions to use when creating a new file are specified. On failure an exception is thrown.

Parameters:
fnamepath name of disk file to open or create.
accessfile access mode.
permfile permission to assign when creating a new file.

See also: File

SharedFile (const char *fname, int access)

Open an existing disk file for shared access between multiple threads. A file name and file access mode must be specified. If the file does not exist or cannot be opened, an exception is thrown.

Parameters:
fnamepath name of disk file to open.
accessfile access mode.

SharedFile (const SharedFile &f)

Open a copy of an existing "File" through a duplicate object for shared access from multiple threads. This essentially uses the Posix dup() call to duplicate the file descriptor involved.

Parameters:
fan existing File class to duplicate from.

SharedFile (int fd)

Create a shared file "class" to reference an existing and already open file descriptor from multiple threads. This is kind of like "fdopen" in purpose, and simply allows any existing file descriptor to be manipulated by the thread shared methods.

Parameters:
fdan existing and already open file descriptor.

~SharedFile ()

Close the existing shared file object and release any used resources.

int Append (void *buf, size_t len)

Write data to the end of a specified share file exclusivily. The mutex lock is used to assure the write operation is not interfered with by other threads until it completes.

Parameters:
bufpointer to data to write to the file.
lennumber of bytes to write.

Returns: number of bytes written on success, -1 on failure.

Reimplemented from File

int Read (pos_t pos, void *buf, size_t len)

Read data from a specified file offset exclusivily. The Mutex lock is used to assure the read operation can complete without interference by other threads. While the current file offset must be specified and tracked seperately by each thread on it's own, an enhanced version may soon use a ThreadKey for this purpose.

Parameters:
posfile offset to start read from file.
bufpointer to store data read from file.
lennumber of bytes to read.

Returns: number of bytes read on success, -1 on error.

Reimplemented from File

int Write (pos_t pos, void *buf, size_t len)

Write data to a specified file offset exclusivily. The Mutex lock is used to assure the write operation can complete without interference by other threads. While the current file offset must be specified and tracked seperately by each thread on it's own, an enhanced version may soon use a ThreadKey for this purpose.

Parameters:
posfile offset to start file write.
bufpointer to data to write to the file.
lennumber of bytes to write.

Returns: number of bytes written on success, -1 on error.

Reimplemented from File