Annotation of parser3/src/main/pa_os.C, revision 1.1
1.1 ! paf 1: /** @file
! 2: Parser: commonly functions.
! 3:
! 4: Copyright(c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
! 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
! 6: */
! 7:
! 8: static const char* IDENT_COMMON_C="$Date: 2003/11/03 13:20:30 $";
! 9:
! 10: #include "pa_config_includes.h"
! 11: #include "pa_os.h"
! 12:
! 13: # if defined(WIN32)
! 14: # include <windows.h>
! 15: # endif
! 16:
! 17: // locking constants
! 18: //#define PA_DEBUG_NO_LOCKING
! 19:
! 20: #ifdef PA_DEBUG_NO_LOCKING
! 21:
! 22: #ifdef HAVE_FLOCK
! 23:
! 24: static int pa_lock_shared_blocking(int fd) { return flock(fd, LOCK_SH); }
! 25: static int pa_lock_exclusive_blocking(int fd) { return flock(fd, LOCK_EX); }
! 26: static int pa_lock_exclusive_nonblocking(int fd) { return flock(fd, LOCK_EX || LOCK_NB); }
! 27: static int pa_unlock(int fd) { return flock(fd, LOCK_UN); }
! 28:
! 29: #else
! 30: #ifdef HAVE__LOCKING
! 31:
! 32: #define FLOCK(operation) lseek(fd, 0, SEEK_SET); return _locking(fd, operation, 1)
! 33: static int pa_lock_shared_blocking(int fd) { FLOCK(_LK_LOCK); }
! 34: static int pa_lock_exclusive_blocking(int fd) { FLOCK(_LK_LOCK); }
! 35: static int pa_lock_exclusive_nonblocking(int fd) { FLOCK(_LK_NBLCK); }
! 36: static int pa_unlock(int fd) { FLOCK(_LK_UNLCK); }
! 37:
! 38: #else
! 39: #ifdef HAVE_FCNTL
! 40:
! 41: #define FLOCK(cmd, arg) struct flock ls={arg, SEEK_SET}; return fcntl(fd, cmd, &ls)
! 42: static int pa_lock_shared_blocking(int fd) { FLOCK(F_SETLKW, F_RDLCK); }
! 43: static int pa_lock_exclusive_blocking(int fd) { FLOCK(F_SETLKW, F_WRLCK); }
! 44: static int pa_lock_exclusive_nonblocking(int fd) { FLOCK(F_SETLK, F_RDLCK); }
! 45: static int pa_unlock(int fd) { FLOCK(F_SETLK, F_UNLCK); }
! 46:
! 47: #else
! 48: #ifdef HAVE_LOCKF
! 49:
! 50: #define FLOCK(fd, operation) lseek(fd, 0, SEEK_SET); return lockf(fd, operation, 1)
! 51: static int pa_lock_shared_blocking(int fd) { FLOCK(F_LOCK); } // on intel solaris man doesn't have doc on shared blocking
! 52: static int pa_lock_exclusive_blocking(int fd) { FLOCK(F_LOCK); }
! 53: static int pa_lock_exclusive_nonblocking(int fd) { FLOCK(F_TLOCK); }
! 54: static int pa_unlock(int fd) { FLOCK(F_TLOCK); }
! 55:
! 56: #else
! 57:
! 58: #error unable to find file locking func
! 59:
! 60: #endif
! 61: #endif
! 62: #endif
! 63: #endif
! 64:
! 65: #else
! 66: static int pa_lock_shared_blocking(int fd) { return 0; }
! 67: static int pa_lock_exclusive_blocking(int fd) { return 0; }
! 68: static int pa_lock_exclusive_nonblocking(int fd) { return 0; }
! 69: static int pa_unlock(int fd) { return 0; }
! 70:
! 71: #endif
! 72:
! 73: int pa_sleep(unsigned long secs, unsigned long usecs) {
! 74: for (; usecs >= 1000000; ++secs, usecs -= 1000000);
! 75:
! 76: #ifdef WIN32
! 77: Sleep(secs * 1000 + usecs / 1000);
! 78: return 0;
! 79: #else
! 80: struct timeval t;
! 81: t.tv_sec = secs;
! 82: t.tv_usec = usecs;
! 83: return (select(0, NULL, NULL, NULL, &t) == -1 ? errno : 0);
! 84: #endif
! 85: }
E-mail: