(file) Return to MessageQueueService.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/MessageQueueService.cpp between version 1.117 and 1.121

version 1.117, 2005/10/14 17:40:18 version 1.121, 2006/07/14 20:12:46
Line 1 
Line 1 
 //%2005////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
Line 8 
Line 8 
 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 // EMC Corporation; VERITAS Software Corporation; The Open Group. // EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; Symantec Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 44 
Line 46 
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 cimom *MessageQueueService::_meta_dispatcher = 0; cimom *MessageQueueService::_meta_dispatcher = 0;
 AtomicInt MessageQueueService::_service_count = 0;  AtomicInt MessageQueueService::_service_count(0);
 AtomicInt MessageQueueService::_xid(1);  IDFactory MessageQueueService::_xidFactory(1);
 Mutex MessageQueueService::_meta_dispatcher_mutex; Mutex MessageQueueService::_meta_dispatcher_mutex;
  
 static struct timeval deallocateWait = {300, 0}; static struct timeval deallocateWait = {300, 0};
  
 ThreadPool *MessageQueueService::_thread_pool = 0; ThreadPool *MessageQueueService::_thread_pool = 0;
  
 DQueue<MessageQueueService> MessageQueueService::_polling_list(true);  MessageQueueService::PollingList* MessageQueueService::_polling_list;
   Mutex MessageQueueService::_polling_list_mutex;
  
 Thread* MessageQueueService::_polling_thread = 0; Thread* MessageQueueService::_polling_thread = 0;
  
Line 109 
Line 112 
 PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL MessageQueueService::polling_routine(void *parm) PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL MessageQueueService::polling_routine(void *parm)
 { {
    Thread *myself = reinterpret_cast<Thread *>(parm);    Thread *myself = reinterpret_cast<Thread *>(parm);
    DQueue<MessageQueueService> *list = reinterpret_cast<DQueue<MessageQueueService> *>(myself->get_parm());     List<MessageQueueService, RecursiveMutex> *list =
    while (_stop_polling.value()  == 0)         reinterpret_cast<List<MessageQueueService, RecursiveMutex>*>(myself->get_parm());
   
      while (_stop_polling.get()  == 0)
    {    {
       _polling_sem.wait();       _polling_sem.wait();
  
       if (_stop_polling.value() != 0)        if (_stop_polling.get() != 0)
       {       {
          break;          break;
       }       }
Line 129 
Line 134 
       // (e.g., MessageQueueServer::~MessageQueueService).       // (e.g., MessageQueueServer::~MessageQueueService).
  
       list->lock();       list->lock();
       MessageQueueService *service = list->next(0);        MessageQueueService *service = list->front();
       ThreadStatus rtn = PEGASUS_THREAD_OK;       ThreadStatus rtn = PEGASUS_THREAD_OK;
       while (service != NULL)       while (service != NULL)
       {       {
           if ((service->_incoming.count() > 0) &&           if ((service->_incoming.count() > 0) &&
               (service->_die.value() == 0) &&                (service->_die.get() == 0) &&
               (service->_threads < max_threads_per_svc_queue))                (service->_threads.get() < max_threads_per_svc_queue))
           {           {
              // The _threads count is used to track the              // The _threads count is used to track the
              // number of active threads that have been allocated              // number of active threads that have been allocated
Line 171 
Line 176 
                     "Skipping the service for right now. ",                     "Skipping the service for right now. ",
                     service->getQueueName(),                     service->getQueueName(),
                     service->_incoming.count(),                     service->_incoming.count(),
                     service->_threads.value());                      service->_threads.get());
  
                  pegasus_yield();                  pegasus_yield();
                  service = NULL;                  service = NULL;
Line 179 
Line 184 
           }           }
           if (service != NULL)           if (service != NULL)
           {           {
              service = list->next(service);               service = list->next_of(service);
           }           }
       }       }
       list->unlock();       list->unlock();
  
       if (_check_idle_flag.value() != 0)        if (_check_idle_flag.get() != 0)
       {       {
          _check_idle_flag = 0;          _check_idle_flag = 0;
          // try to do idle thread clean up processing when system is not busy          // try to do idle thread clean up processing when system is not busy
Line 223 
Line 228 
      _mask(mask),      _mask(mask),
      _die(0),      _die(0),
      _threads(0),      _threads(0),
      _incoming(true, 0),       _incoming(0),
      _incoming_queue_shutdown(0)      _incoming_queue_shutdown(0)
 { {
  
Line 251 
Line 256 
    if (_meta_dispatcher == 0)    if (_meta_dispatcher == 0)
    {    {
       _stop_polling = 0;       _stop_polling = 0;
       PEGASUS_ASSERT(_service_count.value() == 0);        PEGASUS_ASSERT(_service_count.get() == 0);
       _meta_dispatcher = new cimom();       _meta_dispatcher = new cimom();
       if (_meta_dispatcher == NULL)       if (_meta_dispatcher == NULL)
       {       {
Line 275 
Line 280 
       throw BindFailedException(parms);       throw BindFailedException(parms);
    }    }
  
    _polling_list.insert_last(this);     _get_polling_list()->insert_back(this);
  
 } }
  
Line 290 
Line 295 
    // prior to processing, avoids synchronization issues    // prior to processing, avoids synchronization issues
    // with the _polling_routine.    // with the _polling_routine.
  
    _polling_list.remove(this);     // ATTN: added to prevent assertion in List in which the list does not
      // contain this element.
   
      if (_get_polling_list()->contains(this))
          _get_polling_list()->remove(this);
  
    // ATTN: The code for closing the _incoming queue    // ATTN: The code for closing the _incoming queue
    // is not working correctly. In OpenPegasus 2.5,    // is not working correctly. In OpenPegasus 2.5,
    // execution of the following code is very timing    // execution of the following code is very timing
    // dependent. This needs to be fix.    // dependent. This needs to be fix.
    // See Bug 4079 for details.    // See Bug 4079 for details.
    if (_incoming_queue_shutdown.value() == 0)     if (_incoming_queue_shutdown.get() == 0)
    {    {
        _shutdown_incoming_queue();        _shutdown_incoming_queue();
    }    }
Line 305 
Line 314 
    // Wait until all threads processing the messages    // Wait until all threads processing the messages
    // for this service have completed.    // for this service have completed.
  
    while (_threads.value() > 0)     while (_threads.get() > 0)
    {    {
       pegasus_yield();       pegasus_yield();
    }    }
Line 313 
Line 322 
    {    {
      AutoMutex autoMut(_meta_dispatcher_mutex);      AutoMutex autoMut(_meta_dispatcher_mutex);
      _service_count--;      _service_count--;
      if (_service_count.value() == 0)       if (_service_count.get() == 0)
      {      {
  
       _stop_polling++;       _stop_polling++;
Line 335 
Line 344 
   while (_incoming.count())   while (_incoming.count())
   {   {
     try {     try {
       delete _incoming.remove_first();        delete _incoming.dequeue();
     } catch (const ListClosed &e)     } catch (const ListClosed &e)
     {     {
       // If the list is closed, there is nothing we can do.       // If the list is closed, there is nothing we can do.
Line 346 
Line 355 
  
 void MessageQueueService::_shutdown_incoming_queue() void MessageQueueService::_shutdown_incoming_queue()
 { {
    if (_incoming_queue_shutdown.value() > 0)     if (_incoming_queue_shutdown.get() > 0)
       return;       return;
  
    AsyncIoctl *msg = new AsyncIoctl(    AsyncIoctl *msg = new AsyncIoctl(
Line 366 
Line 375 
    msg->op->_state &= ~ASYNC_OPSTATE_COMPLETE;    msg->op->_state &= ~ASYNC_OPSTATE_COMPLETE;
  
    msg->op->_op_dest = this;    msg->op->_op_dest = this;
    msg->op->_request.insert_first(msg);     msg->op->_request.insert_front(msg);
    try {    try {
      _incoming.insert_last_wait(msg->op);       _incoming.enqueue_wait(msg->op);
      _polling_sem.signal();      _polling_sem.signal();
    } catch (const ListClosed &)    } catch (const ListClosed &)
    {    {
Line 404 
Line 413 
     try     try
     {     {
  
         if (service->_die.value() != 0)          if (service->_die.get() != 0)
         {         {
             service->_threads--;             service->_threads--;
             return (0);             return (0);
Line 418 
Line 427 
         {         {
             try             try
             {             {
                 operation = service->_incoming.remove_first();                  operation = service->_incoming.dequeue();
             }             }
             catch (ListClosed &)             catch (ListClosed &)
             {             {
Line 538 
Line 547 
 // << Tue Feb 19 14:10:38 2002 mdd >> // << Tue Feb 19 14:10:38 2002 mdd >>
       operation->lock();       operation->lock();
  
       Message *rq = operation->_request.next(0);        Message *rq = operation->_request.front();
  
 // optimization <<< Thu Mar  7 21:04:05 2002 mdd >>> // optimization <<< Thu Mar  7 21:04:05 2002 mdd >>>
 // move this to the bottom of the loop when the majority of // move this to the bottom of the loop when the majority of
Line 547 
Line 556 
       // divert legacy messages to handleEnqueue       // divert legacy messages to handleEnqueue
       if ((rq != 0) && (!(rq->getMask() & message_mask::ha_async)))       if ((rq != 0) && (!(rq->getMask() & message_mask::ha_async)))
       {       {
          rq = operation->_request.remove_first() ;           rq = operation->_request.remove_front() ;
          operation->unlock();          operation->unlock();
          // delete the op node          // delete the op node
          operation->release();          operation->release();
Line 641 
Line 650 
  
       AsyncLegacyOperationResult *async_result =       AsyncLegacyOperationResult *async_result =
          new AsyncLegacyOperationResult(          new AsyncLegacyOperationResult(
             async->getKey(),  
             async->getRouting(),             async->getRouting(),
             op,             op,
             response);             response);
Line 693 
Line 701 
  
 Boolean MessageQueueService::accept_async(AsyncOpNode *op) Boolean MessageQueueService::accept_async(AsyncOpNode *op)
 { {
    if (_incoming_queue_shutdown.value() > 0)     if (_incoming_queue_shutdown.get() > 0)
       return false;       return false;
    if (_polling_thread == NULL)    if (_polling_thread == NULL)
    {    {
       _polling_thread = new Thread(       _polling_thread = new Thread(
           polling_routine,           polling_routine,
           reinterpret_cast<void *>(&_polling_list),            reinterpret_cast<void *>(_get_polling_list()),
           false);           false);
       ThreadStatus tr = PEGASUS_THREAD_OK;       ThreadStatus tr = PEGASUS_THREAD_OK;
       while ( (tr =_polling_thread->run()) != PEGASUS_THREAD_OK)       while ( (tr =_polling_thread->run()) != PEGASUS_THREAD_OK)
Line 714 
Line 722 
 // ATTN optimization remove the message checking altogether in the base // ATTN optimization remove the message checking altogether in the base
 // << Mon Feb 18 14:02:20 2002 mdd >> // << Mon Feb 18 14:02:20 2002 mdd >>
    op->lock();    op->lock();
    Message *rq = op->_request.next(0);     Message *rq = op->_request.front();
    Message *rp = op->_response.next(0);     Message *rp = op->_response.front();
    op->unlock();    op->unlock();
  
    if ((rq != 0 && (true == messageOK(rq))) ||    if ((rq != 0 && (true == messageOK(rq))) ||
        (rp != 0 && (true == messageOK(rp))) && _die.value() == 0)         (rp != 0 && (true == messageOK(rp))) && _die.get() == 0)
    {    {
       _incoming.insert_last_wait(op);        _incoming.enqueue_wait(op);
       _polling_sem.signal();       _polling_sem.signal();
       return true;       return true;
    }    }
Line 730 
Line 738 
  
 Boolean MessageQueueService::messageOK(const Message *msg) Boolean MessageQueueService::messageOK(const Message *msg)
 { {
    if (_incoming_queue_shutdown.value() > 0)     if (_incoming_queue_shutdown.get() > 0)
       return false;       return false;
    return true;    return true;
 } }
Line 741 
Line 749 
  
    AsyncReply *reply = new AsyncReply(    AsyncReply *reply = new AsyncReply(
       async_messages::HEARTBEAT,       async_messages::HEARTBEAT,
       req->getKey(),  
       req->getRouting(),       req->getRouting(),
       0,       0,
       req->op,       req->op,
Line 775 
Line 782 
          // ensure we do not accept any further messages          // ensure we do not accept any further messages
  
          // ensure we don't recurse on IO_CLOSE          // ensure we don't recurse on IO_CLOSE
          if (_incoming_queue_shutdown.value() > 0)           if (_incoming_queue_shutdown.get() > 0)
             break;             break;
  
          // set the closing flag          // set the closing flag
Line 786 
Line 793 
             AsyncOpNode *operation;             AsyncOpNode *operation;
             try             try
             {             {
                operation = service->_incoming.remove_first();                 operation = service->_incoming.dequeue();
             }             }
             catch(IPCException &)             catch(IPCException &)
             {             {
Line 801 
Line 808 
                break;                break;
          } // message processing loop          } // message processing loop
  
          // shutdown the AsyncDQueue           // shutdown the AsyncQueue
          service->_incoming.shutdown_queue();          service->_incoming.shutdown_queue();
          return;          return;
       }       }
Line 1001 
Line 1008 
    }    }
    else    else
    {    {
       op->_request.insert_first(msg);        op->_request.insert_front(msg);
       (static_cast<AsyncMessage *>(msg))->op = op;       (static_cast<AsyncMessage *>(msg))->op = op;
    }    }
    return _meta_dispatcher->route_async(op);    return _meta_dispatcher->route_async(op);
Line 1021 
Line 1028 
    if (op == 0)    if (op == 0)
    {    {
       op = get_op();       op = get_op();
       op->_request.insert_first(msg);        op->_request.insert_front(msg);
       if (mask & message_mask::ha_async)       if (mask & message_mask::ha_async)
       {       {
          (static_cast<AsyncMessage *>(msg))->op = op;          (static_cast<AsyncMessage *>(msg))->op = op;
Line 1054 
Line 1061 
    if (request->op == 0)    if (request->op == 0)
    {    {
       request->op = get_op();       request->op = get_op();
       request->op->_request.insert_first(request);        request->op->_request.insert_front(request);
       destroy_op = true;       destroy_op = true;
    }    }
  
Line 1070 
Line 1077 
    request->op->_client_sem.wait();    request->op->_client_sem.wait();
  
    request->op->lock();    request->op->lock();
    AsyncReply * rpl = static_cast<AsyncReply *>(request->op->_response.remove_first());     AsyncReply * rpl = static_cast<AsyncReply *>(request->op->_response.remove_front());
    rpl->op = 0;    rpl->op = 0;
    request->op->unlock();    request->op->unlock();
  
Line 1258 
Line 1265 
  
 Uint32 MessageQueueService::get_next_xid() Uint32 MessageQueueService::get_next_xid()
 { {
    static Mutex _monitor;      return _xidFactory.getID();
    Uint32 value;  }
    AutoMutex autoMut(_monitor);  
    _xid++;  MessageQueueService::PollingList* MessageQueueService::_get_polling_list()
    value =  _xid.value();  {
    return value;      _polling_list_mutex.lock();
   
       if (!_polling_list)
           _polling_list = new PollingList;
   
       _polling_list_mutex.unlock();
  
       return _polling_list;
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.117  
changed lines
  Added in v.1.121

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2