SharedFile Class Reference

[APE Index] [APE Hierarchy] [Headers]


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

#include <file.h>

Inherits: File, Mutex

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) [public]

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:
access file access mode.
perm file permission to assign when creating a new file.
fname path name of disk file to open or create.
See Also:
File::File

SharedFile(const char *fname, int access) [public]

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:
access file access mode.
fname path name of disk file to open.

SharedFile(const SharedFile &f) [public]

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:
f an existing File class to duplicate from.

SharedFile(int fd) [public]

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:
fd an existing and already open file descriptor.

~SharedFile() [public]

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

int Append(void *buf, size_t len) [public]

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:
buf pointer to data to write to the file.
len number of bytes to write.
Returns:
number of bytes written on success, -1 on failure.

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

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:
pos file offset to start read from file.
buf pointer to store data read from file.
len number of bytes to read.
Returns:
number of bytes read on success, -1 on error.

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

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:
pos file offset to start file write.
buf pointer to data to write to the file.
len number of bytes to write.
Returns:
number of bytes written on success, -1 on error.

  • Author: David Sugar <dyfet@ostel.com>
  • Documentation generated by dyfet@home.sys on Thu Dec 16 09:54:26 EST 1999
Kdoc