/* Sync is called when the clock needs to advance on the bottom-up pass */ TIMESTAMP multizone::sync(TIMESTAMP t0, TIMESTAMP t1) { if (t1>t0 && t0>0) { office *pFrom = OBJECTDATA(from,office); office *pTo = OBJECTDATA(to,office); /* initial delta T */ double dT = pFrom->zone.current.air_temperature - pTo->zone.current.air_temperature; /* rate of change of delta T */ double ddT = pFrom->zone.current.temperature_change - pTo->zone.current.temperature_change; /* mean delta T */ double DT = dT + ddT/2; /* mean heat transfer */ double dQ = ua * DT * (t1-t0)/TS_SECOND/3600; double x; x = dQ*(t1-t0); LOCKED(from, pFrom->Qz -= x); LOCKED(to, pTo->Qz += dQ); if (ddT!=0) /* time for 1 deg temperature change */ return (TIMESTAMP)(t1+fabs(1/ddT)*3600*TS_SECOND); else return TS_NEVER; } return TS_NEVER; /* return t2>t1 on success, t2=t1 for retry, t2<t1 on failure */ }
static int docvwait(kcondvar_t *cv, kmutex_t *mtx, struct timespec *ts) { struct lwp *l = curlwp; int rv; if (__predict_false(l->l_flag & LW_RUMP_QEXIT)) { /* * yield() here, someone might want the cpu * to set a condition. otherwise we'll just * loop forever. */ yield(); return EINTR; } UNLOCKED(mtx, false); l->l_private = cv; rv = 0; if (ts) { if (rumpuser_cv_timedwait(RUMPCV(cv), RUMPMTX(mtx), ts->tv_sec, ts->tv_nsec)) rv = EWOULDBLOCK; } else { rumpuser_cv_wait(RUMPCV(cv), RUMPMTX(mtx)); } LOCKED(mtx, false); /* * Check for QEXIT. if so, we need to wait here until we * are allowed to exit. */ if (__predict_false(l->l_flag & LW_RUMP_QEXIT)) { struct proc *p = l->l_proc; UNLOCKED(mtx, false); mutex_exit(mtx); /* drop and retake later */ mutex_enter(p->p_lock); while ((p->p_sflag & PS_RUMP_LWPEXIT) == 0) { /* avoid recursion */ rumpuser_cv_wait(RUMPCV(&p->p_waitcv), RUMPMTX(p->p_lock)); } KASSERT(p->p_sflag & PS_RUMP_LWPEXIT); mutex_exit(p->p_lock); /* ok, we can exit and remove "reference" to l->private */ mutex_enter(mtx); LOCKED(mtx, false); rv = EINTR; } l->l_private = NULL; return rv; }
void mutex_spin_enter(kmutex_t *mtx) { WANTLOCK(mtx, 0); rumpuser_mutex_enter_nowrap(RUMPMTX(mtx)); LOCKED(mtx, false); }
void rw_downgrade(krwlock_t *rw) { rumpuser_rw_downgrade(RUMPRW(rw)); UNLOCKED(rw, 0); WANTLOCK(rw, 1); LOCKED(rw, 1); }
void rw_enter(krwlock_t *rw, const krw_t op) { WANTLOCK(rw, op == RW_READER); rumpuser_rw_enter(krw2rumprw(op), RUMPRW(rw)); LOCKED(rw, op == RW_READER); }
static int pcc_set_mem_map(struct pcmcia_socket *s, struct pccard_mem_map *mem) { unsigned int sock = container_of(s, struct pcc_socket, socket)->number; if (socket[sock].flags & IS_ALIVE) { dev_dbg(&s->dev, "pcc_set_mem_map: sock(%d) -EINVAL\n", sock); return -EINVAL; } dev_dbg(&s->dev, "pcc_set_mem_map: sock(%d)\n", sock); LOCKED(_pcc_set_mem_map(sock, mem)); }
int rw_tryenter(krwlock_t *rw, const krw_t op) { int error; error = rumpuser_rw_tryenter(krw2rumprw(op), RUMPRW(rw)); if (error == 0) { WANTLOCK(rw, op == RW_READER); LOCKED(rw, op == RW_READER); } return error == 0; }
int mutex_tryenter(kmutex_t *mtx) { int error; error = rumpuser_mutex_tryenter(RUMPMTX(mtx)); if (error == 0) { WANTLOCK(mtx, 0); LOCKED(mtx, false); } return error == 0; }
static int pcc_get_status(struct pcmcia_socket *s, u_int *value) { unsigned int sock = container_of(s, struct pcc_socket, socket)->number; if (socket[sock].flags & IS_ALIVE) { dev_dbg(&s->dev, "pcc_get_status: sock(%d) -EINVAL\n", sock); *value = 0; return -EINVAL; } dev_dbg(&s->dev, "pcc_get_status: sock(%d)\n", sock); LOCKED(_pcc_get_status(sock, value)); }
void link::apply_dV(OBJECT *source, complex dV) { complex dI = dV * Y * c; OBJECT *obj; node *n; if (source==from) n = OBJECTDATA(obj=to,node); else if (source==to) n = OBJECTDATA(obj=from,node); else throw "apply_dV() - source is not valid"; LOCKED(obj,n->YVs += dI); }
int rw_tryupgrade(krwlock_t *rw) { int rv; rv = rumpuser_rw_tryupgrade(RUMPRW(rw)); if (rv == 0) { UNLOCKED(rw, 1); WANTLOCK(rw, 0); LOCKED(rw, 0); } return rv == 0; }
int enter_room( int unum, char *room, char *msg ) { int rnum = roomid_to_indx(room); int op = 0; register int i; if (rnum == -1) { /* new room */ for (i=1; i<bbs_max_users; i++) { if (rooms[i].occupants == 0) { rnum = i; if (rooms[rnum].invites == NULL) { rooms[rnum].invites = (char *)malloc(bbs_max_users); if (rooms[rnum].invites == NULL) { send_to_unum(unum, "*** Not enough memory\n", -1); return 0; } } memset(rooms[rnum].invites, 0, bbs_max_users); strncpy(rooms[rnum].name, room, NAMELEN); rooms[rnum].name[NAMELEN] = '\0'; rooms[rnum].flags = 0; op++; break; } } if (rnum == -1) { send_to_unum(unum, "*** No more rooms available\n", -1); return 0; } } if (!MANAGER(unum)) if (LOCKED(rnum) && rooms[rnum].invites[unum] == 0) { send_to_unum(unum, "*** Cannot enter locked room without a key\n", -1); return 0; } exit_room(unum, EXIT_LOGOUT, msg); users[unum].room = rnum; if (op) users[unum].flags |= FLG_CHATOP; rooms[rnum].occupants++; rooms[rnum].invites[unum] = 0; sprintf(genbuf, "*** %s has entered room '%s'\n", users[unum].chatid, rooms[rnum].name); send_to_room(rnum, genbuf, unum); return 0; }