示例#1
0
// Core send message logic.
OsStatus OsMsgQShared::doSendCore(OsMsg* pMsg,
                                  const OsTime& rTimeout,
                                  UtlBoolean isUrgent,
                                  UtlBoolean deleteWhenDone)
{
   if (mSendHookFunc != NULL)
   {
      if (mSendHookFunc(*pMsg))
      {
         // by returning TRUE, the mSendHookFunc indicates that it has handled
         // the message and there is no need to queue the message.
         if (deleteWhenDone)
         {
            // Delete *pMsg, since we are done with it.
            delete pMsg;
         }
         return OS_SUCCESS;
      }
   }

   enqueue(pMsg);

   int count = numMsgs();
   
   if (_reportFull && 2 * count > mMaxMsgs)
   {
     OS_LOG_WARNING(FAC_KERNEL,
                   "OsMsgQShared::doSendCore message queue '" << mName.data()
                   << "' is over half full - count = " << count
                   << " max = " << mMaxMsgs);
   }

   system_tap_queue_enqueue(mName.data(), 0, _queue.size());
   return OS_SUCCESS;
}
示例#2
0
// Core send message logic.
OsStatus OsMsgQShared::doSendCore(OsMsg* pMsg,
                                  const OsTime& rTimeout,
                                  UtlBoolean isUrgent,
                                  UtlBoolean deleteWhenDone)
{
   OsStatus ret;
   const void*    insResult;

#ifdef MSGQ_IS_VALID_CHECK /* [ */
   int      msgCnt;

   ret = mGuard.acquire();         // start critical section
   assert(ret == OS_SUCCESS);

   testMessageQ();

   mNumInsertEntry++;

   ret = mGuard.release();         // exit critical section
   assert(ret == OS_SUCCESS);
#endif /* MSGQ_IS_VALID_CHECK ] */

   if (mSendHookFunc != NULL)
   {
      if (mSendHookFunc(*pMsg))
      {
         // by returning TRUE, the mSendHookFunc indicates that it has handled
         // the message and there is no need to queue the message.
#ifdef MSGQ_IS_VALID_CHECK /* [ */
         OsStatus rc = mGuard.acquire();         // start critical section
         assert(rc == OS_SUCCESS);

         mNumInsertExitOk++;
         testMessageQ();

         rc = mGuard.release();         // exit critical section
         assert(rc == OS_SUCCESS);
#endif /* MSGQ_IS_VALID_CHECK ] */
         if (deleteWhenDone)
         {
            // Delete *pMsg, since we are done with it.
            delete pMsg;
         }
         return OS_SUCCESS;
      }
   }

   ret = mEmpty.acquire(rTimeout);   // wait for there to be room in the queue
   if (ret != OS_SUCCESS)
   {
      // Do not log problem with the queue for the syslog task to prevent
      // infinite recursion.
      if (mName != "syslog")
      {
         Os::Logger::instance().log(FAC_KERNEL, PRI_ERR,
                       "OsMsgQShared::doSendCore message send failed for queue '%s' - no room, ret = %d",
                       mName.data(), ret);
      }
      if (ret == OS_BUSY || ret == OS_WAIT_TIMEOUT)
      {
          ret =  OS_WAIT_TIMEOUT;     // send timed out
      }
      if (deleteWhenDone)
      {
         // Delete *pMsg, since we are done with it.
         delete pMsg;
      }
   }
   else
   {
      int count, max;
      mFull.getCountMax(count, max);
      // Do not log problems with the queue for the syslog task to prevent
      // infinite recursion.
      if (mReportFull && 2 * count > max && mName != "syslog")
      {
         Os::Logger::instance().log(FAC_KERNEL, PRI_NOTICE,
                       "OsMsgQShared::doSendCore message queue '%s' is over half full - count = %d, max = %d",
                       mName.data(), count, max);
      }

      ret = mGuard.acquire();           // start critical section
      assert(ret == OS_SUCCESS);

      if (isUrgent)
      {
         insResult = mDlist.insertAt(0, pMsg); // insert msg at queue head
      }
      else
      {
         insResult = mDlist.insert(pMsg);      // insert msg at queue tail
      }

#ifdef MSGQ_IS_VALID_CHECK
      msgCnt = mDlist.entries();
      if (msgCnt > mHighCnt)
      {
	 mHighCnt = msgCnt;
      }
#endif

      if (insResult == NULL)
      {                                 // queue insert failed
         Os::Logger::instance().log(FAC_KERNEL, PRI_CRIT,
                       "OsMsgQShared::doSendCore message send failed - insert failed");
         assert(FALSE);

         if (deleteWhenDone)
         {
            // Delete *pMsg, since we are done with it.
            delete pMsg;
         }
         ret = OS_UNSPECIFIED;
      }
      else
      {
         ret = mFull.release();            // signal rcvrs that a msg is available
         assert(ret == OS_SUCCESS);
      }

#ifdef OS_MSGQ_REPORTING
      int curCount;
      UtlBoolean increasedLevel = FALSE;
      UtlBoolean decreasedLevel = FALSE;

      curCount = mDlist.entries();
      if (curCount >= mIncreaseLevel)
      {
          increasedLevel = TRUE;
          while (curCount >= mIncreaseLevel)
          {
              mIncreaseLevel += mIncrementLevel;
          }
          mDecreaseLevel = mIncreaseLevel - (2 * mIncrementLevel);
      }

      if (curCount <= mDecreaseLevel)
      {
          decreasedLevel = TRUE;
          while (curCount <= mDecreaseLevel)
          {
              mDecreaseLevel = mDecreaseLevel - mIncrementLevel;
          }
          mIncreaseLevel = mDecreaseLevel + (2 * mIncrementLevel);
      }
#endif

      OsStatus guardRet = mGuard.release();           // exit critical section
      assert(guardRet == OS_SUCCESS);

#ifdef OS_MSGQ_REPORTING
      if (increasedLevel)
      {
          OsSysLogPriority pri = PRI_INFO;
          if (curCount == mMaxMsgs)
	  {
	     pri = PRI_WARNING;
	  }

          Os::Logger::instance().log(FAC_KERNEL, pri,
                        "OsMsgQShared::doSendCore Message queue %p increased to %d msgs (max=%d)\n",
                        this, curCount, mMaxMsgs);
      }
      else if (decreasedLevel)
      {
          Os::Logger::instance().log(FAC_KERNEL, PRI_INFO,
                        "OsMsgQShared::doSendCore Message queue %p decreased to %d msgs (max=%d)\n",
                        this, curCount, mMaxMsgs);
      }
#endif
   }

   system_tap_queue_enqueue(mName.data(), 0, mDlist.entries());

#ifdef MSGQ_IS_VALID_CHECK /* [ */
   OsStatus rc = mGuard.acquire();         // start critical section
   assert(rc == OS_SUCCESS);

   if (ret == OS_SUCCESS)
   {
      mNumInsertExitOk++;
   }
   else
   {
      mNumInsertExitFail++;
   }

   testMessageQ();

   rc = mGuard.release();         // exit critical section
   assert(rc == OS_SUCCESS);
#endif /* MSGQ_IS_VALID_CHECK ] */

   return ret;
}