Ejemplo n.º 1
0
// Destructor
OsProtectEventMgr::~OsProtectEventMgr()
{
   OsProtectedEvent* pEvent;

   mListSem.acquire();
   for (int i=0; i<mCurrentCount; i++)
   {
      pEvent = mpEvents[i];
      if (NULL != pEvent)
          {
         if (!pEvent->isInUse())
                 {
            mpEvents[i] = NULL;
            delete pEvent;
         }
      }
   }
   delete[] mpEvents;
   mpEvents = NULL;

   mListSem.release();
}
Ejemplo n.º 2
0
OsProtectedEvent* OsProtectEventMgr::alloc(void* userData)
{
        int i;
        OsProtectedEvent* pEvent = NULL;
        OsProtectedEvent* ret = NULL;

        mListSem.acquire();

        for (i=0; ((i<mCurrentCount)&&(NULL==ret)); i++)
        {
          pEvent = mpEvents[mNext++];
          if ((NULL != pEvent) && !pEvent->isInUse())
          {
                 pEvent->setInUse(TRUE);
                 ret = pEvent;
       break;
          }
          if (mNext >= mCurrentCount) mNext = 0;
        }

        if (NULL == ret)
        {
          if (mCurrentCount >= mSoftLimit)
          {
             OsSysLog::add(FAC_KERNEL, PRI_ERR,
                           "OsProtectEventMgr::alloc OsProtectedEvent pool exceeds soft limit (%d>%d) ***",
                           mCurrentCount + 1, mSoftLimit);
          }
          if (mCurrentCount < mHardLimit)
          {
                 int limit;

                 mNext = mCurrentCount;
                 limit = mCurrentCount + mIncrement;
                 if (limit > mHardLimit) limit = mHardLimit;
                 for (i=mCurrentCount; i<limit; i++)
                 {
                        pEvent = new OsProtectedEvent(userData);
                        if (NULL != pEvent)
                        {
                           pEvent->setInUse(FALSE);
                           mpEvents[i] = pEvent;
                           mCurrentCount++;
                        }
                 }
                 ret = mpEvents[mNext];
                 assert(NULL!=ret);
                 if ((NULL != ret) && !ret->isInUse())
                 {
                        ret->setInUse(TRUE);
                 }
                 mNext++;
                 if (mNext >= mCurrentCount) mNext = 0;
          }
          else
          {
        OsSysLog::add(FAC_KERNEL, PRI_CRIT,
                        "*** OsProtectEventMgr: pool exceeds hard limit (%d) *** ", mHardLimit);
          }
        }

        if (ret != NULL)
                mAllocs++;

    // If the number of outstanding events is a multiple of 10
    if(((mAllocs - mFrees) % (mIncrement/5)) == 0)
    {
        OsSysLog::add(FAC_KERNEL, PRI_DEBUG, "OsProtectEventMgr::alloc in use: %d pool size: %d num. allocs:%d",
            mAllocs - mFrees, mCurrentCount, mAllocs);
    }

        mListSem.release();
        return ret;
}