This file is indexed.

/usr/include/InsightToolkit/Common/itkLoggerThreadWrapper.txx is in libinsighttoolkit3-dev 3.20.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkLoggerThreadWrapper.txx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __itkLoggerThreadWrapper_txx
#define __itkLoggerThreadWrapper_txx
#if ! ( defined(_MSC_VER)  ||   (defined(__GNUC__) && (__GNUC__ <= 2) ))//NOTE: This class does not work under MSVS6, or gnu 2.95

#include<iostream>
#include "itkLoggerThreadWrapper.h"


namespace itk
{

/** Set the priority level for the current logger. Only messages that have
 * priorities equal or greater than the one set here will be posted to the
 * current outputs */
template < class SimpleLoggerType >
void LoggerThreadWrapper<SimpleLoggerType>::SetPriorityLevel( PriorityLevelType level )
{
  this->m_WaitMutex.Unlock();
  this->m_Mutex.Lock();
  this->m_OperationQ.push(SET_PRIORITY_LEVEL);
  this->m_LevelQ.push(level);
  this->m_Mutex.Unlock();
  this->m_WaitMutex.Lock();
}

/** Get the priority level for the current logger. Only messages that have
 * priorities equal or greater than the one set here will be posted to the
 * current outputs */
template < class SimpleLoggerType >
typename SimpleLoggerType::PriorityLevelType LoggerThreadWrapper<SimpleLoggerType>::GetPriorityLevel() const
{
  this->m_Mutex.Lock();
  PriorityLevelType level = this->m_PriorityLevel;
  this->m_Mutex.Unlock();
  return level;
}

template < class SimpleLoggerType >
void LoggerThreadWrapper<SimpleLoggerType>::SetLevelForFlushing( PriorityLevelType level )
{
  this->m_WaitMutex.Unlock();
  this->m_Mutex.Lock();
  this->m_LevelForFlushing = level;
  this->m_OperationQ.push(SET_LEVEL_FOR_FLUSHING);
  this->m_LevelQ.push(level);
  this->m_Mutex.Unlock();
  this->m_WaitMutex.Lock();
}

template < class SimpleLoggerType >
typename SimpleLoggerType::PriorityLevelType LoggerThreadWrapper<SimpleLoggerType>::GetLevelForFlushing() const
{
  this->m_Mutex.Lock();
  PriorityLevelType level = this->m_LevelForFlushing;
  this->m_Mutex.Unlock();
  return level;
}

/** Adds an output stream to the MultipleLogOutput for writing. */
template < class SimpleLoggerType >
void LoggerThreadWrapper<SimpleLoggerType>::AddLogOutput( OutputType* output )
{
  this->m_WaitMutex.Unlock();
  this->m_Mutex.Lock();
  this->m_OperationQ.push(ADD_LOG_OUTPUT);
  this->m_OutputQ.push(output);
  this->m_Mutex.Unlock();
  this->m_WaitMutex.Lock();
}

template < class SimpleLoggerType >
void LoggerThreadWrapper<SimpleLoggerType>::Write(PriorityLevelType level, std::string const & content)
{
  this->m_WaitMutex.Unlock();
  this->m_Mutex.Lock();
  if( this->m_PriorityLevel >= level )
    {
    this->m_OperationQ.push(WRITE);
    this->m_MessageQ.push(content);
    this->m_LevelQ.push(level);
    }
  this->m_Mutex.Unlock();
  if( this->m_LevelForFlushing >= level )
    {
    this->Flush();
    }
  this->m_WaitMutex.Lock();
}

template < class SimpleLoggerType >
void LoggerThreadWrapper<SimpleLoggerType>::Flush()
{
  this->m_Mutex.Lock();

  while( !this->m_OperationQ.empty() )
    {
    switch( this->m_OperationQ.front() )
      {
      case Self::SET_PRIORITY_LEVEL:
        this->m_PriorityLevel = this->m_LevelQ.front();
        this->m_LevelQ.pop();
        break;
      case Self::SET_LEVEL_FOR_FLUSHING:
        this->m_LevelForFlushing = this->m_LevelQ.front();
        this->m_LevelQ.pop();
        break;

      case Self::ADD_LOG_OUTPUT:
        this->m_Output->AddLogOutput(this->m_OutputQ.front());
        this->m_OutputQ.pop();
        break;

      case Self::WRITE:
        this->SimpleLoggerType::Write(this->m_LevelQ.front(), this->m_MessageQ.front());
        this->m_LevelQ.pop();
        this->m_MessageQ.pop();
        break;
      case Self::FLUSH:
        this->SimpleLoggerType::Flush();
        break;
      }
      this->m_OperationQ.pop();
    }
    this->m_Output->Flush();
  this->m_Mutex.Unlock();
}


/** Constructor */
template < class SimpleLoggerType >
LoggerThreadWrapper<SimpleLoggerType>::LoggerThreadWrapper()
{
  this->m_WaitMutex.Lock();
  this->m_Threader = MultiThreader::New();
  this->m_ThreadID = this->m_Threader->SpawnThread(ThreadFunction, this);
}


/** Destructor */
template < class SimpleLoggerType >
LoggerThreadWrapper<SimpleLoggerType>::~LoggerThreadWrapper()
{
  this->Flush();
  this->m_WaitMutex.Unlock();
  if( this->m_Threader )
    {
    this->m_Threader->TerminateThread(this->m_ThreadID);
    }
}


template < class SimpleLoggerType >
ITK_THREAD_RETURN_TYPE LoggerThreadWrapper<SimpleLoggerType>::ThreadFunction(void* pInfoStruct)
{
  struct MultiThreader::ThreadInfoStruct * pInfo = (struct MultiThreader::ThreadInfoStruct*)pInfoStruct;

  if( pInfo == NULL )
    {
    return ITK_THREAD_RETURN_VALUE;
    }

  if( pInfo->UserData == NULL )
    {
    return ITK_THREAD_RETURN_VALUE;
    }

  LoggerThreadWrapper *pLogger = (LoggerThreadWrapper*)pInfo->UserData;

  while(1)
    {

    pLogger->m_WaitMutex.Lock();

    pInfo->ActiveFlagLock->Lock();
    int activeFlag = *pInfo->ActiveFlag;
    pInfo->ActiveFlagLock->Unlock();
    if( !activeFlag )
      {
      break;
      }

    pLogger->m_Mutex.Lock();
    while( !pLogger->m_OperationQ.empty() )
      {
      switch( pLogger->m_OperationQ.front() )
        {
        case Self::SET_PRIORITY_LEVEL:
          pLogger->m_PriorityLevel = pLogger->m_LevelQ.front();
          pLogger->m_LevelQ.pop();
          break;

        case Self::SET_LEVEL_FOR_FLUSHING:
          pLogger->m_LevelForFlushing = pLogger->m_LevelQ.front();
          pLogger->m_LevelQ.pop();
          break;

        case Self::ADD_LOG_OUTPUT:
          pLogger->m_Output->AddLogOutput(pLogger->m_OutputQ.front());
          pLogger->m_OutputQ.pop();
          break;

        case Self::WRITE:
          pLogger->SimpleLoggerType::Write(pLogger->m_LevelQ.front(), pLogger->m_MessageQ.front());
          pLogger->m_LevelQ.pop();
          pLogger->m_MessageQ.pop();
        break;
        case Self::FLUSH:
          pLogger->SimpleLoggerType::Flush();
          break;
        }
      pLogger->m_OperationQ.pop();
      }
    pLogger->m_Mutex.Unlock();
    pLogger->m_WaitMutex.Unlock();
    }
  return ITK_THREAD_RETURN_VALUE;
}


/** Print contents of a LoggerThreadWrapper */
template < class SimpleLoggerType >
void LoggerThreadWrapper<SimpleLoggerType>::PrintSelf(std::ostream &os, Indent indent) const
{
  Superclass::PrintSelf(os,indent);

  os << indent << "Thread ID: " << this->m_ThreadID << std::endl;
  os << indent << "Operation Queue Size: " << this->m_OperationQ.size() << std::endl;
  os << indent << "Message Queue Size: " << this->m_MessageQ.size() << std::endl;
  os << indent << "Level Queue Size: " << this->m_LevelQ.size() << std::endl;
  os << indent << "Output Queue Size: " << this->m_OutputQ.size() << std::endl;
}


} // namespace itk

#endif  // !defined (_MSC_VER)
#endif