LCOV - code coverage report
Current view: top level - HLT/BASE - AliHLTAsyncMemberProcessor.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 32 6.2 %
Date: 2016-06-14 17:26:59 Functions: 8 22 36.4 %

          Line data    Source code
       1             : #ifndef H_ALIHLTASYNCMEMBERPROCESSOR
       2             : #define H_ALIHLTASYNCMEMBERPROCESSOR
       3             : 
       4             : /* This file is property of and copyright by the ALICE HLT Project        * 
       5             : * ALICE Experiment at CERN, All rights reserved.                         *
       6             : * See cxx source for full Copyright notice                               */
       7             : 
       8             : /** @file    AliHLTAsyncMemberProcessor.h
       9             : @author  David Rohr (drohr@cern.ch)
      10             : */
      11             : 
      12             : //This file is a wrapper for AliHLTAsyncProcessor, which allows to use
      13             : //member functions as callbacks in the queue.
      14             : //This class provides the two additional functions QueueAsyncMemberTask and
      15             : //InitializeAsyncMemberTask on top of the interface provided by AliHLTAsyncProcessor.
      16             : //They work in the same fashion as QueueAsyncTask and InitializeAsyncTask, but
      17             : //instead of non-member or static member function, they take member functions
      18             : //as callback paramters. Hence, the class instance (usually 'this') must be passed first.
      19             : 
      20             : #include "AliHLTAsyncProcessor.h"
      21             : 
      22             : template <class T>
      23             : class AliHLTAsyncMemberProcessor : public AliHLTAsyncProcessor
      24             : {
      25             : public:
      26          24 :         AliHLTAsyncMemberProcessor() : AliHLTAsyncProcessor() {}
      27          24 :         virtual ~AliHLTAsyncMemberProcessor() {}
      28             : 
      29             :         int QueueAsyncMemberTask(T* obj, void* (T::*function)(void*), void* data)
      30             :         {
      31           0 :                 AliHLTAsyncMemberProcessorContainer* tmp = GetContainer();
      32           0 :                 if (tmp == NULL) return(1);
      33           0 :                 tmp->Set(obj, function, data);
      34           0 :                 int retVal = QueueAsyncTask(&QueueAsyncMemberTaskHelper, tmp);
      35           0 :                 if (retVal) FreeContainer(tmp);
      36             :                 return (retVal);
      37           0 :         }
      38             : 
      39             :         void* InitializeAsyncMemberTask(T* obj, void* (T::*function)(void*), void* data)
      40             :         {
      41             :                 AliHLTAsyncMemberProcessorContainer* tmp = GetContainer();
      42             :                 if (tmp == NULL) return(NULL);
      43             :                 tmp->Set(obj, function, data);
      44             :                 void* retVal = InitializeAsyncTask(&QueueAsyncMemberTaskHelper, tmp);
      45             :                 if (retVal == NULL) FreeContainer(tmp);
      46             :                 return (retVal);
      47             :         }
      48             : 
      49             : private:
      50             :         AliHLTAsyncMemberProcessor(const AliHLTAsyncMemberProcessor&);
      51             :         AliHLTAsyncMemberProcessor& operator=(const AliHLTAsyncMemberProcessor&);
      52             :         
      53             :         struct AliHLTAsyncMemberProcessorContainer
      54             :         {
      55           0 :                 void Set(T* obj, void* (T::*function)(void*), void* data) {fObj = obj; fFunction = function; fData = data; fUsed = true;}
      56             :                 T* fObj;
      57             :                 void* (T::*fFunction)(void*);
      58             :                 void* fData;
      59             :                 bool fUsed;
      60             :                 bool fStaticallyAllocated;
      61             :         };
      62             : 
      63             :         AliHLTAsyncMemberProcessorContainer* GetContainer()
      64             :         {
      65             :                 AliHLTAsyncMemberProcessorContainer* container;
      66           0 :                 if (fMe->fQueueDepth == 0)
      67             :                 {
      68           0 :                         container = new AliHLTAsyncMemberProcessorContainer;
      69           0 :                         container->fStaticallyAllocated = false;
      70           0 :                         return(new AliHLTAsyncMemberProcessorContainer);
      71             :                 }
      72           0 :                 container = (AliHLTAsyncMemberProcessorContainer*) fMe->fChildBufferSpace;
      73           0 :                 LockMutex(5);
      74           0 :                 for (int i = 0;i <= fMe->fQueueDepth;i++)
      75             :                 {
      76           0 :                         if (!container[i].fUsed)
      77             :                         {
      78           0 :                                 container[i].fUsed = true;
      79           0 :                                 container[i].fStaticallyAllocated = true;
      80           0 :                                 UnlockMutex(5);
      81           0 :                                 return(&container[i]);
      82             :                         }
      83             :                 }
      84           0 :                 UnlockMutex(5);
      85           0 :                 return(NULL);
      86           0 :         }
      87             :         
      88             :         static void FreeContainer(AliHLTAsyncMemberProcessorContainer* ptr)
      89             :         {
      90           0 :                 if (!ptr->fStaticallyAllocated) delete ptr;
      91           0 :                 else ptr->fUsed = false;
      92           0 :         }
      93             : 
      94             :         static void* QueueAsyncMemberTaskHelper(void* data)
      95             :         {
      96           0 :                 AliHLTAsyncMemberProcessorContainer *tmpData = (AliHLTAsyncMemberProcessorContainer*) data;
      97           0 :                 AliHLTAsyncMemberProcessorContainer tmpDataCopy = *tmpData;
      98           0 :                 FreeContainer(tmpData);
      99           0 :                 return((tmpDataCopy.fObj->*tmpDataCopy.fFunction)(tmpDataCopy.fData));
     100             :         }
     101             :         
     102           0 :         virtual size_t ChildSharedProcessBufferSize() {return sizeof(AliHLTAsyncMemberProcessorContainer) * (fMe->fQueueDepth + 1);}
     103             : };
     104             : 
     105             : #endif

Generated by: LCOV version 1.11