本文整理汇总了C++中iceutil::ThreadPtr类的典型用法代码示例。如果您正苦于以下问题:C++ ThreadPtr类的具体用法?C++ ThreadPtr怎么用?C++ ThreadPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ThreadPtr类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: startHook
static unsigned int
WINAPI startHook(void* arg)
{
// Ensure that the thread doesn't go away until run() has
// completed.
//
IceUtil::ThreadPtr thread;
try
{
IceUtil::Thread* rawThread = static_cast<IceUtil::Thread*>(arg);
//
// Ensure that the thread doesn't go away until run() has
// completed.
//
thread = rawThread;
//
// Initialize the random number generator in each thread on
// Windows (the rand() seed is thread specific).
//
unsigned int seed = static_cast<unsigned int>(IceUtil::Time::now().toMicroSeconds());
srand(seed ^ thread->getThreadControl().id());
//
// See the comment in IceUtil::Thread::start() for details.
//
rawThread->__decRef();
thread->run();
}
catch(...)
{
if(!thread->name().empty())
{
cerr << thread->name() << " terminating" << endl;
}
std::terminate();
}
thread->_done();
return 0;
}
示例2: Shutdown
/***********************************************************
tell the server to shutdown
***********************************************************/
void MaintenanceInterfaceServant::Shutdown(const Ice::Current&)
{
IceUtil::ThreadPtr t = new ShutdownThread(_communicator, _worldname, _wcH);
t->start();
}
示例3: m
//.........这里部分代码省略.........
m.put(ByteIntMap::value_type(alphabet[21], static_cast<Int>(17)));
//
// Non-exact match
//
p = m.findByValue(21);
test(p == m.end());
test(m.valueCount(21) == 0);
p = m.findByValue(21, false);
test(p == m.end());
p = m.findByValue(22, false);
int previous = 21;
int count = 0;
while(p != m.end())
{
test(p->second > previous);
previous = p->second;
++p;
count++;
}
test(count == 4);
cout << "ok " << endl;
cout << "testing concurrent access... " << flush;
m.clear();
populateDB(connection, m);
vector<IceUtil::ThreadControl> controls;
for(int i = 0; i < 5; ++i)
{
IceUtil::ThreadPtr rt = new ReadThread(communicator, envName, dbName);
controls.push_back(rt->start());
IceUtil::ThreadPtr wt = new WriteThread(communicator, envName, dbName);
controls.push_back(wt->start());
}
for(vector<IceUtil::ThreadControl>::iterator q = controls.begin(); q != controls.end(); ++q)
{
q->join();
}
cout << "ok" << endl;
cout << "testing index creation... " << flush;
{
IntIdentityMap iim(connection, "intIdentity");
Ice::Identity odd;
odd.name = "foo";
odd.category = "odd";
Ice::Identity even;
even.name = "bar";
even.category = "even";
TransactionHolder txHolder(connection);
for(int i = 0; i < 1000; i++)
{
if(i % 2 == 0)
{
iim.put(IntIdentityMap::value_type(i, even));
}
else
{
示例4: Connect
//.........这里部分代码省略.........
return -1;
}
try
{
std::string verS = _session->GetVersion();
Ice::PropertiesPtr prop = _communicator->getProperties();
std::string serverV = prop->getPropertyWithDefault("LbanetServerVersion", "v0");
if(verS != serverV)
{
reason = "Server version mismatch - please update your game.";
Disconnect();
return -1;
}
}
catch(const Ice::Exception& ex)
{
LogHandler::getInstance()->LogToFile(std::string("Error getting server version: ") + ex.what());
return 0;
}
try
{
_adapter = _communicator->createObjectAdapter("LbaNetClient");
_adapter->activate();
}
catch(const Ice::Exception& ex)
{
LogHandler::getInstance()->LogToFile(std::string("Error creating adapter: ") + ex.what());
return 0;
}
// clear online list
ThreadSafeWorkpile::JoinEvent evcl;
evcl.ListName = "online";
evcl.Clear = true;
ThreadSafeWorkpile::getInstance()->HappenedJoinEvent(evcl);
// fill it with already connected people
if(_session)
{
Ice::Long ownid = -1;
LbaNet::ConnectedL listco = _session->GetConnected(ownid);
ThreadSafeWorkpile::getInstance()->SetPlayerId(ownid);
LbaNet::ConnectedL::const_iterator it = listco.begin();
LbaNet::ConnectedL::const_iterator end = listco.end();
for(;it != end; ++it)
{
ThreadSafeWorkpile::JoinEvent ev;
ev.ListName = "online";
ev.Joined = true;
ev.Clear = false;
ev.Nickname = it->first;
ev.Status = it->second.Status;
ev.Color = it->second.NameColor;
ThreadSafeWorkpile::getInstance()->HappenedJoinEvent(ev);
ThreadSafeWorkpile::getInstance()->ChatColorChanged(ev.Nickname, ev.Color);
}
//synchronize time with server
//SynchronizedTimeHandler::getInstance()->Initialize(session);
}
IceUtil::ThreadPtr t = new SendingLoopThread(_adapter, _session,
_router->getServerProxy()->ice_getIdentity().category,
user);
_tc = t->start();
_thread_started = true;
//---------------------------------------------------------------
// start the irc thread
Ice::PropertiesPtr prop = _communicator->getProperties();
_ircOn = (prop->getPropertyAsInt("IrcOn") == 1);
std::string IrcServer = prop->getProperty("IrcServer");
std::string IrcChannel = "#" + prop->getProperty("IrcChannel");
if(_ircOn)
{
ircon = true;
IrcThread::IrcCoInfo coi;
coi.Server = IrcServer;
coi.Nickname = user;
coi.Channel = IrcChannel;
_ircth = new IrcThread(coi);
_tcirc = _ircth->start();
}
else
ircon = false;
return 1;
}
示例5: lock
void C2S_Put(
const std::string& bucketID,
const std::string& objID,
const FleCS::ByteSeq& content)
{
_LOG(objID);
string boID = bucketID + "/" + objID;
GlobalLock lock(boID, 'W');
/*Get Random server to write to */
/*
*0->flecs12
*1->flecs22
*2->REDIS_HOST
*/
int s1 = getRand();
int s2=s1;
while(s2!=s1)
s2=getRand();
redisContext *c;
redisReply *reply;
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
c = redisConnectWithTimeout((char*)"REDIS_HOST ", 6379, timeout);
if (c->err) {
_LOG("Connection error"<<c->errstr);
//exit(1);
}
_LOG("Redis connected");
/* Set a key */
reply = (redisReply*)redisCommand(c, "SET %s %s",(string(bucketID + ":" + objID).c_str()),(string(FleCSServer::stg_root_dir)+ "/" + bucketID + "/" + objID).c_str());
_LOG("SET:"<< reply->str);
freeReplyObject(reply);
reply = (redisReply*)redisCommand(c, "GET %s",(string(bucketID + ":" + objID).c_str()));
_LOG("GET:"<< reply->str);
_writefile(reply->str, content);
//_writefile((string(FleCSServer::stg_root_dir) + "/" + boID).c_str(), content);
freeReplyObject(reply);
// propagate update to the other servers.
map<string, FleCS::SM2SPrx*>& s = FleCSServer::peer_servers;
#ifdef _SERIAL_PROCESSING
for (map<string, FleCS::SM2SPrx*>::const_iterator i = s.begin(); i != s.end(); ++ i)
{
string endpoint = dynamic_cast<string>(*(i->first));
(*(i->second))->Put(bucketID, objID, content);
}
#else // Parallel processing (by default)
vector<IceUtil::ThreadPtr> tpv;
vector<IceUtil::ThreadControl> tcv;
for (map<string, FleCS::SM2SPrx*>::const_iterator i = s.begin(); i != s.end(); ++ i)
{
IceUtil::ThreadPtr t = new PutThread(*(i->second), bucketID, objID, content);
tcv.push_back(t->start());
tpv.push_back(t);
}
for (vector<IceUtil::ThreadControl>::iterator j = tcv.begin(); j != tcv.end(); ++ j)
j->join();
#endif
}
示例6: ds
//.........这里部分代码省略.........
Ice::CommunicatorPtr ic = Ice::initialize(initData);
Ice::Context ctx;
ctx["one"] = "ONE";
ctx["two"] = "TWO";
ctx["three"] = "THREE";
Test::MyClassPrxPtr p = ICE_UNCHECKED_CAST(Test::MyClassPrx,
ic->stringToProxy("test:" + getTestEndpoint(ic, 0)));
ic->getImplicitContext()->setContext(ctx);
test(ic->getImplicitContext()->getContext() == ctx);
test(p->opContext() == ctx);
test(ic->getImplicitContext()->containsKey("zero") == false);
string r = ic->getImplicitContext()->put("zero", "ZERO");
test(r == "");
test(ic->getImplicitContext()->containsKey("zero") == true);
test(ic->getImplicitContext()->get("zero") == "ZERO");
ctx = ic->getImplicitContext()->getContext();
test(p->opContext() == ctx);
Ice::Context prxContext;
prxContext["one"] = "UN";
prxContext["four"] = "QUATRE";
Ice::Context combined = prxContext;
combined.insert(ctx.begin(), ctx.end());
test(combined["one"] == "UN");
p = ICE_UNCHECKED_CAST(Test::MyClassPrx, p->ice_context(prxContext));
ic->getImplicitContext()->setContext(Ice::Context());
test(p->opContext() == prxContext);
ic->getImplicitContext()->setContext(ctx);
test(p->opContext() == combined);
test(ic->getImplicitContext()->remove("one") == "ONE");
if(impls[i] == "PerThread")
{
IceUtil::ThreadPtr thread = new PerThreadContextInvokeThread(p->ice_context(Ice::Context()));
thread->start();
thread->getThreadControl().join();
}
ic->getImplicitContext()->setContext(Ice::Context()); // Clear the context to avoid leak report.
ic->destroy();
}
}
#endif
}
{
Ice::Double d = 1278312346.0 / 13.0;
Test::DoubleS ds(5, d);
p->opDoubleMarshaling(d, ds);
}
p->opIdempotent();
p->opNonmutating();
test(p->opByte1(0xFF) == 0xFF);
test(p->opShort1(0x7FFF) == 0x7FFF);
test(p->opInt1(0x7FFFFFFF) == 0x7FFFFFFF);
test(p->opLong1(0x7FFFFFFFFFFFFFFFLL) == 0x7FFFFFFFFFFFFFFFLL);
test(p->opFloat1(1.0) == 1.0);
test(p->opDouble1(1.0) == 1.0);
test(p->opString1("opString1") == "opString1");
Test::MyDerivedClassPrxPtr d = ICE_UNCHECKED_CAST(Test::MyDerivedClassPrx, p);
Test::MyStruct1 s;
s.tesT = "Test::MyStruct1::s";
s.myClass = 0;
s.myStruct1 = "Test::MyStruct1::myStruct1";
s = d->opMyStruct1(s);
test(s.tesT == "Test::MyStruct1::s");
test(s.myClass == 0);
test(s.myStruct1 == "Test::MyStruct1::myStruct1");
Test::MyClass1Ptr c = ICE_MAKE_SHARED(Test::MyClass1);
c->tesT = "Test::MyClass1::testT";
c->myClass = 0;
c->myClass1 = "Test::MyClass1::myClass1";
c = d->opMyClass1(c);
test(c->tesT == "Test::MyClass1::testT");
test(c->myClass == 0);
test(c->myClass1 == "Test::MyClass1::myClass1");
Test::StringS seq;
p->opStringS1(seq);
Test::ByteBoolD dict;
p->opByteBoolD1(dict);
}
示例7: planifica
void ARobot::planifica(Scene *scn,int event){
// _robot->parar();
_scn=scn;
tiposEstrategias es=AMANHATTAN;
if (event == NEWAI){
cout<<"ARobot::"<<_id<<":: NEWAI:"<<_object->getPos()[0]<<":"<<_object->getPos()[1]<<endl;
_lMov.clear();
_guardia = -1;
Search *b = new Search(_id, scn->getMap(), scn->getMarca(_id+2)->getPos()[0]%scn->getGrid(), scn->getMarca(_id+2)->getPos()[1]%scn->getGrid(), scn->getMarca(_id+2)->getPos()[0]/scn->getGrid(), scn->getMarca(_id+2)->getPos()[1]/scn->getGrid(), scn->getAncho()/scn->getGrid()+1, scn->getAlto()/scn->getGrid()+1, scn->getMarca(_id+2)->getRatio()[0], scn->getMarca(_id+2)->getRatio()[1], es, _object->getId()+3, _object->getPos()[0]/scn->getGrid(), _object->getPos()[1]/scn->getGrid());
//Search *b = new Search(_id, scn->getMap(), scn->getMarca(_id+2)->getPos()[0]%scn->getGrid(), scn->getMarca(_id+2)->getPos()[1]%scn->getGrid(), scn->getMarca(_id+2)->getPos()[0]/scn->getGrid(), scn->getMarca(_id+2)->getPos()[1]/scn->getGrid(), scn->getAncho()/scn->getGrid()+1, scn->getAlto()/scn->getGrid()+1, scn->getMarca(_id+2)->getRatio()[0], scn->getMarca(_id+2)->getRatio()[1], es, _id, fin0,fin1);
//State *e = new State(_id,scn->getMarca(_id+2)->getPos()[0]%scn->getGrid(),scn->getMarca(_id+2)->getPos()[1]%scn->getGrid(),scn->getMarca(_id+2)->getPos()[0]/scn->getGrid(),scn->getMarca(_id+2)->getPos()[1]/scn->getGrid(),scn->getMarca(_id+2)->getRatio()[0],scn->getMarca(_id+2)->getRatio()[1],scn->getAncho()/scn->getGrid()+1,scn->getAlto()/scn->getGrid()+1,_object->getPos()[0],_object->getPos()[1],scn->getGrid(),scn->getGrid(),scn->arrayToVectorMap());
IceUtil::ThreadPtr t = new AI(b,this);
t->start();
}else if (event == MOVIMIENTO){
cout<<"ARobot::"<<_id<<":: MOVIMIENTO"<<endl;
if (casillaValida(scn)){
if ((int)_lMov.size() <= scn->getMarca(_id+2)->getRatio()[0]+1){
if(_guardia>0){
fin0 = -1, fin1 = -1;
switch(_guardia){
case 1:
_guardia = 2;
fin0 = scn->getFin()[0]/scn->getGrid();
fin1 = scn->getCenter()[1]/scn->getGrid();
break;
case 2:
_guardia = 3;
fin0 = scn->getCenter()[0]/scn->getGrid();;
fin1 = scn->getCenter()[1]/scn->getGrid();;
break;
case 3:
_guardia = 4;
fin0 = scn->getCenter()[0]/scn->getGrid();;
fin1 = scn->getFin()[1]/scn->getGrid();
break;
case 4:
_guardia = 1;
fin0 = scn->getFin()[0]/scn->getGrid();
fin1 = scn->getFin()[1]/scn->getGrid();
break;
}
_lMov.clear();
Search *b = new Search(_id, scn->getMap(), scn->getMarca(_id+2)->getPos()[0]%scn->getGrid(), scn->getMarca(_id+2)->getPos()[1]%scn->getGrid(), scn->getMarca(_id+2)->getPos()[0]/scn->getGrid(), scn->getMarca(_id+2)->getPos()[1]/scn->getGrid(), scn->getAncho()/scn->getGrid()+1, scn->getAlto()/scn->getGrid()+1, scn->getMarca(_id+2)->getRatio()[0], scn->getMarca(_id+2)->getRatio()[1], es, _id, fin0,fin1);
IceUtil::ThreadPtr t = new AI(b,this);
t->start();
// cout<<"TIDDDDDD:"<<tc.id()<<endl;
} else {
orientarO(scn);
}
}else{
if ((scn->getMarca(_id+2)->getPos()[0]/scn->getGrid() == static_cast<int>(_pos[0]/scn->getGrid())) && (scn->getMarca(_id+2)->getPos()[1]/scn->getGrid()) == static_cast<int>(_pos[1]/scn->getGrid())){
orientar(scn);
}else{
// cout<<"nextm ove"<<endl;
nextMov();
orientar(scn);
}
}
}else{
_lMov.clear();
if(_guardia>0){
Search *b = new Search(_id, scn->getMap(), scn->getMarca(_id+2)->getPos()[0]%scn->getGrid(), scn->getMarca(_id+2)->getPos()[1]%scn->getGrid(), scn->getMarca(_id+2)->getPos()[0]/scn->getGrid(), scn->getMarca(_id+2)->getPos()[1]/scn->getGrid(), scn->getAncho()/scn->getGrid()+1, scn->getAlto()/scn->getGrid()+1, scn->getMarca(_id+2)->getRatio()[0], scn->getMarca(_id+2)->getRatio()[1], es, _id, fin0,fin1);
IceUtil::ThreadPtr t = new AI(b,this);
t->start();
// cout<<"TIDDDDDD:"<<tc.id()<<endl;
}else{
Search *b = new Search(_id, scn->getMap(), scn->getMarca(_id+2)->getPos()[0]%scn->getGrid(), scn->getMarca(_id+2)->getPos()[1]%scn->getGrid(), scn->getMarca(_id+2)->getPos()[0]/scn->getGrid(), scn->getMarca(_id+2)->getPos()[1]/scn->getGrid(), scn->getAncho()/scn->getGrid()+1, scn->getAlto()/scn->getGrid()+1, scn->getMarca(_id+2)->getRatio()[0], scn->getMarca(_id+2)->getRatio()[1], es, _object->getId()+3, _object->getPos()[0]/scn->getGrid(), _object->getPos()[1]/scn->getGrid());
//State *e = new State(_id,scn->getMarca(_id+2)->getPos()[0]%scn->getGrid(),scn->getMarca(_id+2)->getPos()[1]%scn->getGrid(),scn->getMarca(_id+2)->getPos()[0]/scn->getGrid(),scn->getMarca(_id+2)->getPos()[1]/scn->getGrid(),scn->getMarca(_id+2)->getRatio()[0],scn->getMarca(_id+2)->getRatio()[1],scn->getAncho()/scn->getGrid()+1,scn->getAlto()/scn->getGrid()+1,scn->getFin()[0]/scn->getGrid(),scn->getFin()[1]/scn->getGrid(),scn->getGrid(),scn->getGrid(),scn->arrayToVectorMap());
IceUtil::ThreadPtr t = new AI(b,this);
t->start();
}
}
}else if (event == GUARDAI){
cout<<"ARobot::"<<_id<<":: GUARDAI"<<endl;
_lMov.clear();
if (_guardia==-1){
_guardia = 1;
// for (int j=0;j<=scn->getAlto()/scn->getGrid();j++){
// for (int i=0;i<=scn->getAncho()/scn->getGrid();i++){
// std::cout<<scn->getMap(i,j);
// }
// std::cout<<""<<std::endl;
// }
fin0=scn->getFin()[0]/scn->getGrid();
fin1=scn->getFin()[1]/scn->getGrid();
}
// cout<<"ARobot:: Inicio: "<<scn->getMarca(_id+2)->getPos()[0]/scn->getGrid()<<" : "<<scn->getMarca(_id+2)->getPos()[1]/scn->getGrid()<<endl;
// cout<<"ARobot:: ratio: "<<scn->getMarca(_id+2)->getRatio()[0]<<" : "<<scn->getMarca(_id+2)->getRatio()[1]<<endl;
Search *b = new Search(_id, scn->getMap(), scn->getMarca(_id+2)->getPos()[0]%scn->getGrid(), scn->getMarca(_id+2)->getPos()[1]%scn->getGrid(), scn->getMarca(_id+2)->getPos()[0]/scn->getGrid(), scn->getMarca(_id+2)->getPos()[1]/scn->getGrid(), scn->getAncho()/scn->getGrid()+1, scn->getAlto()/scn->getGrid()+1, scn->getMarca(_id+2)->getRatio()[0], scn->getMarca(_id+2)->getRatio()[1], es, _id, fin0,fin1);
//State *e = new State(_id,scn->getMarca(_id+2)->getPos()[0]%scn->getGrid(),scn->getMarca(_id+2)->getPos()[1]%scn->getGrid(),scn->getMarca(_id+2)->getPos()[0]/scn->getGrid(),scn->getMarca(_id+2)->getPos()[1]/scn->getGrid(),scn->getMarca(_id+2)->getRatio()[0],scn->getMarca(_id+2)->getRatio()[1],scn->getAncho()/scn->getGrid()+1,scn->getAlto()/scn->getGrid()+1,scn->getFin()[0]/scn->getGrid(),scn->getFin()[1]/scn->getGrid(),scn->getGrid(),scn->getGrid(),scn->arrayToVectorMap());
IceUtil::ThreadPtr t = new AI(b,this);
t->start();
// cout<<"TIDDDDDD:"<<tc.id()<<endl;
}
double po[2] = {scn->getMarca(_id+2)->getPos()[0],scn->getMarca(_id+2)->getPos()[1]};
setPos(po);
// _markerInfo = markerInfo;
// _pos[0] = _markerInfo->pos[0];
// _pos[1] = _markerInfo->pos[1];
//.........这里部分代码省略.........