コード例 #1
0
void    PhysicsServerExample::exitPhysics()
{
		for (int i=0;i<MAX_MOTION_NUM_THREADS;i++)
		{
			m_args[i].m_cs->lock();
			m_args[i].m_cs->setSharedParam(0,eRequestTerminateMotion);
			m_args[i].m_cs->unlock();
		}
		int numActiveThreads = MAX_MOTION_NUM_THREADS;

		while (numActiveThreads)
                {
			int arg0,arg1;
                        if (m_threadSupport->isTaskCompleted(&arg0,&arg1,0))
                        {
                                numActiveThreads--;
                                printf("numActiveThreads = %d\n",numActiveThreads);

                        } else
                        {
							b3Clock::usleep(1000);
                        }
                };

		printf("stopping threads\n");

		delete m_threadSupport;   
		m_threadSupport = 0;

		//m_physicsServer.resetDynamicsWorld();
		
}
コード例 #2
0
void	PhysicsServerExample::initPhysics()
{
	///for this testing we use Z-axis up
	int upAxis = 2;
	m_guiHelper->setUpAxis(upAxis);


	


	m_threadSupport = createMotionThreadSupport(MAX_MOTION_NUM_THREADS);
		
		

		for (int i=0;i<m_threadSupport->getNumTasks();i++)
		{
			MotionThreadLocalStorage* storage = (MotionThreadLocalStorage*) m_threadSupport->getThreadLocalMemory(i);
			b3Assert(storage);
			storage->threadId = i;
			//storage->m_sharedMem = data->m_sharedMem;
		}


		

		for (int w=0;w<MAX_MOTION_NUM_THREADS;w++)
		{
			m_args[w].m_cs = m_threadSupport->createCriticalSection();
			m_args[w].m_cs->setSharedParam(0,eMotionIsUnInitialized);
			int numMoving = 0;
 			m_args[w].m_positions.resize(numMoving);
			m_args[w].m_physicsServerPtr = &m_physicsServer;
			int index = 0;
			
			m_threadSupport->runTask(B3_THREAD_SCHEDULE_TASK, (void*) &this->m_args[w], w);
			
			while (m_args[w].m_cs->getSharedParam(0)==eMotionIsUnInitialized)
			{
				b3Clock::usleep(1000);
			}
		}

		m_args[0].m_cs->setSharedParam(1,eGUIHelperIdle);
		m_multiThreadedHelper->setCriticalSection(m_args[0].m_cs);
		m_isConnected = m_physicsServer.connectSharedMemory( m_guiHelper);
}
コード例 #3
0
    virtual void    exitPhysics()
    {
        b3Printf("exitPhysics, stopping threads");
       	bool blockingWait =false;
       	 int arg0,arg1;
       	   
        args.m_cs->lock();
        //terminate all threads
        args.m_cs->setSharedParam(1,MAGIC_RESET_NUMBER);
        args.m_cs->unlock();
       	   
        if (blockingWait)
        {
            for (int i=0;i<m_numThreads;i++)
            {
                m_threadSupport->waitForResponse(&arg0,&arg1);
                printf("finished waiting for response: %d %d\n", arg0,arg1);
            }
        } else
        {
            int numActiveThreads = m_numThreads;
            while (numActiveThreads)
            {
                if (m_threadSupport->isTaskCompleted(&arg0,&arg1,0))
                {
                    numActiveThreads--;
                    printf("numActiveThreads = %d\n",numActiveThreads);

                } else
                {
    //				printf("polling..");
                }
            };
        }
        
        delete m_threadSupport;
        
        b3Printf("Threads stopped");
        for (int i=0;i<m_jobs.size();i++)
        {
         delete m_jobs[i];
        }
        m_jobs.clear();
        	
    }
コード例 #4
0
    virtual void    initPhysics()
    {
        b3Printf("initPhysics");
        
        

        m_threadSupport = createThreadSupport(m_numThreads);



        for (int i=0;i<m_threadSupport->getNumTasks();i++)
        {
            SampleThreadLocalStorage* storage = (SampleThreadLocalStorage*)m_threadSupport->getThreadLocalMemory(i);
            b3Assert(storage);
            storage->threadId = i;
        }


        
        args.m_cs = m_threadSupport->createCriticalSection();
        args.m_cs->setSharedParam(0,100);
        
        for (int i=0;i<100;i++)
        {
            SampleJob1* job = new SampleJob1(i);
            args.submitJob(job);
        }

       
        int i;
        for (i=0;i<m_numThreads;i++)
        {
            m_threadSupport->runTask(B3_THREAD_SCHEDULE_TASK, (void*) &args, i);
        }
         b3Printf("Threads started");

    }