This file is indexed.

/usr/include/ola/thread/Thread.h is in libola-dev 0.9.8-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
/*
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * Thread.h
 * A thread object.
 * Copyright (C) 2010 Simon Newton
 */

#ifndef INCLUDE_OLA_THREAD_THREAD_H_
#define INCLUDE_OLA_THREAD_THREAD_H_

#ifdef _WIN32
// On MinGW, pthread.h pulls in Windows.h, which in turn pollutes the global
// namespace. We define VC_EXTRALEAN and WIN32_LEAN_AND_MEAN to reduce this.
#define VC_EXTRALEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <pthread.h>
#include <ola/base/Macro.h>
#include <ola/thread/Mutex.h>

#include <string>

#if defined(_WIN32) && defined(__GNUC__)
inline std::ostream& operator<<(std::ostream &stream,
                                 const ptw32_handle_t &handle) {
  stream << handle.p;
  return stream;
}
#endif

namespace ola {
namespace thread {

typedef pthread_t ThreadId;

/**
 * A thread object that can be subclassed.
 */
class Thread {
 public:
  /**
   * @brief Thread options.
   *
   * The Scheduler options default to PTHREAD_EXPLICIT_SCHED, with the policy
   * and priority set to the default values for the platform.
   */
  struct Options {
   public:
    /**
     * @brief The name of the thread.
     */
    std::string name;

    /**
     * @brief The scheduling policy.
     *
     * Should be one of SCHED_OTHER (usually the platform default), SCHED_FIFO
     *   or SCHED_RR.
     */
    int policy;

    /**
     * @brief The thread priority.
     *
     * Defaults to the default value of the platform.
     */
    int priority;

    /**
     * @brief The scheduling mode, either PTHREAD_EXPLICIT_SCHED or
     *   PTHREAD_INHERIT_SCHED.
     *
     * Defaults to PTHREAD_EXPLICIT_SCHED.
     */
    int inheritsched;

    /**
     * @brief Create new thread Options.
     * @param name the name of the thread.
     */
    explicit Options(const std::string &name = "");
  };

  /**
   * @brief Create a new thread with the specified thread options.
   * @param options the thread's options
   */
  explicit Thread(const Options &options = Options());

  /**
   * @brief Destructor
   */
  virtual ~Thread() {}

  /**
   * @brief Start the thread and wait for the thread to be running.
   * @returns true if the thread started, false otherwise.
   *
   * This will block until the thread is running. Use FastStart() if you don't
   * want to block.
   */
  virtual bool Start();

  /**
   * @brief Start the thread and return immediately.
   * @returns true if the thread started, false otherwise.
   *
   * Don't use this unless you know what you're doing, since it introduces a
   * race condition with Join().
   */
  virtual bool FastStart();

  /**
   * @brief Join this thread.
   * @param[out] ptr The value returned from the thread.
   * @returns false if the thread wasn't running or didn't stop, true otherwise.
   */
  virtual bool Join(void *ptr = NULL);

  /**
   * @brief Check if the thread is running.
   * @return true if the thread was running at some point in the past.
   *
   * This is best-effort only, since the thread may stop after IsRunning()
   * returns.
   */
  bool IsRunning();

  /**
   * @brief Return the thread id.
   * @returns the thread id.
   */
  ThreadId Id() const { return m_thread_id; }

  /**
   * @brief Return the thread name.
   * @returns the thread name.
   *
   * This may differ from the name assigned with pthread_setname, since the
   * latter has a limit of 16 characters.
   */
  std::string Name() const { return m_options.name; }

  /**
   * @private
   * Called by pthread_create. Internally this calls Run().
   */
  void* _InternalRun();

  /**
   * @brief Returns the current thread's id.
   * @returns the current thread's id.
   */
  static inline ThreadId Self() { return pthread_self(); }

 protected:
  /**
   * @brief The entry point for the new thread.
   * @returns A value returned to Join().
   *
   * Sub classes must implement this.
   */
  virtual void *Run() = 0;

 private:
  pthread_t m_thread_id;
  bool m_running;
  Options m_options;
  Mutex m_mutex;  // protects m_running
  ConditionVariable m_condition;  // use to wait for the thread to start

  DISALLOW_COPY_AND_ASSIGN(Thread);
};
}  // namespace thread
}  // namespace ola
#endif  // INCLUDE_OLA_THREAD_THREAD_H_