pwr_tBoolean sect_Lock ( pwr_tStatus *sts, sect_sHead *shp, sect_sMutex *mp ) { pwr_tStatus lsts = 1; #if defined(OS_ELN) ELN$LOCK_AREA((AREA)shp->area, *mp); #elif defined(OS_VMS) { sect_sMutexEntry *ep; int i; /* Get free list entry. */ while ( 1) { i = _REMQHI(&mp->freeroot, (void **)&ep); if ( i == 1) continue; else if (i == 3) sleep(1); else break; } /* Insert in ownership list. */ while ((i = _INSQTI(ep, &mp->ownerroot)) == 1); if (i == 0) { /* Contention, we must wait for the resource. */ lsts = sys$ascefc(64, &shp->namedsc, 0, 0); if (ODD(lsts)) lsts = sys$waitfr(ep->flag); if (ODD(lsts)) lsts = sys$clref(ep->flag); } } #elif defined(OS_LYNX) while (sem_wait(mp) != 0) { if (errno != EINTR) { perror("sect_Lock: sem_wait "); lsts = 2; break; } } #elif defined OS_POSIX while (posix_sem_wait(mp) != 0) { if (errno != EINTR) { perror("sect_Lock: sem_wait "); lsts = 2; break; } } #endif errh_ReturnOrBugcheck(ODD(lsts), sts, lsts, ""); }
pwr_tBoolean sect_Unlock ( pwr_tStatus *sts, sect_sHead *shp, sect_sMutex *mp ) { pwr_tStatus lsts = 1; #if defined(OS_ELN) ELN$UNLOCK_AREA((AREA)shp->area, *mp); #elif defined(OS_VMS) { sect_sMutexEntry *ep; pwr_tUInt32 i; /* When the entry is removed the resource becomes free if noone else is waiting... */ while ((i = _REMQHI(&mp->ownerroot, (void **)&ep)) == 1); if (i == 3) { lsts = LIB$_QUEWASEMP; } else { /* Reinsert entry in free list */ while (_INSQTI(ep, &mp->freeroot) == 1); if (i == 0) { /* Someone was waiting. */ ep = (sect_sMutexEntry *)( ((pwr_tUInt32)&mp->ownerroot) + mp->ownerroot.low /* flink */); lsts = sys$ascefc(64, &shp->namedsc, 0, 0); if (ODD(lsts)) lsts = sys$setef(ep->flag); } } } #elif defined(OS_LYNX) if (sem_post(mp) != 0) { perror("sect_Unlock: sem_signal "); lsts = 2; } #elif defined OS_POSIX if (posix_sem_post(mp) != 0) { perror("sect_Unlock: sem_signal "); lsts = 2; } #endif errh_ReturnOrBugcheck(ODD(lsts), sts, lsts, ""); }
pwr_tBoolean sect_InitLock ( pwr_tStatus *sts, sect_sHead *shp, sect_sMutex *mp ) { pwr_tStatus lsts = 1; #ifdef OS_ELN ELN$INITIALIZE_AREA_LOCK((AREA)shp->area, *mp, &lsts); #elif defined(OS_VMS) { pwr_tUInt32 i; /* Clear mutex variable and build free list. */ memset(mp, 0, sizeof(*mp)); lsts = sys$ascefc(64, &shp->namedsc, 0, 0); if (ODD(lsts)) { for (i=0; i<32; i++) { while (_INSQTI(&mp->list[i].entry, &mp->freeroot) == 1); mp->list[i].flag = 64+i; lsts = sys$clref(mp->list[i].flag); if (EVEN(lsts)) break; } } } #elif defined(OS_LYNX) if (sem_init(mp, 1, 1) != 0) { errh_Error("sect_InitLock: sem_init, errno: %d", errno); lsts = 2; } #elif defined OS_POSIX if (posix_sem_init_shared(mp, ftok(shp->name, 'P'), 1) != 0) { errh_Error("sect_InitLock: sem_init(%s), errno: %d", shp->name, errno); lsts = 2; } #endif errh_ReturnOrBugcheck(ODD(lsts), sts, lsts, ""); }
void bck_ForceBackup ( void **context) { pwr_tInt32 sts; pwr_tTime *t; #ifdef OS_VMS $DESCRIPTOR (efcname, BCK_EFC_NAME); #endif /* * Initialize */ #ifdef OS_ELN if (!areas_mapped) { BCK_MAP_AREAS; areas_mapped = TRUE; } #endif /* * Build the context block (i.e. current time) */ if (context != NULL) { t = malloc (sizeof *t); time_GetTime(t); *context = t; } /* * Kick the backup processes */ #ifdef OS_ELN ker$signal (NULL, bck_forced_activation); #else sts = sys$ascefc (BCK_EFC, &efcname, 0, 0); if (EVEN (sts)) lib$signal (sts); sts = sys$setef (BCK_ACTIVATE); if (EVEN (sts)) lib$signal (sts); #endif } /* bck_ForceBackup */
pwr_tUInt32 bck_WaitBackup ( void *context, pwr_tBoolean timeout) { pwr_tUInt32 sts; pwr_tObjid objid; pwr_tInt32 c; pwr_tTime t; pwr_tVaxTime tmo; pwr_tVaxTime tmptime; pwr_sClass_Backup_Conf *backup_confp; /* Backup_Conf object pointer */ $DESCRIPTOR (timeunitdsc, "0 0:0:0.1"); /* 0.1 second units */ int cycletime; #ifdef OS_ELN pwr_tInt32 res; pwr_tVaxTime *tmop; #endif #ifdef OS_VMS $DESCRIPTOR (efcname, BCK_EFC_NAME); #endif /* * Initialize */ #ifdef OS_ELN if (!areas_mapped) { BCK_MAP_AREAS; areas_mapped = TRUE; } #endif /* * Find the local Backup_Conf object */ sts = gdh_GetClassList (pwr_cClass_Backup_Conf, &objid); while (ODD (sts)) { sts = gdh_ObjidToPointer (objid, (pwr_tAddress *)&backup_confp); if (ODD (sts)) break; sts = gdh_GetNextObject (objid, &objid); } if (EVEN (sts)) return sts; /* Something wrong, quit */ /* * Pick up argument information */ if (context == NULL) time_GetTime(&t); else { t = *(pwr_tTime *)context; free (context); } #ifdef OS_ELN tmop = NULL; #else timed_out = FALSE; sts = sys$ascefc (BCK_EFC, &efcname, 0, 0); if (EVEN (sts)) lib$signal (sts); /* BUG */ #endif if (timeout) { cycletime = backup_confp->CycleSlow * 2; if (cycletime == 0) cycletime = BCK_DEFAULT_SLOW * 2; #ifdef OS_ELN tmo = eln$time_value (&timeunitdsc); #else sts = sys$bintim (&timeunitdsc, &tmo); if (EVEN (sts)) lib$signal (sts); /* BUG, should not happen */ #endif lib$mult_delta_time ( &cycletime, /* multiplier */ &tmo); /* delta_time (modified) */ sys$gettim (&tmptime); lib$add_times (&tmo, &tmptime, &tmo); /* Make absolute time */ #ifdef OS_ELN tmop = &tmo; #else sts = sys$setimr (BCK_WRITE_DONE, &tmo, &astrtn, 4711, 0); if (EVEN (sts)) lib$signal (sts); /* BUG */ #endif } /* * Loop, and wait for things to happen */ while (TRUE) { #ifdef OS_ELN ker$clear_event (NULL, bck_write_done); ker$wait_any (NULL, &res, tmop, bck_write_done); /* Check for timeout */ if (res == 0) return SS$_TIMEOUT; #else sts = sys$clref (BCK_WRITE_DONE); if (EVEN (sts)) lib$signal (sts); /* BUG */ sts = sys$waitfr (BCK_WRITE_DONE); if (EVEN (sts)) lib$signal (sts); /* BUG */ /* Check for timeout */ if (timed_out) return SS$_TIMEOUT; #endif /* Check if both cycles done */ if (time_Acomp(&backup_confp->ObjTimeSlow, &t) < 0) continue; if (time_Acomp(&backup_confp->ObjTimeFast, &t) < 0) continue; break; } /* Loop */ #ifdef OS_VMS sys$cantim (4711, 0); #endif return 1; /* Done. */ } /* bck_WaitBackup */