本文整理汇总了C++中ACE_Thread_Manager类的典型用法代码示例。如果您正苦于以下问题:C++ ACE_Thread_Manager类的具体用法?C++ ACE_Thread_Manager怎么用?C++ ACE_Thread_Manager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ACE_Thread_Manager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ACE_TMAIN
/*
fence: 1) send the heartbeat message to repo at regular basis. 1/1 minute, get back the messages,
calculate the digest, and send to localhost:9907
2)listens on localhost:9901, for the incoming raw inputs, calculate the digest, and send it to hub:10007
*/
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[]){
ACE_SOCK_Acceptor _9901acceptor;
ACE_INET_Addr _9901addr(9901);
//create the acceptor
if(_9901acceptor.open(_9901addr,1)==-1){
ACE_ERROR_RETURN((LM_ERROR,
"%p\n","open"),1);
}else if(_9901acceptor.get_local_addr(_9901addr)== -1){
ACE_ERROR_RETURN((LM_ERROR,
"%p\n","get_local_addr"),1);
}
ACE_DEBUG((LM_INFO,
"(%P|%t) starting server at port %d\n",
_9901addr.get_port_number()));
// ACE_INET_Addr repo_addr(repo_port,repo_host.c_str());
ACE_SOCK_Connector con;
// ACE_SOCK_Stream cli_stream ;
ACE_Thread_Manager* mgr = ACE_Thread_Manager::instance();
// if(con.connect(cli_stream,repo_addr)==-1){
// ACE_ERROR_RETURN((LM_ERROR,
// "(%P|%t:%l) %p\n","connection failed"),0);
// }else{
// ACE_DEBUG((LM_DEBUG,
// "(%P|%t) connected to %s at port %d\n",repo_addr.get_host_name(),repo_addr.get_port_number()));
// }
/*connector side; do in a seperate thread;
*/
if(mgr->spawn(fetch_step2,
0,
THR_DETACHED) == -1){
ACE_ERROR ((LM_ERROR,
"(%P|%t) %p\n",
"spawn"));
}
/*
run the accept loop ;
*/
do{
ACE_SOCK_Stream stream;
if(_9901acceptor.accept(stream)== -1){
ACE_ERROR_RETURN((LM_ERROR,
"(%P|%t:%l) %p\n","accept failed"),0);
}else{
ACE_DEBUG((LM_DEBUG,
"(%P|%t:%l) connected to %s at port %d\n",_9901addr.get_host_name(),_9901addr.get_port_number()));
}
if(mgr->spawn(accept_step1,
reinterpret_cast<void *> (stream.get_handle()),
THR_DETACHED) == -1){
ACE_ERROR ((LM_ERROR,
"(%P|%t) %p\n",
"spawn"));
}
}while(true);
return 0;
}
示例2: printf
int ChatServer::handle_data(ACE_SOCK_Stream *client)
{
if (DLOG)
{
printf("\n");
Util::log("[ChatServer::handle_data] START\n");
}
// Place the connection into blocking mode since this
// thread isn't doing anything except handling this client.
client->disable(ACE_NONBLOCK);
PacketHandler handler = PacketHandler(*client);
ServerPacketListener spl = ServerPacketListener(handler);
// Keep handling chat messages until client closes connection
// or this thread is asked to cancel itself.
ACE_Thread_Manager *mgr = ACE_Thread_Manager::instance();
ACE_thread_t me = ACE_Thread::self();
while (!mgr->testcancel(me) &&
handler.processPacket(spl) != 0)
continue;
handler.close();
if (DLOG) Util::log("[ChatServer::handle_data] END\n");
return 0;
}
示例3: ACE_TMAIN
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("s:c:"));
int c = -1;
const ACE_TCHAR *client_cmd = 0;
while ((c = get_opts ()) != -1)
switch (c)
{
case 'c':
client_cmd = get_opts.opt_arg ();
ACE_DEBUG ((LM_DEBUG, "Client argument: %s\n", client_cmd));
break;
case 's':
server_cmd = get_opts.opt_arg ();
ACE_DEBUG ((LM_DEBUG, "Server argument: %s\n", server_cmd));
break;
default:
ACE_ERROR_RETURN ((LM_ERROR,
"Usage: collocation_test -s \"server opts\" -c \"client opts\""),
-1);
}
ACE_TCHAR cmd_line[1024];
ACE_OS::strcpy (cmd_line, ACE_TEXT("client "));
if (client_cmd != 0)
ACE_OS::strcat (cmd_line, client_cmd);
ACE_OS::strcat (cmd_line, ACE_TEXT(" -f ") THE_IOR);
ACE_ARGV args (cmd_line);
Barriers thread_barrier (2);
int retv = 1;
ACE_DEBUG ((LM_DEBUG,
"\n \t IDL_Cubit: Collocation test \n\n"));
ACE_Thread_Manager tm;
tm.spawn (reinterpret_cast<ACE_THR_FUNC> (&svr_worker),
&thread_barrier);
thread_barrier.server_init_.wait ();
ACE_OS::sleep (1);
Cubit_Client cubit_client (1);
// Make sure the server shuts itself down afterward.
if (cubit_client.init (args.argc (), args.argv ()) == -1)
return 1;
else
retv = cubit_client.run ();
thread_barrier.client_fini_.wait ();
tm.wait ();
ACE_OS::unlink (THE_IOR);
return retv;
}
示例4: thread_test
int thread_test(int argc, char *argv[])
{
ACE_Thread_Manager* pThMgr = ACE_Thread_Manager::instance();
ACE_thread_t thId = 0;
int ret = pThMgr->spawn(thread_func, "create thread"
, THR_DETACHED|THR_SCOPE_SYSTEM
, &thId);
printf("thread_id=%d\n", thId);
ret = pThMgr->join(thId);
return ret;
}
示例5: ACE_TMAIN
// Listing 4 code/ch13
int ACE_TMAIN (int, ACE_TCHAR *[])
{
ExitHandler eh;
ACE_Thread_Manager tm;
HA_CommandHandler handler (eh);
handler.thr_mgr (&tm);
handler.activate ();
tm.wait();
return 0;
}
示例6: fsConfigUpdater
int
FrameStoreUpdaterSvc::svc()
{
// set up RAPID frame-updaters
rapid::FsConfigUpdater fsConfigUpdater(*m_frameStore);
typedef kn::shared_ptr<rapid::FsPositionUpdater> FsPositionUpdaterPtr;
typedef kn::shared_ptr<rapid::FsJointUpdater> FsJointUpdaterPtr;
std::vector<FsPositionUpdaterPtr> fsPositionUpdaters;
std::vector<FsJointUpdaterPtr> fsJointUpdaters;
kn::DdsEventLoop eventLoop(svcName);
// connect RAPID frame-updaters for local-robot updates
if (m_params->frameStoreConfig.enabled) {
eventLoop.connect<rapid::FrameStoreConfig>(&fsConfigUpdater, rapid::FRAMESTORE_CONFIG_TOPIC +
m_params->frameStoreConfig.topicSuffix,
m_params->frameStoreConfig.parentNode,
m_params->frameStoreConfig.profile,
m_params->frameStoreConfig.library);
}
for (unsigned int i = 0; i < m_params->positionUpdaters.size(); ++i) {
fsPositionUpdaters.push_back(FsPositionUpdaterPtr(new rapid::FsPositionUpdater(*m_frameStore,
m_params->positionUpdaters[i])));
fsPositionUpdaters.back()->connect(eventLoop);
}
for (unsigned int i = 0; i < m_params->jointUpdaters.size(); ++i) {
fsJointUpdaters.push_back(FsJointUpdaterPtr(new rapid::FsJointUpdater(*m_frameStore,
m_params->jointUpdaters[i])));
fsJointUpdaters.back()->connect(eventLoop);
}
// enter processing loop
MIRO_LOG(LL_NOTICE, "Entering (detached) rapid framestore update loop.");
ACE_Thread_Manager * mgr = this->thr_mgr();
while (!mgr->testcancel(mgr->thr_self())) {
// 10Hz processing
eventLoop.processEvents(kn::microseconds(100000));
}
MIRO_LOG(LL_NOTICE, "Exiting (detached) rapid framestore updater loop.");
return 0;
}
示例7: make_log_file
int Thread_Per_Connection_Logging_Server::handle_data(ACE_SOCK_Stream *client)
{
ACE_FILE_IO log_file;
make_log_file(log_file, client);
client->disable(ACE_NONBLOCK);
Logging_Handler logging_handler(log_file, *client);
ACE_Thread_Manager *tm = ACE_Thread_Manager::instance();
ACE_thread_t me = ACE_OS::thr_self();
while (!tm->testcancel(me) && logging_handler.log_record() != -1)
continue;
log_file.close();
return 0;
}
示例8: MIRO_DBG_OSTR
//
// Now the svc() method where everything interesting happens.
//
int
ReactorTask::svc()
{
MIRO_DBG_OSTR(MIRO, LL_DEBUG,
"[Miro::ReactorTask] 0x" << (void*)this <<
" starts in thread " << ACE_Thread::self());
ACE_Time_Value timeout(0, 100000); // wait for 100 msec
ACE_Time_Value delta; // uninitialized time value
// set the given thread scheduling policy
if (ACE_OS::sched_params(schedp_) == -1) {
MIRO_LOG_OSTR(LL_ERROR, "[Miro::ReactorTask] Could not set sched parameters." << std::endl
<< "[Miro::ReactorTask] Maybe suid root is missing." << std::endl
<< "[Miro::ReactorTask] Will work on default scheduling policy." << std::endl);
}
// set the thread to be the owner of the reactor,
//otherwise we will get errors
reactor_.owner(ACE_OS::thr_self());
ACE_Thread_Manager * mgr = this->thr_mgr();
try {
while (!mgr->testcancel(mgr->thr_self())) {
// set delta to timeout
// handle_events decrements the timeout
delta = timeout;
// trigger message handling
reactor_.handle_events(delta);
}
}
catch (const Miro::Exception& e) {
MIRO_LOG_OSTR(LL_ERROR, "ReactorTask.handleMessage() - Uncaught Miro exception: " << e << std::endl);
conditionalShutdown();
}
catch (...) {
MIRO_LOG(LL_ERROR, "[Miro::HwReactor] task terminated due to unknown exception.");
conditionalShutdown();
}
return 0;
}
示例9: ACE_TMAIN
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
if (parse_args (argc, argv) == -1)
return -1;
if (remote)
{
ACE_Remote_Mutex::set_server_address (ACE_INET_Addr (server_port, server_host));
global_rlock = (ACE_Token_Proxy *) new
ACE_Remote_RLock ("THE_TOKEN", ignore_deadlock, debug);
global_wlock = (ACE_Token_Proxy *) new
ACE_Remote_WLock ("THE_TOKEN", ignore_deadlock, debug);
}
else
{
global_rlock = (ACE_Token_Proxy *) new
ACE_Local_RLock ("THE_TOKEN", ignore_deadlock, debug);
global_wlock = (ACE_Token_Proxy *) new
ACE_Local_WLock ("THE_TOKEN", ignore_deadlock, debug);
}
ACE_Thread_Manager mgr;
if (mgr.spawn_n (threads, ACE_THR_FUNC (run_thread),
(void *) 0,
THR_BOUND | SUSPEND) == -1)
ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "spawn failed"), -1);
#if ! defined (ACE_HAS_PTHREADS)
if (mgr.resume_all () == -1)
ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "resume failed"), -1);
#endif
mgr.wait ();
return 0;
}
示例10: make_log_file
int
Thread_Per_Connection_Logging_Server::handle_data (ACE_SOCK_Stream *client)
{
ACE_FILE_IO log_file;
// Client's hostname is logfile name.
make_log_file (log_file, client);
// Place the connection into blocking mode since this
// thread isn't doing anything except handling this client.
client->disable (ACE_NONBLOCK);
Logging_Handler logging_handler (log_file, *client);
// Keep handling log records until client closes connection
// or this thread is asked to cancel itself.
ACE_Thread_Manager *mgr = ACE_Thread_Manager::instance ();
ACE_thread_t me = ACE_Thread::self ();
while (!mgr->testcancel (me) &&
logging_handler.log_record () != -1)
continue;
log_file.close ();
return 0;
}
示例11: reactor
int
SystemInfoSvc::fini()
{
// deregister the update timer
if (m_timerId != -1)
reactor()->cancel_timer(m_timerId);
m_timerId = -1;
ACE_Thread_Manager * mgr = this->thr_mgr();
if (mgr != NULL) {
mgr->cancel_task(this);
this->wait();
}
m_errorCounter = 0;
delete m_systemInfo;
delete m_sampleSupplier;
delete m_configSupplier;
MIRO_LOG(LL_NOTICE, "kn::SystemInfoSvc::fini() done");
return 0;
}
示例12:
void TAO::Fault_Detector_i::start(ACE_Thread_Manager & threadManager)
{
threadManager.spawn(thr_func, this);
}
示例13: ACE_MAIN
//---------------------------------------------------------------------------
int ACE_MAIN(int argc, ACE_TCHAR *argv[])
{
// 환경설정 (제일 먼저 초기화 해야함)
procArguments(argc, argv);
// 로그
if(initLog() < 0)
{
printf("로그 초기화를 실패했으므로 프로그램을 종료합니다.\n");
return -1;
}
//-----------------------------------------------------------------------
// 데몬 만들기
//-----------------------------------------------------------------------
// acceptor 가 초기화 된 후 데몬을 만들게 되면, 부모프로세스가 제거되면서
// listen 소켓도 같이 제거된다. 그러므로 acceptor 를 초기화 하기 전에
// 데몬을 먼저 만들어야 한다.
if(Config::instance()->process.daemon == true)
{
if(makeDaemon() < 0)
{
printf("데몬으로 만들기를 실패했으므로 프로그램을 종료합니다.\n");
return -1;
}
}
PAS_NOTICE1("%s", compile_date);
// 시그널 핸들러
PasSignalHandler* pSignalHandler = new PasSignalHandler;
initSignal(pSignalHandler);
//------------------
// 각 모듈의 초기화
//------------------
HTTP::Request::HeaderBuffBytes = HTTP::Response::HeaderBuffBytes = Config::instance()->process.HttpHeaderBufferBytes;
increseFdLimit();
// PAS 공식 로그
char hostName[32];
gethostname(hostName, sizeof(hostName)-1);
PasDataLog::setPasAddr(hostName);
// 메모리 매니저 초기화
//initMessageBlockManager();
if (readMBconfig() < 0)
{
printf("메모리 풀 컨피그 설정값을 확인하세요.\n");
PAS_ERROR("메모리 풀 컨피그 설정값을 확인하세요.\n");
return -1;
}
const int numWorkerThread = Config::instance()->thread.numWorker;
// 리액터
ACE_Reactor* pReactor = ReactorPool::instance()->createMaster();
ReactorPool::instance()->createWorkers(numWorkerThread);
ACE_Reactor* pGlobalReactor = ACE_Reactor::instance();
PAS_NOTICE3("REACTOR: Master=%X, Global=%X, Master=%x",
pReactor, pGlobalReactor, ReactorPool::instance()->masterReactor());
// Listen 포트 설정
PAS_NOTICE("Listen Socket Activate");
PasAcceptor* pAcceptor = new PasAcceptor(pReactor);
const int listenPort = Config::instance()->network.listenPort;
// mIDC 내의 서버를 감시하는 쪽에 mwatch 전달하기 위해 메시지 작성한다.
Util2::setMwatchMsg(listenPort);
// acceptor 기동
if(pAcceptor->open(listenPort) < 0)
{
PAS_ERROR1("Listen 소켓 생성 실패, Port[%d]\n", listenPort);
PAS_ERROR("프로그램 종료\n");
printf("Listen 소켓 생성 실패, Port[%d]\n", listenPort);
printf("프로그램 종료\n");
return -1;
}
// 쓰레드 매니저
ACE_Thread_Manager* pTManager = ACE_Thread_Manager::instance();
// monitor 보고리를 위한 thread 를 생성한다.
MonitorReporter *monitor = MonitorReporter::instance(pTManager);
monitor->activate(THR_NEW_LWP | THR_JOINABLE);
WatchReporter *watch = WatchReporter::instance(pTManager);
watch->activate(THR_NEW_LWP | THR_JOINABLE);
// UserInfo 관리를 위한 thread 를 생성한다.
//.........这里部分代码省略.........
示例14: ACE_TMAIN
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[]){
u_long priority_mask =
ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
ACE_CLR_BITS (priority_mask,
LM_DEBUG|LM_TRACE);
ACE_LOG_MSG->priority_mask (priority_mask,
ACE_Log_Msg::PROCESS);
ACE::set_handle_limit();
ACE_Thread_Manager* mgr = ACE_Thread_Manager::instance();
ACE_SOCK_Acceptor _987acceptor;
ACE_INET_Addr _987addr(0x987);//2439
if(_987acceptor.open(_987addr, 1) == -1){
ACE_ERROR_RETURN((LM_ERROR,
"%p\n",
"open"),
1);
}else if(_987acceptor.get_local_addr(_987addr) == -1){
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"get_local_addr"),
1);
}
ACE_DEBUG((LM_INFO,
"(%P|%t) starting 987 server at port %d\n",
_987addr.get_port_number()));
ACE_SOCK_Stream _str;
ACE_Handle_Set _set;
_set.set_bit(_987acceptor.get_handle());
do{
ACE_Time_Value timeout(ACE_DEFAULT_TIMEOUT);
ACE_Handle_Set tmp = _set;
int result = ACE_OS::select(ACE_Utils::truncate_cast<int> ((intptr_t) _987acceptor.get_handle()) +1,
(fd_set *) tmp,
0,
0,
NULL);
if(result == -1)
ACE_ERROR((LM_ERROR,
"(%P|%t) %p\n",
"select"));
else if(result==0)
ACE_DEBUG((LM_INFO,
"(%P|%t) select timed out\n"));
else{
if(tmp.is_set(_987acceptor.get_handle())){
if(_987acceptor.accept(_str) == -1){
ACE_ERROR((LM_ERROR,
"%p\n",
"987 accept"));
continue;
}else{
ACE_DEBUG((LM_INFO,
"(%P|%t: %l) spawning 987 server\n"));
if(mgr->spawn(process,
reinterpret_cast<void*> (_str.get_handle()),
THR_DETACHED) == -1){
ACE_ERROR((LM_ERROR,
"(%P|%t) %p\n",
"spawn"));
}
}
}
}
}while(true);
return 0;
}
示例15: ACE_TMAIN
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
if (parse_args (argc, argv) == -1)
return -1;
ACE_Token_Proxy *A; // Mutex *A*.
ACE_Token_Proxy *B; // Mutex *B*.
ACE_Token_Proxy *R; // *R*eader Lock.
ACE_Token_Proxy *W; // *W*riter Lock.
// Depending on the command line arguments, we will create local or
// remote tokens. The names of the tokens are not important as long
// as they are unique.
if (remote)
{
ACE_Remote_Mutex::set_server_address (ACE_INET_Addr (server_port, server_host));
A = new ACE_Remote_Mutex ("R Mutex A", 0, debug);
B = new ACE_Remote_Mutex ("R Mutex B", 0, debug);
R = new ACE_Remote_RLock ("R Reader Lock", 0, debug);
W = new ACE_Remote_WLock ("R Writer Lock", 0, debug);
}
else
{
A = new ACE_Local_Mutex ("L Mutex A", 0, debug);
B = new ACE_Local_Mutex ("L Mutex B", 0, debug);
R = new ACE_Local_RLock ("L Reader Lock", 0, debug);
W = new ACE_Local_WLock ("L Writer Lock", 0, debug);
}
// These collections will be treated as Tokens by the threads.
ACE_Token_Collection collectionAR (debug, "A and Reader");
ACE_Token_Collection collectionAW (debug, "A and Writer");
ACE_Token_Collection collectionBR (debug, "B and Reader");
// AR and BR can run concurrently. Neither AR or BR can run when AW
// is running.
collectionAR.insert (*A);
collectionAR.insert (*R);
collectionAW.insert (*A);
collectionAW.insert (*W);
collectionBR.insert (*B);
collectionBR.insert (*R);
// Spawn off three threads.
ACE_Thread_Manager *mgr = ACE_Thread_Manager::instance ();
if (mgr->spawn (ACE_THR_FUNC (run_thread),
(void *) &collectionAR, THR_BOUND | THR_SUSPENDED) == -1)
ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "spawn 1 failed"), -1);
if (mgr->spawn (ACE_THR_FUNC (run_thread),
(void *) &collectionAW, THR_BOUND | THR_SUSPENDED) == -1)
ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "spawn 2 failed"), -1);
if (mgr->spawn (ACE_THR_FUNC (run_thread),
(void *) &collectionBR, THR_BOUND | THR_SUSPENDED) == -1)
ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "spawn 3 failed"), -1);
#if ! defined (ACE_HAS_PTHREADS)
if (mgr->resume_all () == -1)
ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "resume failed"), -1);
#endif
// Wait for all threads to exit.
mgr->wait ();
return 0;
}