Diff for /parser3/src/main/pa_os.C between versions 1.1 and 1.10

version 1.1, 2003/11/06 08:50:26 version 1.10, 2007/05/24 10:32:57
Line 1 Line 1
 /** @file  /** @file
         Parser: commonly functions.          Parser: commonly functions.
   
         Copyright(c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)          Copyright(c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
 */  */
   
 static const char* IDENT_COMMON_C="$Date$";   static const char * const IDENT_COMMON_C="$Date$"; 
   
 #include "pa_config_includes.h"  #include "pa_config_includes.h"
 #include "pa_os.h"  #include "pa_os.h"
Line 14  static const char* IDENT_COMMON_C="$Date Line 14  static const char* IDENT_COMMON_C="$Date
 #               include <windows.h>  #               include <windows.h>
 #       endif  #       endif
   
 // locking constants  
 //#define PA_DEBUG_NO_LOCKING  
   
 #ifdef PA_DEBUG_NO_LOCKING  
   
 #ifdef HAVE_FLOCK  #ifdef HAVE_FLOCK
   
 static int pa_lock_shared_blocking(int fd) { return flock(fd, LOCK_SH); }  #define PA_SH_LOCK LOCK_SH|LOCK_NB
 static int pa_lock_exclusive_blocking(int fd) { return flock(fd, LOCK_EX); }  #define PA_EX_LOCK LOCK_EX|LOCK_NB
 static int pa_lock_exclusive_nonblocking(int fd) { return flock(fd, LOCK_EX || LOCK_NB); }  #define PA_ULOCK LOCK_UN
 static int pa_unlock(int fd) { return flock(fd, LOCK_UN); }  #define FLOCK(operation) int status=flock(fd, operation);
   
 #else  #else
 #ifdef HAVE__LOCKING  #ifdef HAVE__LOCKING
   
 #define FLOCK(operation) lseek(fd, 0, SEEK_SET);  return _locking(fd, operation, 1)  #define PA_SH_LOCK _LK_NBLCK
 static int pa_lock_shared_blocking(int fd) { FLOCK(_LK_LOCK); }  #define PA_EX_LOCK _LK_NBLCK
 static int pa_lock_exclusive_blocking(int fd) { FLOCK(_LK_LOCK); }  #define PA_ULOCK _LK_UNLCK
 static int pa_lock_exclusive_nonblocking(int fd) { FLOCK(_LK_NBLCK); }  #define FLOCK(operation) lseek(fd, 0, SEEK_SET); int status=_locking(fd, operation, 1);
 static int pa_unlock(int fd) { FLOCK(_LK_UNLCK); }  
   
 #else  #else
 #ifdef HAVE_FCNTL  #ifdef HAVE_FCNTL
   
 #define FLOCK(cmd, arg) struct flock ls={arg, SEEK_SET};  return fcntl(fd, cmd, &ls)  #define PA_SH_LOCK F_RDLCK
 static int pa_lock_shared_blocking(int fd) { FLOCK(F_SETLKW, F_RDLCK); }  #define PA_EX_LOCK F_WRLCK
 static int pa_lock_exclusive_blocking(int fd) { FLOCK(F_SETLKW, F_WRLCK); }  #define PA_ULOCK F_UNLCK
 static int pa_lock_exclusive_nonblocking(int fd) { FLOCK(F_SETLK, F_RDLCK); }  #define FLOCK(operation) struct flock ls={operation, SEEK_SET}; int status=fcntl(fd, F_SETLK, &ls); 
 static int pa_unlock(int fd) { FLOCK(F_SETLK, F_UNLCK); }  
   
 #else  #else
 #ifdef HAVE_LOCKF  #ifdef HAVE_LOCKF
   
 #define FLOCK(fd, operation) lseek(fd, 0, SEEK_SET);  return lockf(fd, operation, 1)  #define PA_SH_LOCK F_TLOCK
 static int pa_lock_shared_blocking(int fd) { FLOCK(F_LOCK); } // on intel solaris man doesn't have doc on shared blocking  #define PA_EX_LOCK F_TLOCK
 static int pa_lock_exclusive_blocking(int fd) { FLOCK(F_LOCK); }  #define PA_ULOCK F_ULOCK
 static int pa_lock_exclusive_nonblocking(int fd) { FLOCK(F_TLOCK); }  #define FLOCK(operation) lseek(fd, 0, SEEK_SET); int status=lockf(fd, operation, 1);
 static int pa_unlock(int fd) { FLOCK(F_TLOCK); }  
   
 #else  #else
   
Line 62  static int pa_unlock(int fd) { FLOCK(F_T Line 54  static int pa_unlock(int fd) { FLOCK(F_T
 #endif  #endif
 #endif  #endif
   
 #else  int pa_lock(int fd, int attempts, int operation){
 static int pa_lock_shared_blocking(int fd) { return 0; }          while(true){
 static int pa_lock_exclusive_blocking(int fd) { return 0; }                  FLOCK(operation);
 static int pa_lock_exclusive_nonblocking(int fd) { return 0; }                  attempts--;
 static int pa_unlock(int fd) { return 0; }                  if(status==0 || attempts<=0){
                           return status;
                   }
                   pa_sleep(PA_LOCK_WAIT_TIMEOUT_SECS, PA_LOCK_WAIT_TIMEOUT_USECS);
           }
   };
   
   int pa_lock_shared_blocking(int fd) {
           return pa_lock(fd, PA_LOCK_ATTEMPTS, PA_SH_LOCK);
   }
   
   int pa_lock_exclusive_blocking(int fd) {
           return pa_lock(fd, PA_LOCK_ATTEMPTS, PA_EX_LOCK);
   }
   
   int pa_lock_exclusive_nonblocking(int fd) {
           return pa_lock(fd, 1, PA_EX_LOCK);
   }
   
   int pa_unlock(int fd) {
           return pa_lock(fd, 1, PA_ULOCK);
   }
   
 #endif  
   
 int pa_sleep(unsigned long secs, unsigned long usecs) {  int pa_sleep(unsigned long secs, unsigned long usecs) {
         for (;  usecs >= 1000000; ++secs, usecs -= 1000000);           for (;  usecs >= 1000000; ++secs, usecs -= 1000000); 
Line 80  int pa_sleep(unsigned long secs, unsigne Line 92  int pa_sleep(unsigned long secs, unsigne
         struct timeval t;          struct timeval t;
         t.tv_sec = secs;          t.tv_sec = secs;
         t.tv_usec = usecs;          t.tv_usec = usecs;
         return (select(0, NULL, NULL, NULL, &t) == -1 ? errno : 0);           return (select(0, NULL, NULL, NULL, &t)<0 ? errno : 0); 
 #endif  #endif
 }  }

Removed from v.1.1  
changed lines
  Added in v.1.10


E-mail: