void err_txt(std::string s) { GETLOCK(mtx_io, lk); std::cerr << "Error: " << s << endl; ofstream ferr("err.txt", ios_base::out | ios_base::app); ferr << "DAOOPT: " << s << endl; ferr.close(); }
void check_common(dbref obj) { printf("\nObject %s\n", unparse_object(me, obj)); printf("Name: %s\n", uncompress(DBFETCH(obj)->name)); if (GETDESC(obj)) printf("Desc: %s\n", uncompress(GETDESC(obj))); printf("Loc: #%s\n", unparse_object(me, DBFETCH(obj)->location)); printf("Owner: #%d\n", unparse_object(me, DBFETCH(obj)->owner)); printf("First contents: #%d\n", unparse_object(me, DBFETCH(obj)->contents)); printf("Next item: #%d\n", unparse_object(me, DBFETCH(obj)->next)); printf("Key: %s\n", unparse_boolexp(me, GETLOCK(obj)), 1); if (GETFAIL(obj)) printf("Fail: %s\n", uncompress(GETFAIL(obj))); if (GETSUCC(obj)) printf("Succ: %s\n", uncompress(GETSUCC(obj))); if (GETDROP(obj)) printf("Drop: %s\n", uncompress(GETDROP(obj))); if (GETOFAIL(obj)) printf("Ofail: %s\n", uncompress(GETOFAIL(obj))); if (GETOSUCC(obj)) printf("Osucc: %s\n", uncompress(GETOSUCC(obj))); if (GETODROP(obj)) printf("Odrop: %s\n", uncompress(GETODROP(obj))); printf("Properties:\n"); check_properties("/", obj); printf("End of properties.\n"); }
void PushWork(int i,int j) { register TaskElement *te = gMem->tasks + LocalTaskStack[LocalStackTop--]; int a; if (LocalStackTop < 0) { printf("!!!!!!!FAILURE IN LOCAL STACK TOP!!!\n\n\n"); HALT(-1); } te->left=i; te->right=j; GETLOCK(&gMem->TaskStackLock); ANNOUNCE("\t\t\tI have got the lock -- ", whoami); a=gMem->TaskStackTop++; te->next=gMem->TaskStack; gMem->TaskStack=te; FREELOCK(&gMem->TaskStackLock); ANNOUNCE("\t\t\tI have released the lock -- ",whoami); ANNOUNCE("\t\t\tMy TaskStackTop was -- ",a); if(LocalStackTop < 0) { printf("Local TaskStackTop negative!\n"); } }
/* * could_doit: Checks to see if player could actually do what is proposing * to be done: if thing is an exit, this checks to see if the exit will * perform a move that is allowed. Then, it checks the @lock on the thing, * whether it's an exit or not. */ int could_doit(int descr, dbref player, dbref thing) { dbref source, dest, owner; if (Typeof(thing) == TYPE_EXIT) { /* If exit is unlinked, can't do it. */ if (DBFETCH(thing)->sp.exit.ndest == 0) { return 0; } owner = OWNER(thing); source = DBFETCH(player)->location; dest = *(DBFETCH(thing)->sp.exit.dest); if (Typeof(dest) == TYPE_PLAYER) { /* Check for additional restrictions related to player dests */ dbref destplayer = dest; dest = DBFETCH(dest)->location; /* If the dest player isn't JUMP_OK, or if the dest player's loc * is set BOUND, can't do it. */ if (!(FLAGS(destplayer) & JUMP_OK) || (FLAGS(dest) & BUILDER)) { return 0; } } /* for actions */ if ((DBFETCH(thing)->location != NOTHING) && (Typeof(DBFETCH(thing)->location) != TYPE_ROOM)) { /* If this is an exit on a Thing or a Player... */ /* If the destination is a room or player, and the current * location is set BOUND (note: if the player is in a vehicle * set BUILDER this will also return failure) */ if ((Typeof(dest) == TYPE_ROOM || Typeof(dest) == TYPE_PLAYER) && (FLAGS(source) & BUILDER)) return 0; /* If secure_teleport is true, and if the destination is a room */ if (tp_secure_teleport && Typeof(dest) == TYPE_ROOM) { /* if player doesn't control the source and the source isn't * set Jump_OK, then if the destination isn't HOME, * can't do it. (Should this include getlink(owner)? Not * everyone knows that 'home' or '#-3' can be linked to and * be treated specially. -winged) */ if ((dest != HOME) && (!controls(owner, source)) && ((FLAGS(source) & JUMP_OK) == 0)) { return 0; } /* FIXME: Add support for in-server banishment from rooms * and environments here. */ } } } /* Check the @lock on the thing, as a final test. */ return (eval_boolexp(descr, player, GETLOCK(thing), thing)); }
void myerror(std::string s) { time_t now; time(&now); double T = difftime(now, _time_start); { GETLOCK(mtx_io, lk); std::cerr << '[' << (int)T << "] " << s << std::flush; } }
void BoundPropagatorMaster::operator() () { bool allDone = false; size_t noPropagated = 0; try { while (!allDone) { SearchNode* n = NULL; Subproblem* sp = NULL; bool hasMore = false; noPropagated = 0; boost::thread* tp = NULL; do { { GETLOCK(m_spaceMaster->mtx_solved, lk); while( m_spaceMaster->solved.empty() && m_spaceMaster->leaves.empty() ) { CONDWAIT(m_spaceMaster->cond_solved, lk); } if (m_spaceMaster->leaves.size()) { // new leaf node to propagate n = m_spaceMaster->leaves.front(); m_spaceMaster->leaves.pop(); } else if (m_spaceMaster->solved.size()) { // new externally solved subproblem sp = m_spaceMaster->solved.front(); n = sp->root; // root node of subproblem // collect subproblem statistics { // myprint("Adding subproblem to statistics\n"); GETLOCK(m_spaceMaster->mtx_stats, lk2); // myprint("Acquired mutex\n"); m_spaceMaster->avgStats->addSubprob(sp); } { // clean up processing thread GETLOCK(m_spaceMaster->mtx_activeThreads, lk2); map< Subproblem*, boost::thread* >::iterator it = m_spaceMaster->activeThreads.find(sp); if (it!=m_spaceMaster->activeThreads.end()) { // tp = m_space->activeThreads.find(p)->second; tp = it->second; m_spaceMaster->activeThreads.erase(sp); tp->join(); delete tp; } } delete sp; m_spaceMaster->solved.pop(); } } // mtx_solved released { // actual propagation GETLOCK(m_spaceMaster->mtx_space, lk); propagate(n, true); ++noPropagated; } { //check if there's more to propagate GETLOCK(m_spaceMaster->mtx_solved, lk); hasMore = !m_spaceMaster->solved.empty() || !m_spaceMaster->leaves.empty(); } } while (hasMore); { // TODO: Make sure race condition can't happen GETLOCK(m_spaceMaster->mtx_searchDone,lk); if (m_spaceMaster->searchDone) { // search process done? GETLOCK(m_spaceMaster->mtx_activeThreads,lk2); if (m_spaceMaster->activeThreads.empty()) { // no more processing threads allDone = true; } } else { // search not done, notify { // notify the search that the buffer is open again GETLOCK(m_spaceMaster->mtx_allowedThreads,lk); m_spaceMaster->allowedThreads += noPropagated; m_spaceMaster->cond_allowedThreads.notify_one(); } } } } // overall while(!allDone) loop myprint("\t!!! PROP done !!!\n"); } catch (boost::thread_interrupted i) { myprint("\t!!! PROP aborted !!!\n"); } }
bool could_doit(int descr, dbref player, dbref thing) { dbref source, dest, owner; if (Typeof(thing) == TYPE_EXIT) { if (DBFETCH(thing)->sp.exit.ndest == 0) { return 0; } owner = OWNER(thing); source = DBFETCH(player)->location; dest = *(DBFETCH(thing)->sp.exit.dest); if (dest == NIL) /* unless its locked, anyone can use #-4 */ return (eval_boolexp(descr, player, GETLOCK(thing), thing)); if (Typeof(dest) == TYPE_PLAYER) { dbref destplayer = dest; dest = DBFETCH(dest)->location; if (!(FLAGS(destplayer) & JUMP_OK) || (FLAGS(dest) & BUILDER)) { return 0; } } /* if (OkObj(thing)) if ( ((FLAG2(player) & F2IMMOBILE) && !(FLAG2(thing) & F2IMMOBILE)) && (!(Typeof(dest) == TYPE_PROGRAM) && !(dest == NIL)) ) { envpropqueue(descr, player, OkObj(player) ? getloc(player) : -1, thing, thing, NOTHING, "@immobile", "Immobile", 1, 1); return 0; } */ /* if( (dest != HOME) && (Typeof(dest)==TYPE_ROOM) && (FLAGS(player) & ZOMBIE) && (Typeof(player) == TYPE_THING) && (FLAGS(dest) & ZOMBIE) ) return 0; Saving this part for a revision of trigger() and this function. */ if ((dest != HOME) && (Typeof(dest) == TYPE_ROOM) && Guest(player) && (tp_guest_needflag ? !(FLAG2(dest) & F2GUEST) : (FLAG2(dest) & F2GUEST))) { /* anotify_nolisten(player, CFAIL "Guests aren't allowed there.", 1); */ return 0; } /* for actions */ if ((DBFETCH(thing)->location != NOTHING) && (Typeof(DBFETCH(thing)->location) != TYPE_ROOM)) { if ((Typeof(dest) == TYPE_ROOM || Typeof(dest) == TYPE_PLAYER) && (FLAGS(source) & BUILDER)) return 0; if (tp_secure_teleport && Typeof(dest) == TYPE_ROOM) { if ((dest != HOME) && (!controls(owner, dest)) && ((FLAGS(dest) & JUMP_OK) == 0)) { return 0; } } } } return (eval_boolexp(descr, player, GETLOCK(thing), thing)); }