当前位置: 首页>>代码示例>>C++>>正文


C++ JMutex类代码示例

本文整理汇总了C++中JMutex的典型用法代码示例。如果您正苦于以下问题:C++ JMutex类的具体用法?C++ JMutex怎么用?C++ JMutex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了JMutex类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: v3f

void ClientLauncher::speed_tests()
{
    // volatile to avoid some potential compiler optimisations
    volatile static s16 temp16;
    volatile static f32 tempf;
    static v3f tempv3f1;
    static v3f tempv3f2;
    static std::string tempstring;
    static std::string tempstring2;

    tempv3f1 = v3f();
    tempv3f2 = v3f();
    tempstring = std::string();
    tempstring2 = std::string();

    {
        infostream << "The following test should take around 20ms." << std::endl;
        TimeTaker timer("Testing std::string speed");
        const u32 jj = 10000;
        for (u32 j = 0; j < jj; j++) {
            tempstring = "";
            tempstring2 = "";
            const u32 ii = 10;
            for (u32 i = 0; i < ii; i++) {
                tempstring2 += "asd";
            }
            for (u32 i = 0; i < ii+1; i++) {
                tempstring += "asd";
                if (tempstring == tempstring2)
                    break;
            }
        }
    }

    infostream << "All of the following tests should take around 100ms each."
               << std::endl;

    {
        TimeTaker timer("Testing floating-point conversion speed");
        tempf = 0.001;
        for (u32 i = 0; i < 4000000; i++) {
            temp16 += tempf;
            tempf += 0.001;
        }
    }

    {
        TimeTaker timer("Testing floating-point vector speed");

        tempv3f1 = v3f(1, 2, 3);
        tempv3f2 = v3f(4, 5, 6);
        for (u32 i = 0; i < 10000000; i++) {
            tempf += tempv3f1.dotProduct(tempv3f2);
            tempv3f2 += v3f(7, 8, 9);
        }
    }

    {
        TimeTaker timer("Testing std::map speed");

        std::map<v2s16, f32> map1;
        tempf = -324;
        const s16 ii = 300;
        for (s16 y = 0; y < ii; y++) {
            for (s16 x = 0; x < ii; x++) {
                map1[v2s16(x, y)] =  tempf;
                tempf += 1;
            }
        }
        for (s16 y = ii - 1; y >= 0; y--) {
            for (s16 x = 0; x < ii; x++) {
                tempf = map1[v2s16(x, y)];
            }
        }
    }

    {
        infostream << "Around 5000/ms should do well here." << std::endl;
        TimeTaker timer("Testing mutex speed");

        JMutex m;
        u32 n = 0;
        u32 i = 0;
        do {
            n += 10000;
            for (; i < n; i++) {
                m.Lock();
                m.Unlock();
            }
        }
        // Do at least 10ms
        while(timer.getTimerTime() < 10);

        u32 dtime = timer.stop();
        u32 per_ms = n / dtime;
        infostream << "Done. " << dtime << "ms, " << per_ms << "/ms" << std::endl;
    }
}
开发者ID:4aiman,项目名称:MultiCraft,代码行数:98,代码来源:clientlauncher.cpp

示例2: SpeedTests

void SpeedTests()
{
	{
		dstream<<"The following test should take around 20ms."<<std::endl;
		TimeTaker timer("Testing std::string speed");
		const u32 jj = 10000;
		for(u32 j=0; j<jj; j++)
		{
			tempstring = "";
			tempstring2 = "";
			const u32 ii = 10;
			for(u32 i=0; i<ii; i++){
				tempstring2 += "asd";
			}
			for(u32 i=0; i<ii+1; i++){
				tempstring += "asd";
				if(tempstring == tempstring2)
					break;
			}
		}
	}
	
	dstream<<"All of the following tests should take around 100ms each."
			<<std::endl;

	{
		TimeTaker timer("Testing floating-point conversion speed");
		tempf = 0.001;
		for(u32 i=0; i<4000000; i++){
			temp16 += tempf;
			tempf += 0.001;
		}
	}
	
	{
		TimeTaker timer("Testing floating-point vector speed");

		tempv3f1 = v3f(1,2,3);
		tempv3f2 = v3f(4,5,6);
		for(u32 i=0; i<10000000; i++){
			tempf += tempv3f1.dotProduct(tempv3f2);
			tempv3f2 += v3f(7,8,9);
		}
	}

	{
		TimeTaker timer("Testing core::map speed");
		
		core::map<v2s16, f32> map1;
		tempf = -324;
		const s16 ii=300;
		for(s16 y=0; y<ii; y++){
			for(s16 x=0; x<ii; x++){
				map1.insert(v2s16(x,y), tempf);
				tempf += 1;
			}
		}
		for(s16 y=ii-1; y>=0; y--){
			for(s16 x=0; x<ii; x++){
				tempf = map1[v2s16(x,y)];
			}
		}
	}

	{
		dstream<<"Around 5000/ms should do well here."<<std::endl;
		TimeTaker timer("Testing mutex speed");
		
		JMutex m;
		m.Init();
		u32 n = 0;
		u32 i = 0;
		do{
			n += 10000;
			for(; i<n; i++){
				m.Lock();
				m.Unlock();
			}
		}
		// Do at least 10ms
		while(timer.getTime() < 10);

		u32 dtime = timer.stop();
		u32 per_ms = n / dtime;
		dstream<<"Done. "<<dtime<<"ms, "
				<<per_ms<<"/ms"<<std::endl;
	}
}
开发者ID:Oblomov,项目名称:minetest,代码行数:88,代码来源:main.cpp

示例3: SpeedTests

void SpeedTests(IrrlichtDevice *device)
{
	/*
		Test stuff
	*/

	//test();
	//return 0;
	/*TestThread thread;
	thread.Start();
	std::cout<<"thread started"<<std::endl;
	while(thread.IsRunning()) sleep(1);
	std::cout<<"thread ended"<<std::endl;
	return 0;*/

	{
		std::cout<<"Testing floating-point conversion speed"<<std::endl;
		u32 time1 = device->getTimer()->getRealTime();
		tempf = 0.001;
		for(u32 i=0; i<10000000; i++){
			temp16 += tempf;
			tempf += 0.001;
		}
		u32 time2 = device->getTimer()->getRealTime();
		u32 fp_conversion_time = time2 - time1;
		std::cout<<"Done. "<<fp_conversion_time<<"ms"<<std::endl;
		//assert(fp_conversion_time < 1000);
	}
	
	{
		std::cout<<"Testing floating-point vector speed"<<std::endl;
		u32 time1 = device->getTimer()->getRealTime();

		tempv3f1 = v3f(1,2,3);
		tempv3f2 = v3f(4,5,6);
		for(u32 i=0; i<40000000; i++){
			tempf += tempv3f1.dotProduct(tempv3f2);
			tempv3f2 += v3f(7,8,9);
		}

		u32 time2 = device->getTimer()->getRealTime();
		u32 dtime = time2 - time1;
		std::cout<<"Done. "<<dtime<<"ms"<<std::endl;
	}

	{
		std::cout<<"Testing core::map speed"<<std::endl;
		u32 time1 = device->getTimer()->getRealTime();
		
		core::map<v2s16, f32> map1;
		tempf = -324;
		for(s16 y=0; y<500; y++){
			for(s16 x=0; x<500; x++){
				map1.insert(v2s16(x,y), tempf);
				tempf += 1;
			}
		}
		for(s16 y=500-1; y>=0; y--){
			for(s16 x=0; x<500; x++){
				tempf = map1[v2s16(x,y)];
			}
		}

		u32 time2 = device->getTimer()->getRealTime();
		u32 dtime = time2 - time1;
		std::cout<<"Done. "<<dtime<<"ms"<<std::endl;
	}

	{
		std::cout<<"Testing mutex speed"<<std::endl;
		u32 time1 = device->getTimer()->getRealTime();
		u32 time2 = time1;
		
		JMutex m;
		m.Init();
		u32 n = 0;
		u32 i = 0;
		do{
			n += 10000;
			for(; i<n; i++){
				m.Lock();
				m.Unlock();
			}
			time2 = device->getTimer()->getRealTime();
		}
		// Do at least 10ms
		while(time2 < time1 + 10);

		u32 dtime = time2 - time1;
		u32 per_ms = n / dtime;
		std::cout<<"Done. "<<dtime<<"ms, "
				<<per_ms<<"/ms"<<std::endl;
	}

	//assert(0);
}
开发者ID:EUGD,项目名称:minetest_nmpr,代码行数:96,代码来源:main.cpp

示例4: log_deregister_thread

void log_deregister_thread()
{
	threadid_t id = get_current_thread_id();
	log_threadnamemutex.Lock();
	log_threadnames.erase(id);
	log_threadnamemutex.Unlock();
}
开发者ID:1CoreyDev1,项目名称:minetest,代码行数:7,代码来源:log.cpp

示例5: log_register_thread

void log_register_thread(const std::string &name)
{
	threadid_t id = get_current_thread_id();
	log_threadnamemutex.Lock();
	log_threadnames[id] = name;
	log_threadnamemutex.Unlock();
}
开发者ID:1CoreyDev1,项目名称:minetest,代码行数:7,代码来源:log.cpp

示例6: updateViewingRange

void updateViewingRange(f32 frametime)
{
#if 1
	static f32 counter = 0;
	if(counter > 0){
		counter -= frametime;
		return;
	}
	counter = 5.0; //seconds

	g_viewing_range_nodes_mutex.Lock();
	bool changed = false;
	if(frametime > 1.0/FPS_MIN
			|| g_viewing_range_nodes > VIEWING_RANGE_NODES_MAX){
		if(g_viewing_range_nodes > VIEWING_RANGE_NODES_MIN){
			g_viewing_range_nodes -= MAP_BLOCKSIZE/2;
			changed = true;
		}
	}
	else if(frametime < 1.0/FPS_MAX
			|| g_viewing_range_nodes < VIEWING_RANGE_NODES_MIN){
		if(g_viewing_range_nodes < VIEWING_RANGE_NODES_MAX){
			g_viewing_range_nodes += MAP_BLOCKSIZE/2;
			changed = true;
		}
	}
	if(changed){
		std::cout<<"g_viewing_range_nodes = "
				<<g_viewing_range_nodes<<std::endl;
	}
	g_viewing_range_nodes_mutex.Unlock();
#endif
}
开发者ID:EUGD,项目名称:minetest_nmpr,代码行数:33,代码来源:main.cpp

示例7: log_set_lev_silence

void log_set_lev_silence(enum LogMessageLevel lev, bool silence)
{
	log_threadnamemutex.Lock();

	for (std::list<ILogOutput *>::iterator
			it = log_outputs[lev].begin();
			it != log_outputs[lev].end();
			++it) {
		ILogOutput *out = *it;
		out->silence = silence;
	}

	log_threadnamemutex.Unlock();
}
开发者ID:AnnXGame,项目名称:Minetest,代码行数:14,代码来源:log.cpp

示例8: log_printline

void log_printline(enum LogMessageLevel lev, const std::string &text)
{
	log_threadnamemutex.Lock();
	std::string threadname = "(unknown thread)";
	std::map<threadid_t, std::string>::const_iterator i;
	i = log_threadnames.find(get_current_thread_id());
	if(i != log_threadnames.end())
		threadname = i->second;
	std::string levelname = get_lev_string(lev);
	std::ostringstream os(std::ios_base::binary);
	os<<getTimestamp()<<": "<<levelname<<"["<<threadname<<"]: "<<text;
	for(std::list<ILogOutput*>::iterator i = log_outputs[lev].begin();
			i != log_outputs[lev].end(); i++){
		ILogOutput *out = *i;
		out->printLog(os.str());
		out->printLog(os.str(), lev);
		out->printLog(lev, text);
	}
	log_threadnamemutex.Unlock();
}
开发者ID:1CoreyDev1,项目名称:minetest,代码行数:20,代码来源:log.cpp

示例9: debug_stacks_init

void debug_stacks_init()
{
	g_debug_stacks_mutex.Init();
}
开发者ID:Neear,项目名称:minetest,代码行数:4,代码来源:debug.cpp

示例10: main

int main()
{
	sockets_init();
	atexit(sockets_cleanup);

	/*
		Run unit tests
	*/
	if(ENABLE_TESTS)
		run_tests();
	
	//return 0; //DEBUG
		
	/*
		Initialization
	*/

	srand(time(0));

	g_viewing_range_nodes_mutex.Init();
	assert(g_viewing_range_nodes_mutex.IsInitialized());

	MyEventReceiver receiver;

	// create device and exit if creation failed

	/*
		Host selection
	*/
	char connect_name[100];
	std::cout<<std::endl<<std::endl;
	std::cout<<"Address to connect to [empty = host a game]: ";
	std::cin.getline(connect_name, 100);
	
	bool hosting = false;
	if(connect_name[0] == 0){
		snprintf(connect_name, 100, "127.0.0.1");
		hosting = true;
	}
	std::cout<<"-> "<<connect_name<<std::endl;
	
	std::cout<<"Port [empty=30000]: ";
	char templine[100];
	std::cin.getline(templine, 100);
	unsigned short port;
	if(templine[0] == 0)
		port = 30000;
	else
		port = atoi(templine);

	/*
		Resolution selection
	*/

	u16 screenW = 800;
	u16 screenH = 600;

	/*
	u16 resolutions[][2] = {
		{640,480},
		{800,600},
		{1024,768},
		{1280,1024}
	};

	u16 res_count = sizeof(resolutions)/sizeof(resolutions[0]);
	
	std::cout<<"Select window resolution "
			<<"(type a number and press enter):"<<std::endl;
	for(u16 i=0; i<res_count; i++)
	{
		std::cout<<(i+1)<<": "<<resolutions[i][0]<<"x"
				<<resolutions[i][1]<<std::endl;
	}
	u16 r0;
	std::cin>>r0;
	if(r0 > res_count || r0 == 0)
		r0 = 0;
	u16 screenW = resolutions[r0-1][0];
	u16 screenH = resolutions[r0-1][1];
	*/

	//

	video::E_DRIVER_TYPE driverType;

#ifdef _WIN32
	//driverType = video::EDT_DIRECT3D9; // Doesn't seem to work
	driverType = video::EDT_OPENGL;
#else
	driverType = video::EDT_OPENGL;
#endif

	IrrlichtDevice *device;
	device = createDevice(driverType,
			core::dimension2d<u32>(screenW, screenH),
			16, false, false, false, &receiver);

	if (device == 0)
		return 1; // could not create selected driver.
//.........这里部分代码省略.........
开发者ID:EUGD,项目名称:minetest_nmpr,代码行数:101,代码来源:main.cpp


注:本文中的JMutex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。