#include #include #include #include #include #include #define SEQFILE "seqno" /*filename*/ #define MAXBUF 100 #define MAXDELAY 3 #define MAXREPEAT 10 #define bool short #define TRUE 1 #define FALSE 0 //#define LINUX #ifndef LINUX #define LOCK_SH 1 #define LOCK_EX 2 #define LOCK_NB 4 #define LOCK_UN 8 #endif //#define debug /* Locking routines for System V */ bool tryLock(int fd) { if (flock(fd, (LOCK_NB|LOCK_EX)) == -1) { #ifdef debug printf("process %d cannot lock\n",getpid()); #endif return FALSE; } else return TRUE; } //tryLock() void my_unlock(int fd) { if(flock(fd, (LOCK_NB|LOCK_UN)) == -1) printf("process %d cannot unlock file\n",getpid() ); }//my_unlock() void increment2(unsigned int ignoredLockingFailures, unsigned int WaitSecondsBeforeLockingAgain, int delay) { int fd, n, seqno, failedLocks=0; char buffer[MAXBUF + 1]; if ( (fd = open(SEQFILE,O_RDWR) ) < 0 ) { perror("SEQFILE"); exit(1); } //if //file sucessfully opened #ifdef DEBUG printf("file sucessully openend\n"); #endif while ( (tryLock(fd)== FALSE) && (failedLocks