Annotation of parser3/src/main/pa_os.C, revision 1.8

1.1       paf         1: /** @file
                      2:        Parser: commonly functions.
                      3: 
1.8     ! paf         4:        Copyright(c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
1.1       paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
                      6: */
                      7: 
1.8     ! paf         8: static const char * const IDENT_COMMON_C="$Date: 2004/07/15 06:38:10 $"; 
1.1       paf         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: #ifdef HAVE_FLOCK
                     18: 
1.2       paf        19: int pa_lock_shared_blocking(int fd) { return flock(fd, LOCK_SH); }
                     20: int pa_lock_exclusive_blocking(int fd) { return flock(fd, LOCK_EX); }
                     21: int pa_lock_exclusive_nonblocking(int fd) { return flock(fd, LOCK_EX || LOCK_NB); }
                     22: int pa_unlock(int fd) { return flock(fd, LOCK_UN); }
1.1       paf        23: 
                     24: #else
                     25: #ifdef HAVE__LOCKING
                     26: 
                     27: #define FLOCK(operation) lseek(fd, 0, SEEK_SET);  return _locking(fd, operation, 1)
1.2       paf        28: int pa_lock_shared_blocking(int fd) { FLOCK(_LK_LOCK); }
                     29: int pa_lock_exclusive_blocking(int fd) { FLOCK(_LK_LOCK); }
                     30: int pa_lock_exclusive_nonblocking(int fd) { FLOCK(_LK_NBLCK); }
                     31: int pa_unlock(int fd) { FLOCK(_LK_UNLCK); }
1.1       paf        32: 
                     33: #else
                     34: #ifdef HAVE_FCNTL
                     35: 
                     36: #define FLOCK(cmd, arg) struct flock ls={arg, SEEK_SET};  return fcntl(fd, cmd, &ls)
1.2       paf        37: int pa_lock_shared_blocking(int fd) { FLOCK(F_SETLKW, F_RDLCK); }
                     38: int pa_lock_exclusive_blocking(int fd) { FLOCK(F_SETLKW, F_WRLCK); }
                     39: int pa_lock_exclusive_nonblocking(int fd) { FLOCK(F_SETLK, F_RDLCK); }
                     40: int pa_unlock(int fd) { FLOCK(F_SETLK, F_UNLCK); }
1.1       paf        41: 
                     42: #else
                     43: #ifdef HAVE_LOCKF
                     44: 
                     45: #define FLOCK(fd, operation) lseek(fd, 0, SEEK_SET);  return lockf(fd, operation, 1)
1.2       paf        46: int pa_lock_shared_blocking(int fd) { FLOCK(F_LOCK); } // on intel solaris man doesn't have doc on shared blocking
                     47: int pa_lock_exclusive_blocking(int fd) { FLOCK(F_LOCK); }
                     48: int pa_lock_exclusive_nonblocking(int fd) { FLOCK(F_TLOCK); }
                     49: int pa_unlock(int fd) { FLOCK(F_TLOCK); }
1.1       paf        50: 
                     51: #else
                     52: 
                     53: #error unable to find file locking func
                     54: 
                     55: #endif
                     56: #endif
                     57: #endif
                     58: #endif
                     59: 
                     60: int pa_sleep(unsigned long secs, unsigned long usecs) {
                     61:        for (;  usecs >= 1000000; ++secs, usecs -= 1000000); 
                     62: 
                     63: #ifdef WIN32
                     64:        Sleep(secs * 1000 + usecs / 1000); 
                     65:        return 0;
                     66: #else
                     67:        struct timeval t;
                     68:        t.tv_sec = secs;
                     69:        t.tv_usec = usecs;
1.6       paf        70:        return (select(0, NULL, NULL, NULL, &t)<0 ? errno : 0); 
1.1       paf        71: #endif
                     72: }

E-mail: