Beispiel #1
0
void RBench::Start(BOOLEAN trace) {
//    clock_t t1, t2, t3, t4;
    TaskState *t;
    Packet *workQ;

    if (trace) InitTrace(); else tracing = FALSE;
    InitScheduler();
//    t1 = clock();
//    printf("\nRichards benchmark: initializing...\n");
    t = new TaskState; t->Running();				// Idler
    CreateIdler(Idler, 0, NoWork, t);

    workQ = new Packet(NoWork, Worker, WorkPacket);		// Worker
    workQ = new Packet(workQ , Worker, WorkPacket);
    t = new TaskState; t->WaitingWithPacket();
    CreateWorker(Worker, 1000, workQ, t);

    workQ = new Packet(NoWork, DeviceA, DevicePacket);		// HandlerA
    workQ = new Packet(workQ , DeviceA, DevicePacket);
    workQ = new Packet(workQ , DeviceA, DevicePacket);
    t = new TaskState; t->WaitingWithPacket();
    CreateHandler(HandlerA, 2000, workQ, t);

    workQ = new Packet(NoWork, DeviceB, DevicePacket);		// HandlerB
    workQ = new Packet(workQ , DeviceB, DevicePacket);
    workQ = new Packet(workQ , DeviceB, DevicePacket);
    t = new TaskState; t->WaitingWithPacket();
    CreateHandler(HandlerB, 3000, workQ, t);

    t = new TaskState; t->Waiting();				// DeviceA
    CreateDevice(DeviceA, 4000, NoWork, t);
    t = new TaskState; t->Waiting();				// DeviceB
    CreateDevice(DeviceB, 5000, NoWork, t);

//    printf("starting...\n");
//    t2 = clock();
    Schedule();
//    t3 = clock();
//    printf("done.\n");

//    printf("QueuePacketCount = %d, HoldCount = %d.\nThese results are %s",
//           queuePacketCount, holdCount,
//           (queuePacketCount == 23246 && holdCount == 9297) ? 
//                "correct." : "wrong!"
//          );
    if (! (queuePacketCount == 23246 && holdCount == 9297)) {
      printf("error: richards results are incorrect\n");
    }

//    t4 = clock();
//    printf("\nScheduler time = %g seconds, total time = %g\n",
//           (double)(t3 - t2) / CLK_TCK,
//           (double)(t4 - t1) / CLK_TCK);
}
Beispiel #2
0
//创建移动表针
osg::Node* cOSG::CreateMoveHandler(void)
{
	//得到当前的时间
	SYSTEMTIME st ;
	::GetLocalTime (&st) ;
	//创建秒针,分针,时针
	osg::Node * second = CreateHandler(osg::Vec3 (-10.0,-0.0 , 0.0), osg::Vec3(35,-0.0 ,0.0)) ;
	osg::Node * minute = CreateHandler(osg::Vec3 (-8.0, -0.0, 0.0), osg::Vec3 (25,	-0.0, 0.0)) ;
	osg::Node * hour = CreateHandler(osg::Vec3 (-6.0, -0.0, 0.0), osg::Vec3 (15,	-0.0, 0.0)) ;
	//利用当前系统时间初始化角度
	float animationLength = 60.0F;
	osg::Vec3 center(0.0, 0.0, 0.0);
	float radius = 0.0 ;
	float angle0 , angle1, angle2 ;
	angle0 = st.wSecond *6.0 ;
	angle1 = st.wMinute *6.0 + angle0 * (1/60.0) ;
	angle2 = st.wHour * 30.0 + angle1 * (1/60) ;
	//周期越来越长,秒针周期为60S
	osg::AnimationPath* secondPath =createAnimationPath(center,radius,animationLength, -120.0+angle0) ;//+ angle2);
	animationLength *= 60.0f ;
	//分针为60^2
	osg::AnimationPath* minutePath = createAnimationPath (center, radius, animationLength, -120.0+angle1); //+angle1);
	animationLength *=60.0f ;
	//时针为60^3
	osg::AnimationPath* hourPath = createAnimationPath (center, radius, animationLength, -120.0+angle2) ;//+angle0);
	osg::Group* model = new osg::Group;
	osg::MatrixTransform* positioned1 = new osg::MatrixTransform;
	positioned1->setDataVariance(osg::Object::STATIC);
	positioned1->addChild(second);
	osg::MatrixTransform* positioned2 = new osg::MatrixTransform;
	positioned2->setDataVariance(osg::Object::STATIC);
	positioned2->addChild (minute);
	osg::MatrixTransform* positioned3 = new osg::MatrixTransform;
	positioned3->setDataVariance(osg::Object::STATIC);
	positioned3->addChild (hour);
	osg::PositionAttitudeTransform* xform1 = new osg::PositionAttitudeTransform;
	xform1->setUpdateCallback(new osg::AnimationPathCallback(secondPath,0.0,1.0));
	xform1->addChild(positioned1);
	osg::PositionAttitudeTransform* xform2 = new osg::PositionAttitudeTransform;
	xform2->setUpdateCallback(new osg::AnimationPathCallback(minutePath,0.0,1.0));
	xform2->addChild(positioned2);
	osg::PositionAttitudeTransform* xform3 = new osg::PositionAttitudeTransform;
	xform3->setUpdateCallback(new osg::AnimationPathCallback(hourPath,0.0,1.0));
	xform3->addChild(positioned3);
	model->addChild(xform1);
	model->addChild(xform2);
	model->addChild(xform3);
	return model;
}
TcpHandler* TcpServer::AllocSocketHandler(SOCKET sock_fd)
{
	TcpHandler* sh = CreateHandler();
	if(sh != NULL)
	{
        sh->SetNeedDel(true);
		sh->SetFd(sock_fd);		
		sh->server(this);
	}
	return sh;
}
CPDF_SecurityHandler* CPDF_ModuleMgr::CreateSecurityHandler(FX_LPCSTR filter)
{
    CPDF_SecurityHandler* (*CreateHandler)(void*) = NULL;
    if (!m_SecurityHandlerMap.Lookup(filter, (void*&)CreateHandler)) {
        return NULL;
    }
    if (CreateHandler == NULL) {
        return NULL;
    }
    void* param = NULL;
    m_SecurityHandlerMap.Lookup(FX_BSTRC("_param_") + filter, param);
    return CreateHandler(param);
}
Boolean DeviceMotionService::RegisterForAccelerometerSensor()
{
    AutoPtr< ArrayOf<ISensor*> > sensors;
    GetSensorManager()->GetSensorList(ISensor::TYPE_ACCELEROMETER, (ArrayOf<ISensor*>**)&sensors);
    if (sensors->GetLength() == 0) {
        return FALSE;
    }
    CreateHandler();
    // TODO: Consider handling multiple sensors.
    Boolean result = FALSE;
    GetSensorManager()->RegisterListener(
            this, (*sensors)[0], ISensorManager::SENSOR_DELAY_UI, mHandler, &result);
    return result;
}
void DeviceMotionService::SendErrorEvent()
{
    AutoPtr<IThread> thread = Thread::GetCurrentThread();
    String name;
    thread->GetName(&name);
    assert(WebViewCore::THREAD_NAME.Equals(name));
    // The spec requires that each listener receives the error event only once.
    if (mHaveSentErrorEvent)
        return;
    mHaveSentErrorEvent = TRUE;
    CreateHandler();
    AutoPtr<IRunnable> runnable = new ErrorEventRunnable(this);
    Boolean result = FALSE;
    mHandler->Post(runnable, &result);
}
void DeviceMotionService::StartSendingUpdates()
{
    CreateHandler();
    mUpdateRunnable->Run();
}