/* Function LockMutex: lock mutex using file locking. */
int LockMutex(int fd)
{
- struct flock lock; /* file lock structure */
+ struct flock lock; /* file lock structure */
/* set flock structure */
- lock.l_type = F_WRLCK; /* set type: read or write */
- lock.l_whence = SEEK_SET; /* start from the beginning of the file */
- lock.l_start = 0; /* set the start of the locked region */
- lock.l_len = 0; /* set the length of the locked region */
+ lock.l_type = F_WRLCK; /* set type: read or write */
+ lock.l_whence = SEEK_SET; /* start from the beginning of the file */
+ lock.l_start = 0; /* set the start of the locked region */
+ lock.l_len = 0; /* set the length of the locked region */
/* do locking */
return fcntl(fd, F_SETLKW, &lock);
}
/* Function UnlockMutex: unlock a file. */
int UnlockMutex(int fd)
{
- struct flock lock; /* file lock structure */
+ struct flock lock; /* file lock structure */
/* set flock structure */
- lock.l_type = F_UNLCK; /* set type: unlock */
- lock.l_whence = SEEK_SET; /* start from the beginning of the file */
- lock.l_start = 0; /* set the start of the locked region */
- lock.l_len = 0; /* set the length of the locked region */
+ lock.l_type = F_UNLCK; /* set type: unlock */
+ lock.l_whence = SEEK_SET; /* start from the beginning of the file */
+ lock.l_start = 0; /* set the start of the locked region */
+ lock.l_len = 0; /* set the length of the locked region */
/* do locking */
return fcntl(fd, F_SETLK, &lock);
}
int ReadMutex(int fd)
{
int res;
- struct flock lock; /* file lock structure */
+ struct flock lock; /* file lock structure */
/* set flock structure */
- lock.l_type = F_WRLCK; /* set type: unlock */
- lock.l_whence = SEEK_SET; /* start from the beginning of the file */
- lock.l_start = 0; /* set the start of the locked region */
- lock.l_len = 0; /* set the length of the locked region */
+ lock.l_type = F_WRLCK; /* set type: unlock */
+ lock.l_whence = SEEK_SET; /* start from the beginning of the file */
+ lock.l_start = 0; /* set the start of the locked region */
+ lock.l_len = 0; /* set the length of the locked region */
/* do locking */
if ( (res = fcntl(fd, F_GETLK, &lock)) ) {
return res;