/* * @RRL: 16-Oct-1997 (c) ! */ #include #include #include #include #include #include #include #include #include int lock (long *,int); int unlock (long); struct lk_status_block{ short int cnd, rsv; int id; char val[16]; }; /* * Input: lkid - if lkid non zero lock function will performing lock * conversion * lkmode - type of lock requested (see $LKIDEF) */ int lock (long *lkid,int lkmode) { long status; long tmob [ 2 ] = { -30000000, -1 }; /* delta time = 3 sec */ struct lk_status_block lksb; $DESCRIPTOR(resnam,"RRL$RES00"); /* name of resource for */ /* SDA SHO LOCK/NAME=RRL$RESS00 */ long efn_blk,lkflag; long reqidt = 1; lksb.id = *lkid; strcpy(&lksb.val[0],"Lock Value"); /* * call LOCK service */ /* * lkflag = LCK$M_VALBLK; */ if (*lkid) lkflag |= LCK$M_CONVERT; status = sys$enqw(0, lkmode, &lksb, lkflag, &resnam,0,0,0,0,0,0,0); if ( !(status & 1) ) lib$signal(status); /* * check condition in Lock Status Block */ if ( !(lksb.cnd & 1) ) { status = sys$deq(lksb.id,0,0,0); if ( !(status & 1) ) lib$signal(status); return SS$_DEADLOCK; } /* * return LOCK ID and condition */ *lkid = lksb.id; return lksb.cnd; } int unlock (long lkid) { long status; /* * call UNLOCK */ status = sys$deq(lkid,0,0,0); if ( !(status & 1) ) lib$signal(status); return SS$_NORMAL; } void main (void) { long status; long lkid = 0; puts("Try lock."); status = lock (&lkid,LCK$K_CRMODE); if ( !(status & 1) ) lib$signal(status); printf("\nlkid = %x",lkid); getchar(); status = lock (&lkid,LCK$K_EXMODE); if ( !(status & 1) ) lib$signal(status); printf("\nlkid = %x",lkid); sys$hiber(); }