Ejemplo n.º 1
0
void Door::hide() {
	leave();

	Situated::hide();
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
	int i, size, ierr, instructionmsg, ctr;
	char hostname[MAX_LINE];
	int hostnamelen, filepoolnumel, claimedfilepoolnumel;
	int *nodepoolentriesk, *nodepoolentriesv;
	int *filepoolkeys, *claimedfilepoolkeys;
	mpiconfig_t mpicfg;
	MPI_Datatype instructmsg_mpi_t;

	MPI_Datatype array_of_types[3];
	int array_of_blocklengths[3];
	MPI_Aint array_of_displaysments[3];
	MPI_Aint intex, charex, lb;

	MPI_Init(&argc, &argv);
	ierr = MPI_Comm_size(MPI_COMM_WORLD, &mpicfg.num_procs);
	ierr = MPI_Comm_rank(MPI_COMM_WORLD, &mpicfg.rank);
	MPI_Get_processor_name(hostname, &hostnamelen);

	ierr = MPI_Type_get_extent(MPI_INT, &lb, &intex);
	ierr = MPI_Type_get_extent(MPI_CHAR, &lb, &charex);

	//Says the type of every block
	array_of_types[0] = MPI_CHAR;
	array_of_types[1] = MPI_INT;
	array_of_types[2] = MPI_INT;

	//Says how many elements for block
	array_of_blocklengths[0] = MAX_LINE;
	array_of_blocklengths[1] = 1;
	array_of_blocklengths[2] = 1;

	/*Says where every block starts in memory, counting from the beginning of the struct.*/
	array_of_displaysments[0] = 0;
	array_of_displaysments[1] = MAX_LINE * charex;
	array_of_displaysments[2] = MAX_LINE * charex + intex;

	/*Create MPI Datatype and commit*/
	MPI_Type_create_struct(3, array_of_blocklengths, array_of_displaysments, array_of_types, &instructmsg_mpi_t);
	MPI_Type_commit(&instructmsg_mpi_t);

	mpicfg.imsg_t = instructmsg_mpi_t;

	if(EBUG){printf("Hello world!  I am process number: %d on host %s\n", mpicfg.rank, hostname);}

	//hashtable_t *nodepool;
	/* Create node/file pool hash table */
	mpicfg.nodepool = ht_create( mpicfg.num_procs );
	mpicfg.filepool = ht_create( mpicfg.num_procs );

	//Initialize structs:
	mpicfg.procstatus = (int*)calloc(mpicfg.num_procs,sizeof(int));
	mpicfg.aliveprocs = (int*)calloc(mpicfg.num_procs,sizeof(int));
	for ( i = 0 ; i < mpicfg.num_procs ; i++) {
		mpicfg.aliveprocs[i]  = -1;
	}
	mpicfg.id = -1;
	mpicfg.stopexecution = 0;

	
	if( mpicfg.rank == 0 ) {
		/*This is the coordinator process.*/

		//Load instructin list:
		/* the coordinator node must be different from the others!! */
		/* Execute next instruction */
		join( &mpicfg, 1 );
		join( &mpicfg, 4 );
		join( &mpicfg, 8 );
		join( &mpicfg, 6 );
		insert( &mpicfg, 9 );
		insert( &mpicfg, 3 );
		insert( &mpicfg, 4 );
		insert( &mpicfg, 9 );

		find( &mpicfg, 4 );
		del( &mpicfg, 4 );
		find( &mpicfg, 4 );
		find( &mpicfg, 3 );
		leave( &mpicfg, 8 );
		find( &mpicfg, 3 );
		

		/*find( &mpicfg, 8 );
		insert( &mpicfg, 5 );
		insert( &mpicfg, 6 );
		insert( &mpicfg, 7 );
		insert( &mpicfg, 8 );
		*/
		end( &mpicfg);

	}else{

		/*All other ranks */
		while (!mpicfg.stopexecution){
			/* Wait instruction message: */
			MPI_Recv(&mpicfg.imsg, 1, mpicfg.imsg_t, 0, 0, MPI_COMM_WORLD,
				 MPI_STATUS_IGNORE);
			/* Execute whatever instruction in that message */
			executeinstruction(&mpicfg, mpicfg.imsg);
		}

	}

	free(mpicfg.procstatus);
	free(mpicfg.aliveprocs);

	ierr = MPI_Finalize();

	return 0;
}
Ejemplo n.º 3
0
PythonState::~PythonState()
{
	leave();
}
Ejemplo n.º 4
0
CServerProxy::EResult
CServerProxy::parseMessage(const UInt8* code)
{
    if (memcmp(code, kMsgDMouseMove, 4) == 0) {
        mouseMove();
    }

    else if (memcmp(code, kMsgDMouseRelMove, 4) == 0) {
        mouseRelativeMove();
    }

    else if (memcmp(code, kMsgDMouseWheel, 4) == 0) {
        mouseWheel();
    }

    else if (memcmp(code, kMsgDKeyDown, 4) == 0) {
        keyDown();
    }

    else if (memcmp(code, kMsgDKeyUp, 4) == 0) {
        keyUp();
    }

    else if (memcmp(code, kMsgDMouseDown, 4) == 0) {
        mouseDown();
    }

    else if (memcmp(code, kMsgDMouseUp, 4) == 0) {
        mouseUp();
    }

    else if (memcmp(code, kMsgDKeyRepeat, 4) == 0) {
        keyRepeat();
    }

    else if (memcmp(code, kMsgCKeepAlive, 4) == 0) {
        // echo keep alives and reset alarm
        CProtocolUtil::writef(m_stream, kMsgCKeepAlive);
        resetKeepAliveAlarm();
    }

    else if (memcmp(code, kMsgCNoop, 4) == 0) {
        // accept and discard no-op
    }

    else if (memcmp(code, kMsgCEnter, 4) == 0) {
        enter();
    }

    else if (memcmp(code, kMsgCLeave, 4) == 0) {
        leave();
    }

    else if (memcmp(code, kMsgCClipboard, 4) == 0) {
        grabClipboard();
    }

    else if (memcmp(code, kMsgCScreenSaver, 4) == 0) {
        screensaver();
    }

    else if (memcmp(code, kMsgQInfo, 4) == 0) {
        queryInfo();
    }

    else if (memcmp(code, kMsgCInfoAck, 4) == 0) {
        infoAcknowledgment();
    }

    else if (memcmp(code, kMsgDClipboard, 4) == 0) {
        setClipboard();
    }

    else if (memcmp(code, kMsgCResetOptions, 4) == 0) {
        resetOptions();
    }

    else if (memcmp(code, kMsgDSetOptions, 4) == 0) {
        setOptions();
    }

    else if (memcmp(code, kMsgDGameButtons, 4) == 0) {
        gameDeviceButtons();
    }

    else if (memcmp(code, kMsgDGameSticks, 4) == 0) {
        gameDeviceSticks();
    }

    else if (memcmp(code, kMsgDGameTriggers, 4) == 0) {
        gameDeviceTriggers();
    }

    else if (memcmp(code, kMsgCGameTimingReq, 4) == 0) {
        gameDeviceTimingReq();
    }

    else if (memcmp(code, kMsgCClose, 4) == 0) {
        // server wants us to hangup
        LOG((CLOG_DEBUG1 "recv close"));
        m_client->disconnect(NULL);
        return kDisconnect;
    }
    else if (memcmp(code, kMsgEBad, 4) == 0) {
        LOG((CLOG_ERR "server disconnected due to a protocol error"));
        m_client->disconnect("server reported a protocol error");
        return kDisconnect;
    }
    else {
        return kUnknown;
    }

    // send a reply.  this is intended to work around a delay when
    // running a linux server and an OS X (any BSD?) client.  the
    // client waits to send an ACK (if the system control flag
    // net.inet.tcp.delayed_ack is 1) in hopes of piggybacking it
    // on a data packet.  we provide that packet here.  i don't
    // know why a delayed ACK should cause the server to wait since
    // TCP_NODELAY is enabled.
    CProtocolUtil::writef(m_stream, kMsgCNoop);

    return kOkay;
}
Ejemplo n.º 5
0
Archivo: savecopy.c Proyecto: wfp5p/elm
/*
 * save_mssg() - Append a mail message to fname_dest.
 */
int save_mssg(const char *fname_dest, const char *fname_mssg,
	      const SEND_HEADER *shdr, int form)
{
    int rc, err;
    size_t len;
    char *fmode;
    long clen_pos, clen_begdata, clen_enddata;
    char buf[SLEN];
    time_t now;
    FILE *fp_copy, *fp_mssg;

    rc = FALSE;
    fp_mssg = fp_copy = NULL;

    if ((fp_mssg = file_open(fname_mssg, "r")) == NULL)
	goto done;
    fmode = (access(fname_dest, ACCESS_EXISTS) == 0 ? "r+" : "w");
    if ((fp_copy = file_open(fname_dest, fmode)) == NULL)
	goto done;
    if (file_seek(fp_copy, 0L, SEEK_END, fname_dest) < 0)
	goto done;

    putc('\n', fp_copy);
    time(&now);
    fprintf(fp_copy, "From %s %s", user_name, ctime(&now));

    /* dump the header to the end of the copy file */
    (void) sndhdr_output(fp_copy, shdr, (form == YES), TRUE);

    /* add Content-Length: for UAs that care about it */
    fputs("Content-Length: ", fp_copy);
    clen_pos = ftell(fp_copy);
    fputs("          \n", fp_copy); /* length fixup to go here */

    /* terminate the header */
    putc('\n', fp_copy);

    /* write out the message body */
    clen_begdata = ftell(fp_copy);
    while ((len = mail_gets(buf, sizeof(buf), fp_mssg)) > 0) {

	if (fwrite(buf, 1, len, fp_copy) != len) {
	    ShutdownTerm();
	    show_error(catgets(elm_msg_cat, ElmSet, ElmWriteFailedSaveMssg,
			"Write failed in save_mssg! [%s]"), strerror(errno));
	    leave(LEAVE_EMERGENCY);
	}

	if (buf[0] == '[') {
	    if (strbegConst(buf, MSSG_DONT_SAVE))
		break;
	    if (strbegConst(buf, MSSG_DONT_SAVE2))
		break;
	}

    }
    clen_enddata = ftell(fp_copy);

    /* ensure message ends with a newline */
    putc('\n', fp_copy);

    /* go fixup the content length header */
    if (file_seek(fp_copy, clen_pos, SEEK_SET, fname_dest) < 0)
	goto done;
    fprintf(fp_copy, "%ld", clen_enddata - clen_begdata);

    /* copy complete */
    if (file_close(fp_copy, fname_dest) < 0)
	goto done;
    fp_copy = NULL;
    if (file_close(fp_mssg, fname_mssg) < 0)
	goto done;
    fp_mssg = NULL;

    rc = TRUE;

done:
    err = errno;
    if (fp_mssg != NULL)
	(void) fclose(fp_mssg);
    if (fp_copy != NULL)
	(void) fclose(fp_copy);
    errno = err;
    return rc;
}
Ejemplo n.º 6
0
void gametile::draw()
{
	glPushAttrib(GL_TEXTURE_BIT);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	if(lightened)	glColor4f(1,1,1,1);
	else			glColor4f(0.5,0.5,0.5,1);
	texture->bind();
	glBegin(GL_POLYGON);
		glTexCoord2f(0,   0.25*th);  glVertex2f(points[4][0], points[4][1]);
		glTexCoord2f(0.5*tw, 0);     glVertex2f(points[3][0], points[3][1]);
		glTexCoord2f(tw,   0.25*th);  glVertex2f(points[2][0], points[2][1]);
		glTexCoord2f(tw,   0.75*th);  glVertex2f(points[1][0], points[1][1]);
		glTexCoord2f(0.5*tw, th);     glVertex2f(points[0][0], points[0][1]);
		glTexCoord2f(0,   0.75*th);  glVertex2f(points[5][0], points[5][1]);
	glEnd();
	texture->release();
	glPopAttrib();

//looking directions shown as red triangles
	glColor4f(1.0,0,0,0.3);
	if(lookdir[0])
	{
		glBegin(GL_TRIANGLES);
		glVertex2f(centerX, centerY);
		glVertex2f(points[0][0], points[0][1]);
		glVertex2f(points[1][0], points[1][1]);
		glEnd();
	}
	if(lookdir[1])
	{
		glBegin(GL_TRIANGLES);
		glVertex2f(centerX, centerY);
		glVertex2f(points[1][0], points[1][1]);
		glVertex2f(points[2][0], points[2][1]);
		glEnd();
	}
	if(lookdir[2])
	{
		glBegin(GL_TRIANGLES);
		glVertex2f(centerX, centerY);
		glVertex2f(points[2][0], points[2][1]);
		glVertex2f(points[3][0], points[3][1]);
		glEnd();
	}
	if(lookdir[3])
	{
		glBegin(GL_TRIANGLES);
		glVertex2f(centerX, centerY);
		glVertex2f(points[3][0], points[3][1]);
		glVertex2f(points[4][0], points[4][1]);
		glEnd();
	}
	if(lookdir[4])
	{
		glBegin(GL_TRIANGLES);
		glVertex2f(centerX, centerY);
		glVertex2f(points[4][0], points[4][1]);
		glVertex2f(points[5][0], points[5][1]);
		glEnd();
	}
	if(lookdir[5])
	{
		glBegin(GL_TRIANGLES);
		glVertex2f(centerX, centerY);
		glVertex2f(points[5][0], points[5][1]);
		glVertex2f(points[0][0], points[0][1]);
		glEnd();
	}

	if(occupied) 
	{
		enter();
		unitTile->draw();
		leave();
	}

	//draw selectioncircle if the unit on this field is selected
	//if(Unit != 0)
	//	drawSelectionCircle();
}
Ejemplo n.º 7
0
void EnMenu::updateEntity( float deltaTime )
{
    // main control state machine
    switch ( _menuState )
    {
        case None:
            break;

        case BeginIntro:
        {
            // let the mouse disappear for intro
            gameutils::GuiUtils::get()->showMousePointer( false );
            _menuState = Intro;
        }
        break;

        case Intro:
        {
            _intro->update( deltaTime );
        }
        break;

        // in order to show up the loading pic we have to activate it
        //  and do the actual level loading one step later, as loading a level blocks the main loop :-(
        case BeginLoadingLevel:
        {
            _p_loadingWindow->show();
            // show up the loading window
            gameutils::GuiUtils::get()->showMousePointer( false ); // let the mouse disappear
            _menuState = PrepareLoadingLevel;
        }
        break;

        case PrepareLoadingLevel:
        {
            // unload level, don't keep physics and entities
            // note: the menu entity is persistent anyway, it handles the level switch itself!
            yaf3d::LevelManager::get()->unloadLevel( true, true );
            _menuState  = LoadingLevel;

            // set the proper game state
            yaf3d::GameState::get()->setState( yaf3d::GameState::StartingLevel );
        }
        break;

        case LoadingLevel:
        {
            // problems getting level file info?
            if ( !_queuedLevelFile.length() )
            {
                _levelSelectDialog->enable( false );
                _menuState = Visible;
                break;
            }

            yaf3d::LevelManager::get()->loadLevel( _queuedLevelFile );
            _queuedLevelFile = ""; // reset the queue

            // now load the player and its other entities
            std::string playerCfgFile;
            vrc::gameutils::PlayerUtils::get()->getPlayerConfig( yaf3d::GameState::get()->getMode(), false, playerCfgFile );
            yaf3d::LevelManager::get()->loadEntities( playerCfgFile );

            // complete level loading
            yaf3d::LevelManager::get()->finalizeLoading();

            // set flag that we have loaded a level; some menu oprions depend on this flag
            _levelLoaded = true;

            // store level scene's static mesh for later switching
            _levelScene = yaf3d::LevelManager::get()->getStaticMesh();

            // now start client networking when we joined to a session
            if ( yaf3d::GameState::get()->getMode() == yaf3d::GameState::Client )
            {
                // try to start client
                try
                {
                    yaf3d::NetworkDevice::get()->startClient();

                    // send the notification on established network session
                    yaf3d::EntityNotification ennotify( YAF3D_NOTIFY_NETWORKING_ESTABLISHED );
                    yaf3d::EntityManager::get()->sendNotification( ennotify );
                }
                catch ( const yaf3d::NetworkException& e )
                {

                    yaf3d::MessageBoxDialog* p_msg = new yaf3d::MessageBoxDialog( "Attention", e.what(), yaf3d::MessageBoxDialog::OK, true );
                    p_msg->show();

                    _menuState = PrepareUnloadLevel;

                    // play attention sound
                    vrc::gameutils::GuiUtils::get()->playSound( GUI_SND_NAME_ATTENTION );

                    return;
                }
            }

            // leave the menu system
            leave();

            // now fade out the loading window
            _menuState = FadeIntoLevel;

            // set the proper game state
            yaf3d::GameState::get()->setState( yaf3d::GameState::MainLoop );
        }
        break;

        case FadeIntoLevel:
        {
            _fadeIntoLevelTimer += deltaTime;
            float alpha = 1.0f - ( _fadeIntoLevelTimer / FADE_INTOLEVEL_TIME );
            _p_loadingWindow->setAlpha( alpha );

            if ( _fadeIntoLevelTimer > FADE_INTOLEVEL_TIME )
            {
                _fadeIntoLevelTimer = 0.0f;

                // restore the alpha and hide the loading window now
                _p_loadingWindow->removeChildWindow( _p_loadingOverly );
                _p_loadingWindow->setAlpha( 1.0f );
                _p_loadingWindow->hide();

                // disable level select dialog now freeing up the resources ( textures )
                _levelSelectDialog->enable( false );
                _p_menuWindow->disable();

                // change to state hidden
                _menuState = Hidden;

                // free up the client level file object which was previously used for getting the loading pic
                if ( _p_clientLevelFiles )
                    delete _p_clientLevelFiles;
                _p_clientLevelFiles = NULL;

            }
        }
        break;

        // unloading a level must be delayed one step due to freeing up graphics objects
        case PrepareUnloadLevel:
        {
            _menuState = UnloadLevel;
            // set the proper game state
            yaf3d::GameState::get()->setState( yaf3d::GameState::LeavingLevel );
            yaf3d::LevelManager::get()->unloadLevel();
        }
        break;

        case UnloadLevel:
        {
            // release the level scene node
            if ( _levelScene.valid() )
                _levelScene = NULL;

            switchMenuScene( true );

            // set the proper game state
            yaf3d::GameState::get()->setState( yaf3d::GameState::MainLoop );

            // reset the game mode
            yaf3d::GameState::get()->setMode( yaf3d::GameState::UnknownMode );

            _menuState = Visible;
        }
        break;

        // currently we do nothing in hidden state, just idle
        case Hidden:
            break;

        case Visible:
        {
            _settingsDialog->update( deltaTime );

            if ( _menuAnimationPath.get() )
            {
                // play the camera animation during the user is in menu
                vrc::gameutils::TransformationVisitor tv( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ); // see vrc_utils.h in framework
                _menuAnimationPath->accept( tv );
                const osg::Matrixf&  mat = tv.getMatrix();
                osg::Quat rot;
                mat.get( rot );
                osg::Vec3f pos = mat.getTrans();
                _p_cameraControl->setCameraTransformation( pos, rot );
            }

            // handle menu idling
            {
                if ( _idleCounter >= 0.0 )
                {
                    _idleCounter -= deltaTime;
                }

                if ( _idleCounter < 0.0 )
                {
                    // start idle mode
                    _p_menuWindow->hide();
                    yaf3d::GuiManager::get()->showMousePointer( false );
                }
            }
        }
        break;

        case Quitting:
        {
            // quit the application now
            yaf3d::Application::get()->stop();
        }
        break;

        default:
            assert( NULL && "invalid menu state!" );

    }

    // control the menu background sound on entering and leaving menu
    switch ( _menuSoundState )
    {
        case SoundStopped:
            break;

        case SoundFadeIn:
        {
            _p_backgrdSound->startPlaying( true );
            _menuSoundState = SoundFadingIn;
        }
        break;

        case SoundFadingIn:
        {
            _soundFadingCnt += deltaTime;
            if ( _soundFadingCnt > BCKRGD_SND_FADEIN_PERIOD )
            {
                _soundFadingCnt = 0.0f;
                _menuSoundState = SoundStopped;
                break;
            }

            float volume = std::min( _soundFadingCnt / BCKRGD_SND_FADEIN_PERIOD, _backgrdSoundVolume );
            _p_backgrdSound->setVolume( volume );
        }
        break;

        case SoundFadeOut:
        {
            _soundFadingCnt += deltaTime;
            if ( _soundFadingCnt > BCKRGD_SND_FADEIN_PERIOD )
            {
                _p_backgrdSound->stopPlaying( true );
                _soundFadingCnt = 0.0f;
                _menuSoundState = SoundStopped;
                break;
            }

            float volume = std::max( _backgrdSoundVolume * ( 1.0f - _soundFadingCnt / BCKRGD_SND_FADEOUT_PERIOD ), 0.0f );
            _p_backgrdSound->setVolume( volume );
        }
        break;

        default:
            assert( NULL && "unknown menu sound state!" );
    }
}
Ejemplo n.º 8
0
Archivo: error.c Proyecto: optixx/vasm
static void error(int n,va_list vl,struct err_out *errlist,int offset)
{
  static source *last_err_source = NULL;
  static int last_err_no;
  static int last_err_line;
  FILE *f;
  const char *msgkind;
  int lineno;
  int msgno;
  int flags=errlist[n].flags;

  if ((flags&DONTWARN) || ((flags&WARNING) && no_warn))
    return;

  if (last_err_source) {
    /* avoid printing the same error again and again, which might happen
       when a line is evaluated in multiple passes */
    if (cur_src!=NULL && cur_src==last_err_source &&
       cur_src->line==last_err_line &&
       n+offset==last_err_no)
      return;
  }

  if ((flags&MESSAGE) && !(flags&(WARNING|ERROR|FATAL)))
    f = stdout;  /* print messages to stdout */
  else
    f = stderr;  /* otherwise stderr */

  if (cur_src) {
    last_err_source = cur_src;
    last_err_line = cur_src->line;
    last_err_no = n + offset;
  }
  fprintf(f,"\n");

  if (cur_listing)
    cur_listing->error = n + offset;

  if (flags & ERROR) {
    ++errors;
    if(max_errors!=0 && errors>max_errors){
      fprintf(f,"***maximum number of errors reached!***\n");
      leave();
    }
    msgkind = "error";
  }
  else if (flags & WARNING)
    msgkind = "warning";
  else if (flags & MESSAGE)
    msgkind = "message";
  else
	msgkind = "info";

  msgno = n+offset;

  if (!(flags & NOLINE) && cur_src!=NULL)
	  fprintf(f,"%s(%d): ", cur_src->name, cur_src->line);

  fprintf(f,"%s%s %d: ", (flags & FATAL) ? "fatal " : "", msgkind, msgno);

  vfprintf(f,errlist[n].text,vl);
  fprintf(f,"\n");

  if (!(flags & NOLINE) && cur_src!=NULL) {
    if (cur_src->parent != NULL) {
      source *parent,*child;
    
      child = cur_src;
      while (parent = child->parent) {
        if (child->num_params >= 0)
          fprintf(f,"\tcalled");    /* macro called from */
        else
          fprintf(f,"\tincluded");  /* included from */
        fprintf(f," from line %d of \"%s\"\n",child->parent_line,parent->name);
        child = parent;
      }
    }
    print_source_line(f);
  }

  if (flags & FATAL) {
    fprintf(f,"aborting...\n");
    leave();
  }
}
Ejemplo n.º 9
0
void KKVideoFlushWidget::hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
{
	emit leave();
}
Ejemplo n.º 10
0
void Cluster::stopClusterNode(Lock& l) {
    QPID_LOG(notice, *this << " cluster member stopped by administrator.");
    leave(l);
}
Ejemplo n.º 11
0
void Cluster::leave() {
    Lock l(lock);
    leave(l);
}
Ejemplo n.º 12
0
void Cluster ::shutdown(const MemberId& , const Uuid& id, Lock& l) {
    QPID_LOG(notice, *this << " cluster shut down by administrator.");
    if (store.hasStore()) store.clean(id);
    leave(l);
}
Ejemplo n.º 13
0
handler::~handler()
{
	leave();
	SDL_EnableUNICODE(unicode_);
}
Ejemplo n.º 14
0
main()
{
  register struct pw_item *i;
  register struct st_item *s;
  register long k, errors;
  long pid, status;
  char command[80];
  
  putenv("_=orphan_picks");
  chdir(getenv("HOME"));
  
  database_open();

  ss_open();
  co_open();
  oc_open();
  od_open();
  
  if (sp->sp_sku_support == 'n') leave(0);
  
  errors = 0;
  tmp_name(fd_name);
  
  fd = fopen(fd_name, "w");
  if (fd == 0) krash("main", "open temp", 1);
  
  if (sp->sp_sku_support == 'y')           /* only when sku support          */
  {
    for (k = 0, i = pw; k < coh->co_prod_cnt; k++, i++)
    {
      if (i->pw_lines_to_go <= 0) continue;  /* has no picks                 */
  
      s = mod_lookup(k + 1);               /* find in sku table              */
      if (s) continue;                     /* module has a sku               */
    
      fprintf(fd, "No SKU Assigned To Module %d Has %d Picks\n", 
        k + 1, i->pw_lines_to_go);

      errors++;
    }
  }
#ifdef DEBUG
  fprintf(stderr, "errors=%d\n", errors);
#endif

  fprintf(fd, "\n\n");
  pick_setkey(1);
  
  begin_work();
  while (!pick_next(op_rec, NOLOCK))
  {
#ifdef DEBUG
  fprintf(stderr, "pl=%d  on=%d  mod=%d  flag=%x\n",
    op_rec->pi_pl, op_rec->pi_on, op_rec->pi_mod, op_rec->pi_flags);
#endif

    commit_work();
    begin_work();
    
    if (op_rec->pi_flags & VALIDATED) continue;
  
    fprintf(fd, 
      "Pickline: %2d  Order: %7.*d  Mod: %5d  SKU: %-15.15s  Quan: %3d\n",

      op_rec->pi_pl, rf->rf_on, op_rec->pi_on, op_rec->pi_mod,
      op_rec->pi_sku, op_rec->pi_ordered);

    errors++;
  }
  commit_work();
  fclose(fd);

  if (errors)
  {
    tmp_name(ed_name);

    if (fork() == 0)
    {
      execlp("prft", "prft", fd_name, ed_name, "sys/report/orphan_picks.h", 0);
      krash("main", "load prft", 1);
    }
    pid = wait(&status);
    if (!pid || status) krash("main", "prft failed", 1);
   
    sprintf(command, "%s %s", getenv("LPR"), fd_name);
  }
  else unlink(fd_name);
  leave(0);
}
Ejemplo n.º 15
0
void LocalPC::setSetupTime(double time)
{
    enter();
    mSetupTime = time;
    leave();
}
Ejemplo n.º 16
0
void Placeable::hide() {
	leave();

	Situated::hide();
}
Ejemplo n.º 17
0
int multicastcapture_close(multicastcapture h) {
	multicastcapture_t* context = (multicastcapture_t*) h;
	leave(context->conn);
	return 0;
}
Ejemplo n.º 18
0
main()
{
  short rm;
  short ret;
  unsigned char t;
  char buf[NUM_PROMPTS][BUF_SIZE];        /* array of buffers                */

  short i;
  short n;

  putenv("_=printer_control");
  chdir(getenv("HOME"));

  open_all();

  while(1)                                /* begin massive loop              */
  {
    fix(berkeley_control);
    sd_screen_off();
    sd_clear_screen();                    /* clear screen                    */
    sd_text(berkeley_control);
    sd_screen_on();

                /* clear input buffers */

    for(i = 0; i < NUM_PROMPTS; i++)
    for(n = 0; n < BUF_SIZE; n++)
    buf[i][n] = 0;


                /* main loop to get code */

    while(1)
    {
      t = sd_input(&fld[0],sd_prompt(&fld[0],0),&rm,buf[0],0);

      if (t == EXIT) leave();
      if (t == UP_CURSOR) continue;

      *buf[0] = tolower(*buf[0]);      
      
      if (*buf[0] == 'a' || *buf[0] == 'c' || 
          *buf[0] == 'k' || *buf[0] == 's' || 
          *buf[0] == 'r' || *buf[0] == 'd')  break;
      
      eh_post(ERR_CODE, buf[0]);
    }
    if (*buf[0] == 'c')
    {
      t = sd_input(&fld1, sd_prompt(&fld1, 0), 0, op_printer, 0);
      if (t == EXIT) leave();
      if (t == UP_CURSOR) continue;
      
      message_put(sd_server, ChangePrinterEvent, op_printer, 
        strlen(op_printer));

      sprintf(printer, "PRINTER=%s", op_printer);
      putenv(printer);
      continue;
    }
                /* code entered. display second prompt */

    if(buf[0][0] != 'd')                  /* not display                     */
    {
      while (*buf[0] == 'k')
      {
        sd_prompt(&fld[1],0);
        t = sd_input(&fld[1],0,&rm,buf[1],0);
        if(t == EXIT) leave();
        else if(t == RETURN) break;
      }
      switch(buf[0][0])    
      {
        case 'a':                         /* abort current print job         */
        
          sd_wait();
          sd_cursor(0, 18, 27);
          sd_text(".");
          sprintf(command, "cancel %s", op_printer);
          system(command);
          sleep(2);
          break;

        case 'k':                         /* kill print file                 */
          
          sd_wait();
          sd_cursor(0, 18, 27);
          sd_text(".");
          sprintf(command, "cancel %s-%s", op_printer, buf[1]);
          system(command);
          sleep(2);
          break;
          
        case 's':                         /* stop print file                 */
          
          sd_wait();
          sd_cursor(0, 18, 27);
          sd_text(".");
          sprintf(command, "disable %s", op_printer);
          system(command);
          sleep(2);
          break;
          
        case 'r':                         /* restart printing                */
          
          sd_wait();
          sd_cursor(0, 18, 27);
          sd_text(".");
          sprintf(command, "enable %s", op_printer);
          system(command);
          sleep(2);
          break;
      }
      continue;
    }
    else                                  /* display request                 */
    {
      sd_cursor(0,16,2);
      sd_text("Job ID                  Operator          Size   Date");
    }
/*
 *  Get Printer Queue Data
 */
    tmp_name(tname);                      /* get temp name                   */
    sprintf(command, "lpstat -o %s >%s", op_printer, tname);
    system(command);

    t_fd = fopen(tname, "r");
    if (t_fd == 0) continue;              /* open failed                     */
    
    memset(x, 0, sizeof(x));
    
    for (max = 0; max < 25; max++)
    {
      if (!fgets(x[max], 80, t_fd)) break;
      n = strlen(x[max]) - 1;
      x[max][n] = 0;
    }
    n = 0;

    fclose(t_fd);
    unlink(tname);

    while(1)
    {
      sd_cursor(0, 17, 1);
      sd_clear_rest();

      for (i = 0; i < 5 && n + i < max; i++)
      {
        sd_cursor(0, 17 + i, 2);
        sd_text(x[i + n]);
      }
      sd_cursor(0,23,23);
      sd_text("(Exit, Forward, or Backward)");
      sd_prompt(&fld[2],0);

      t = sd_input(&fld[2],0,&rm,buf[2],0);

      ret = sd_more(t, code_to_caps(buf[2][0]));  /* F041897 */
                        
      if (ret == 0) leave();               /* exit                           */
      
      else if (ret == 1)                  /* forward                         */
      {
        if (n + 5 < max) n += 5;
      }
      else if (ret == 2)                  /* backward                        */
      {
        if (n > 0) n -= 5;
      }
      else if (ret == 3) break;           /* quit display                    */
    }
  }                                       /* end massive while(1)loop        */

}
Ejemplo n.º 19
0
main()
{
  long pid, status;
  short rm,ret,i,si,n;
  unsigned char t;
  char buf[NUM_PROMPTS][BUF_SIZE];
  long order_num=0;
  short pickline;
  short all_pl=0;

  putenv("_=stockout_input");
  chdir(getenv("HOME"));
  
  open_all();

        /* set order length into fld_parms structure */

  LORDER = rf->rf_on;

        /* determine operator status */

  rm = 0; si = 1;
  if (SUPER_OP && !IS_ONE_PICKLINE) {rm = 1; si = 0;}
  pickline = op_pl;
  sprintf(buf[0], "%d", pickline);
  
  fix(stockout_input);
  sd_clear_screen();
  sd_screen_off();
  sd_text(stockout_input);
  sd_screen_on();

  for(i=0;i<NUM_PROMPTS;i++)
  for(n=0;n<BUF_SIZE;n++)
  buf[i][n] = 0;

  for(i = si; i < LAST_PROMPT; i++)
  sd_prompt(&fld[i],rm);                  /* display prompts                 */
  i = si;


        /* main loop to gather input */

  while(1)
  {
    t = sd_input(&fld[i],rm,&rm,buf[i],0);

    if(t == EXIT) leave();
    else if(t == UP_CURSOR && i > si) i--;
    
    else if(t == DOWN_CURSOR || t == TAB)
    {
      if(i == (LAST_PROMPT - 1)) i = 0;
      else i++;
    }
    else if (t == RETURN)
    {
                        /* validate proper pickline */

      if (si == 0)                        /* have pickline input             */
      {
        n = pl_lookup(buf[0], pickline);  /* numeric of pickline             */

        if (n <= 0)          
        {
          eh_post(ERR_CODE,buf[0]);       /* invalid pickline                */
          i=0;
          continue;
        }
        pickline = n;
        sprintf(buf[0], "%d", pickline);
        chng_pkln(buf[0]);
      }          
                        /* validate entered order number */

      if(!(*buf[1]) && !(*buf[2]))        /* nothing entered                 */
      {
        eh_post(ERR_REQ_ORDER, 0);
        i=1;
        continue;
      }
      if(*buf[2])                         /* if order number entered         */
      {
        order_num=atol(buf[2]);
        ret = oc_find(pickline, order_num);
        if(!ret)
        {
          eh_post(ERR_ORDER,buf[2]);
          i=2;
          continue;
        }
      }
      break;
    }
  }

        /* process print request */

  for(i=1;i<3;i++)                        /* fill non-entered with zero      */
  {
    if(*buf[i])
    ;
    else
    strcpy(buf[i],"0");
  }

  sd_prompt(&fld[4],rm);
  while(1)
  {
    t = sd_input(&fld[4],rm,&rm,buf[4],0);
    switch(sd_early(t, code_to_caps(*buf[4]))) /* F041897 */
    {
      case (0):
        leave();

      case (4):                           /* print == y                      */
        if(!(*buf[0]))                    /* no pickline entered             */
        {
          strcpy(buf[0], getenv("PICKLINE"));/* set current                  */
        }
        sd_wait();
        close_all();
        execlp("stockout_create", "stockout_create",
          buf[0], buf[1], buf[2], "", "print",  0);

        krash("main", "stockout_create load", 1);

      case (5):                           /* print == n                      */
        
        sd_wait();
        if(!(*buf[0]))                    /* no pickline entered             */
        {
          strcpy(buf[0], getenv("PICKLINE"));/* set current                  */
        }
        close_all();
        execlp("stockout_create", "stockout_create",
          buf[0], buf[1], buf[2], "", "report",  0);

        krash("main", "stockout_create load", 1);

      case (6):
        eh_post(ERR_YN,0);
        break;
      }
  }
}
Ejemplo n.º 20
0
bool Scheduler::futexWait(bool bitmask, bool pi_waiter, uint32_t pid, uint32_t tid, FutexInfo fi, CONTEXT* ctxt, SYSCALL_STANDARD std) {
    DEBUG_FUTEX("Scheduler: FUTEX WAIT called with bitmask %d pi %d pid %u tid %u", bitmask, pi_waiter, pid, tid);
    uint64_t wakeUpPhases = getFutexWakePhase(pi_waiter, fi, ctxt, std);  //pi versions all interpret as realtime
    futex_lock(&schedLock);
    uint32_t cid = gidMap[getGid(pid, tid)]->cid;
    futex_unlock(&schedLock);
    if(wakeUpPhases == 0) {
      wakeUpPhases = 0xffffffff;
    }
    FutexWaiter tempWaiter; tempWaiter.pid = pid; tempWaiter.tid = tid;   tempWaiter.pi_waiter = pi_waiter;
    tempWaiter.mask = 0xffffffff; tempWaiter.val = fi.val; tempWaiter.fi = fi; tempWaiter.allow_requeue = !pi_waiter;
    if(!pi_waiter) { //Normal cases
        if(fi.val != *fi.uaddr) {
            DEBUG_FUTEX("Cur val didn't match val in futex wait");
            return false;
        }
        DEBUG_FUTEX("WAIT took normal path");
        if(bitmask) {
            tempWaiter.mask = fi.val3;
        }
        futexTable[fi.uaddr].push_back(tempWaiter);
        markForSleep(pid, tid, wakeUpPhases);
        leave(pid, tid, cid);
    } else {    //if pi_waiter
        switch (fi.op & FUTEX_CMD_MASK) {
            case FUTEX_LOCK_PI:
                DEBUG_FUTEX("WAIT took lock path");
                if(futexTable[fi.uaddr].size() == 0) // Check that no one else is in line.
                {
                    DEBUG_FUTEX("FUTEX_LOCK_PI successfully locked");
                    futexTable[fi.uaddr].push_back(tempWaiter); //Notice we don't deschedule
                    return true;
                } else {
                  DEBUG_FUTEX("LOCK delayed");
                  if(bitmask) {
                      tempWaiter.mask = fi.val3;
                  }
                  futexTable[fi.uaddr].push_back(tempWaiter);
                  markForSleep(pid, tid, wakeUpPhases);
                  leave(pid, tid, cid);
                }
                break;
            case FUTEX_WAIT_REQUEUE_PI:
                DEBUG_FUTEX("WAIT took reque pi path");
                if(fi.val != *fi.uaddr) {
                    DEBUG_FUTEX("Cur val didn't match val in futex wait");
                    return false;
                }
                tempWaiter.allow_requeue = true;
                if(bitmask) {
                    tempWaiter.mask = fi.val3;
                }
                markForSleep(pid, tid, wakeUpPhases);
                leave(pid, tid, cid);
                futexTable[fi.uaddr].push_back(tempWaiter);
                break;
            case FUTEX_TRYLOCK_PI:
                DEBUG_FUTEX("WAIT took trylock path");
                if(futexTable[fi.uaddr].size() == 0) {
                    DEBUG_FUTEX("FUTEX_LOCK_PI successfully locked");
                    futexTable[fi.uaddr].push_back(tempWaiter); //Notice we don't deschedule
                    return true;
                } else {
                    return false;
                }
                break;
            default:
                panic("We missed something in futex wait.");
        }
    }
    return true;
}
Ejemplo n.º 21
0
main()
{
  register long k;
  unsigned char t;
  struct fld_parms fld;

  putenv("_=record_format_srn");
  chdir(getenv("HOME"));

  sd_open(leave);
  sd_echo_flag = 0x20;
  ss_open();
  co_open();
  
  fix(record_format_srn);
  sd_screen_off();
  sd_clear_screen();
  sd_text(record_format_srn);
  sd_screen_on();
  
  memcpy(&x, rf, sizeof(struct rf_item));
  
  for (k = 0; k < NUM_PROMPTS; k++) show_field(k);
  
/*
 *  Only Super Operator May Input Data
 */
  getparms(0);
  
  if (!SUPER_OP)
  {
    eh_post(ERR_SUPER, 0);
    sd_cursor(0, 23, 3);
    sd_text("* * *  Hit Any Key   * * *");
    t = sd_keystroke(NOECHO);
    leave();
  }
  k = 0;
  
  while (1)
  {
    fld.irow   = field[k].row;
    fld.icol   = field[k].col;
    fld.pcol   = 0;
    fld.arrow  = 0;
    fld.length = &field[k].len;
    fld.prompt = 0;
    fld.type   = field[k].type;
    
    get_field(k); 

    t = sd_input(&fld, 0, 0, buf, 0);
  
    put_field(k);
    
    if (t == EXIT) leave();
    
    if (field[k].type == 'a')
    {
      if (field[k].valid)
      {
        if (!memchr(field[k].valid, *buf, strlen(field[k].valid)))
        {
          eh_post(ERR_CODE, buf);
          continue;
        }
      }
    }
    else
    {
      if (value < field[k].min || value > field[k].max)
      {
        eh_post(ERR_CODE, buf);
        continue;
      }
    }
    switch(k)
    {
      case 0:  if (x.rf_rp == 0x20 || !x.rf_rp)
               {
                 eh_post(ERR_PREFACE, 0);
                 x.rf_rp = rf->rf_rp;
                 continue;
               }
               break;
               
      case 1:  if (x.rf_rt == 0x20) x.rf_rt = 0; break;
      
      case 2:  if (x.rf_ft == 0x20) x.rf_ft = 0; break;
      
      case 3:  if (x.rf_eof == 0x20) x.rf_eof = 0; break;
      
      case 13: if (x.rf_box_pos > x.rf_rmks)
               {
                 eh_post(ERR_CODE, buf);
                 continue;
               }
               break;
               
      case 14: if (x.rf_box_len && !x.rf_rmks)
               {
                 eh_post(ERR_CODE, buf);
                 continue;
               }
               break;
      
      case 15: if (x.rf_box_count && !x.rf_box_len)
               {
                 eh_post(ERR_CODE, buf);
                 continue;
               }
               break;

    }
    show_field(k);
    
    if (t == UP_CURSOR) {if (k > 0) k--;}
    else if (t == RETURN) break;
    else 
    {
      k++;
      if (k >= NUM_PROMPTS) k = 0;
    }
  }
  sd_prompt(&fld1, 0);
  memset(buf, 0, 2);
  t = sd_input(&fld1, 0, 0, buf, 0);
  if (t == EXIT) leave();
  *buf = tolower(*buf);
  if (*buf == 'y')
  {
    memcpy(rf, &x, sizeof(struct rf_item));
    system("ss_dump -sp= -rf=sys/rf_text 1>/dev/null 2>/dev/null");
  }
  leave();
}
Ejemplo n.º 22
0
void
process(int ch)
{
	int x,y;
	struct body *nh;

	x = head->x;
	y = head->y;
	switch(ch)
	{
#ifdef KEY_LEFT
		case KEY_LEFT:
#endif
		case 'h':
			x--; break;
#ifdef KEY_DOWN
		case KEY_DOWN:
#endif
		case 'j':
			y++; break;
#ifdef KEY_UP
		case KEY_UP:
#endif
		case 'k':
			y--; break;
#ifdef KEY_RIGHT
		case KEY_RIGHT:
#endif
		case 'l':
			x++; break;
		case 'H': x--; running = RUNLEN; ch = tolower(ch); break;
		case 'J': y++; running = RUNLEN/2; ch = tolower(ch); break;
		case 'K': y--; running = RUNLEN/2; ch = tolower(ch); break;
		case 'L': x++; running = RUNLEN; ch = tolower(ch); break;
		case '\f': setup(); return;
		case CNTRL('Z'): suspend(0); return;
		case CNTRL('C'): crash(); return;
		case CNTRL('D'): crash(); return;
		case ERR: leave(0); return;
		default: return;
	}
	lastch = ch;
	if (growing == 0)
	{
		display(tail, ' ');
		tail->next->prev = NULL;
		nh = tail->next;
		free(tail);
		tail = nh;
		visible_len--;
	}
	else growing--;
	display(head, BODY);
	wmove(tv, y, x);
	if (isdigit(ch = winch(tv)))
	{
		growing += ch-'0';
		prize();
		score += growing;
		running = 0;
		wmove(stw, 0, COLS - 12);
		wprintw(stw, "Score: %3d", score);
		wrefresh(stw);
	}
	else if(ch != ' ') crash();
	nh = newlink();
	nh->next = NULL;
	nh->prev = head;
	head->next = nh;
	nh->y = y;
	nh->x = x;
	display(nh, HEAD);
	head = nh;
	visible_len++;
	if (!(slow && running)) {
		wmove(tv, head->y, head->x);
		wrefresh(tv);
	}
}
Ejemplo n.º 23
0
void CopasiWidget::refresh()
{
  leave();
  qApp->processEvents();
  enter(mObjectCN);
}
Ejemplo n.º 24
0
void LocalPC::setHandler(ILocalPC *handler)
{
    enter();
    mHandler = handler;
    leave();
}
Ejemplo n.º 25
0
void Spectator::visit(std::shared_ptr<Courthouse>& c) {
    courthouse = c;
    enter();
    spectate();
    leave();
}
Ejemplo n.º 26
0
void LocalPC::updateSetupTime()
{
    enter();
    GET_TIME(mSetupTime);
    leave();
}
Ejemplo n.º 27
0
void Scheduler::watchdogThreadFunc() {
    info("Started scheduler watchdog thread");
    uint64_t lastPhase = 0;
    int multiplier = 1;
    uint64_t lastMs = 0;
    uint64_t fakeLeaveStalls = 0;
    while (true) {
        TrueSleep(multiplier*WATCHDOG_INTERVAL_USEC);

        if (zinfo->terminationConditionMet) {
            // Synchronize to avoid racing with EndOfPhaseActions code
            // (zinfo->terminationConditionMet is set on EndOfPhaseActions,
            // which has schedLock held, we must let it finish)
            futex_lock(&schedLock);
            info("Terminating scheduler watchdog thread");
            futex_unlock(&schedLock);
            SimEnd();
        }

        //Fastpath (unlocked, benign read races, only modifies local state)
        if (lastPhase != curPhase && pendingPidCleanups.size() == 0) {
            lastPhase = curPhase;
            fakeLeaveStalls = 0;
            if (multiplier < WATCHDOG_MAX_MULTIPLER) multiplier++;
            continue;
        }

        //if (lastPhase == curPhase && scheduledThreads == outQueue.size() && !sleepQueue.empty()) info("Mult %d curPhase %ld", multiplier, curPhase);

        futex_lock(&schedLock);

        if (lastPhase == curPhase && !fakeLeaves.empty() && (fakeLeaves.front()->th->futexJoin.action != FJA_WAKE)) {
            if (++fakeLeaveStalls >= WATCHDOG_STALL_THRESHOLD) {
                info("Detected possible stall due to fake leaves (%ld current)", fakeLeaves.size());
                // Uncomment to print all leaves
                FakeLeaveInfo* pfl = fakeLeaves.front();
                while (pfl) {
                    info(" [%d/%d] %s (%d) @ 0x%lx", getPid(pfl->th->gid), getTid(pfl->th->gid), GetSyscallName(pfl->syscallNumber), pfl->syscallNumber, pfl->pc);
                    pfl = pfl->next;
                }

                // Trigger a leave() on the first process, if the process's blacklist regex allows it
                FakeLeaveInfo* fl = fakeLeaves.front();
                ThreadInfo* th = fl->th;
                uint32_t pid = getPid(th->gid);
                uint32_t tid = getTid(th->gid);
                uint32_t cid = th->cid;

                const g_string& sbRegexStr = zinfo->procArray[pid]->getSyscallBlacklistRegex();
                std::regex sbRegex(sbRegexStr.c_str());
                if (std::regex_match(GetSyscallName(fl->syscallNumber), sbRegex)) {
                    // If this is the last leave we catch, it is the culprit for sure -> blacklist it
                    // Over time, this will blacklist every blocking syscall
                    // The root reason for being conservative though is that we don't have a sure-fire
                    // way to distinguish IO waits from truly blocking syscalls (TODO)
                    if (fakeLeaves.size() == 1) {
                        info("Blacklisting from future fake leaves: [%d] %s @ 0x%lx | arg0 0x%lx arg1 0x%lx", pid, GetSyscallName(fl->syscallNumber), fl->pc, fl->arg0, fl->arg1);
                        blockingSyscalls[pid].insert(fl->pc);
                    }

                    uint64_t pc = fl->pc;
                    do {
                        finishFakeLeave(th);

                        futex_unlock(&schedLock);
                        leave(pid, tid, cid);
                        futex_lock(&schedLock);

                        // also do real leave for other threads blocked at the same pc ...
                        fl = fakeLeaves.front();
                        if (fl == nullptr || getPid(th->gid) != pid || fl->pc != pc)
                            break;
                        th = fl->th;
                        tid = getTid(th->gid);
                        cid = th->cid;
                        // ... until a lower bound on queue size, in order to make blacklist work
                    } while (fakeLeaves.size() > 8);
                } else {
                    info("Skipping, [%d] %s @ 0x%lx | arg0 0x%lx arg1 0x%lx does not match blacklist regex (%s)",
                            pid, GetSyscallName(fl->syscallNumber), fl->pc, fl->arg0, fl->arg1, sbRegexStr.c_str());
                }
                fakeLeaveStalls = 0;
            }
        } else {
            fakeLeaveStalls = 0;
        }

        if (lastPhase == curPhase && scheduledThreads == outQueue.size() && !sleepQueue.empty()) {
            //info("Watchdog Thread: Sleep dep detected...")
            int64_t wakeupPhase = sleepQueue.front()->wakeupPhase;
            int64_t wakeupCycles = (wakeupPhase - curPhase)*zinfo->phaseLength;
            int64_t wakeupUsec = (wakeupCycles > 0)? wakeupCycles/zinfo->freqMHz : 0;

            //info("Additional usecs of sleep %ld", wakeupUsec);
            if (wakeupUsec > 10*1000*1000) warn("Watchdog sleeping for a long time due to long sleep, %ld secs", wakeupUsec/1000/1000);

            futex_unlock(&schedLock);
            TrueSleep(WATCHDOG_INTERVAL_USEC + wakeupUsec);
            futex_lock(&schedLock);

            if (lastPhase == curPhase && scheduledThreads == outQueue.size() && !sleepQueue.empty()) {
                ThreadInfo* sth = sleepQueue.front();
                uint64_t curMs = curPhase*zinfo->phaseLength/zinfo->freqMHz/1000;
                uint64_t endMs = sth->wakeupPhase*zinfo->phaseLength/zinfo->freqMHz/1000;
                (void)curMs; (void)endMs; //make gcc happy
                if (curMs > lastMs + 1000) {
                    info("Watchdog Thread: Driving time forward to avoid deadlock on sleep (%ld -> %ld ms)", curMs, endMs);
                    lastMs += 1000;
                }
                while (sth->state == SLEEPING) {
                    idlePhases.inc();
                    callback(); //sth will eventually get woken up

                    if (futex_haswaiters(&schedLock)) {
                        //happens commonly with multiple sleepers and very contended I/O...
                        //info("Sched: Threads waiting on advance, startPhase %ld curPhase %ld", lastPhase, curPhase);
                        break;
                    }

                    if (zinfo->terminationConditionMet) {
                        info("Termination condition met inside watchdog thread loop, exiting");
                        break;
                    }
                }
                idlePeriods.inc();
                multiplier = 0;
            }
        }

        if (multiplier < WATCHDOG_MAX_MULTIPLER) {
            multiplier++;
        }

        lastPhase = curPhase;

        //Lazily clean state of processes that terminated abruptly
        //NOTE: For now, we rely on the process explicitly telling us that it's going to terminate.
        //We could make this self-checking by periodically checking for liveness of the processes we're supposedly running.
        //The bigger problem is that if we get SIGKILL'd, we may not even leave a consistent zsim state behind.
        while (pendingPidCleanups.size()) {
            std::pair<uint32_t, uint32_t> p = pendingPidCleanups.back();
            uint32_t pid = p.first; //the procIdx pid
            uint32_t osPid = p.second;

            std::stringstream ss;
            ss << "/proc/" << osPid;
            struct stat dummy;
            if (stat(ss.str().c_str(), &dummy) == 0) {
                info("[watchdog] Deferring cleanup of pid %d (%d), not finished yet", pid, osPid);
                break;
            }

            pendingPidCleanups.pop_back(); //must happen while we have the lock

            futex_unlock(&schedLock);
            processCleanup(pid);
            futex_lock(&schedLock);
        }

        if (terminateWatchdogThread) {
            futex_unlock(&schedLock);
            break;
        } else {
            futex_unlock(&schedLock);
        }
    }
    info("Finished scheduler watchdog thread");
}
Ejemplo n.º 28
0
void LocalPC::setPort(int port)
{
    enter();
    mTcpServer->setPort(port);
    leave();
}
Ejemplo n.º 29
0
void customer() {
  sem_signal(customer_waiting);
  sem_wait(barber_sleeping);
  get_haircut();
  leave();
}
Ejemplo n.º 30
0
Truck::~Truck()
{
    if (m_leaveOnDestruction)
        leave();
    clearFlavors();
}