This file is indexed.

/usr/include/xmltooling/util/Threads.h is in libxmltooling-dev 1.6.4-1ubuntu2.

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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/**
 * Licensed to the University Corporation for Advanced Internet
 * Development, Inc. (UCAID) under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.
 *
 * UCAID licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the
 * License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 */

/**
 * @file xmltooling/util/Threads.h
 *
 * Thread and locking wrappers.
 */

#ifndef _xmltooling_threads_h
#define _xmltooling_threads_h

#include <xmltooling/exceptions.h>

#include <memory>
#include <boost/scoped_ptr.hpp>
#include <signal.h>

namespace xmltooling
{
    DECL_XMLTOOLING_EXCEPTION(ThreadingException,XMLTOOL_EXCEPTIONAPI(XMLTOOL_API),xmltooling,XMLToolingException,Exceptions during threading/locking operations);

    /**
     * A class for manual thread creation and synchronization.
     */
    class XMLTOOL_API Thread
    {
        MAKE_NONCOPYABLE(Thread);
    protected:
        Thread() {}
    public:
        virtual ~Thread() {}

        /**
         * Disassociate from the thread.
         *
         * @return 0 for success, non-zero for failure
         */
        virtual int detach()=0;

        /**
         * Join with the thread and wait for its completion.
         *
         * @param thread_return holds the return value of the thread routine
         * @return 0 for success, non-zero for failure
         */
        virtual int join(void** thread_return)=0;

        /**
         * Kill the thread.
         *
         * @param signo the signal to send to the thread
         * @return 0 for success, non-zero for failure
         */
        virtual int kill(int signo)=0;

        /**
         * Creates a new thread object to run the supplied start routine.
         *
         * @param start_routine the function to execute on the thread
         * @param arg           a parameter for the start routine
         * @param stacksize     size of stack to use, or 0 for default
         * @return  the created and running thread object
         */
        static Thread* create(void* (*start_routine)(void*), void* arg, size_t stacksize=0);

        /**
         * Exits a thread gracefully.
         *
         * @param return_val    the return value for the thread
         */
        static void exit(void* return_val);

        /**
         * Sleeps the current thread for the specified amount of time.
         *
         * @param seconds   time to sleep
         */
        static void sleep(int seconds);
#ifndef WIN32
        /**
         * Masks all signals from a thread.
         */
        static void mask_all_signals(void);

        /**
         * Masks specific signals from a thread.
         *
         * @param how
         * @param newmask   the new signal mask
         * @param oldmask   the old signal mask
         * @return 0 for success, non-zero for failure
         */
        static int mask_signals(int how, const sigset_t *newmask, sigset_t *oldmask);
#endif
    };

    /**
     * A class for managing Thread Local Storage values.
     */
    class XMLTOOL_API ThreadKey
    {
        MAKE_NONCOPYABLE(ThreadKey);
    protected:
        ThreadKey() {}
    public:
        virtual ~ThreadKey() {}

        /**
         * Sets the value for a TLS key.
         *
         * @param data  the value to set
         * @return 0 for success, non-zero for failure
         */
        virtual int setData(void* data)=0;

        /**
         * Returns the value for a TLS key.
         *
         * @return the value or nullptr
         */
        virtual void* getData() const=0;

        /**
         * Creates a new TLS key.
         *
         * @param destroy_fn    a functon to cleanup key values
         * @return the new key
         */
        static ThreadKey* create(void (*destroy_fn)(void*));

#ifdef WIN32
        /**
         * Allows system to notify TLS implementation when a thread completes.
         *
         * <p>Windows doesn't support TLS destructors, so only the DllMain detach
         * notification can be used to trigger per-thread cleanup.
         */
        static void onDetach();
#endif
    };

    /**
     * A class for managing exclusive access to resources.
     */
    class XMLTOOL_API Mutex
    {
        MAKE_NONCOPYABLE(Mutex);
    protected:
        Mutex() {}
    public:
        virtual ~Mutex() {}

        /**
         * Locks the mutex for exclusive access.
         *
         * @return 0 for success, non-zero for failure
         */
        virtual int lock()=0;

        /**
         * Unlocks the mutex for exclusive access.
         *
         * @return 0 for success, non-zero for failure
         */
        virtual int unlock()=0;

        /**
         * Creates a new mutex object.
         *
         * @return the new mutex
         */
        static Mutex* create();
    };

    /**
     * A class for managing shared and exclusive access to resources.
     */
    class XMLTOOL_API RWLock
    {
        MAKE_NONCOPYABLE(RWLock);
    protected:
        RWLock() {}
    public:
        virtual ~RWLock() {}

        /**
         * Obtains a shared lock.
         *
         * @return 0 for success, non-zero for failure
         */
        virtual int rdlock()=0;

        /**
         * Obtains an exclusive lock.
         *
         * @return 0 for success, non-zero for failure
         */
        virtual int wrlock()=0;

        /**
         * Unlocks the lock.
         *
         * @return 0 for success, non-zero for failure
         */
        virtual int unlock()=0;

        /**
         * Creates a new read/write lock.
         *
         * @return the new lock
         */
        static RWLock* create();
    };

    /**
     * A class for establishing queues on a mutex based on a periodic condition.
     */
    class XMLTOOL_API CondWait
    {
        MAKE_NONCOPYABLE(CondWait);
    protected:
        CondWait() {}
    public:
        virtual ~CondWait() {}

        /**
         * Waits for a condition variable using the supplied mutex as a queue.
         *
         * @param lock  mutex to queue on
         * @return 0 for success, non-zero for failure
         */
        virtual int wait(Mutex* lock)=0;

        /**
         * Waits for a condition variable using the supplied mutex as a queue,
         * but only for a certain time limit.
         *
         * @param lock          mutex to queue on
         * @param delay_seconds maximum time to wait before waking up
         * @return 0 for success, non-zero for failure
         */
        virtual int timedwait(Mutex* lock, int delay_seconds)=0;

        /**
         * Signal a single thread to wake up if a condition changes.
         *
         * @return 0 for success, non-zero for failure
         */
        virtual int signal()=0;

        /**
         * Signal all threads to wake up if a condition changes.
         *
         * @return 0 for success, non-zero for failure
         */
        virtual int broadcast()=0;

        /**
         * Creates a new condition variable.
         *
         * @return the new condition variable
         */
        static CondWait* create();
    };

    /**
     * RAII wrapper for a mutex lock.
     */
    class XMLTOOL_API Lock {
        MAKE_NONCOPYABLE(Lock);
    public:
        /**
         * Locks and wraps the designated mutex.
         *
         * @param mtx mutex to lock
         */
        Lock(Mutex* mtx) : mutex(mtx) {
            if (mutex)
                mutex->lock();
        }

        /**
         * Locks and wraps the designated mutex.
         *
         * @param mtx mutex to lock
         */
        Lock(Mutex& mtx) : mutex(&mtx) {
            mtx.lock();
        }

        /**
         * Locks and wraps the designated mutex.
         *
         * @param mtx mutex to lock
         */
        Lock(const std::auto_ptr<Mutex>& mtx) : mutex(mtx.get()) {
            if (mutex)
                mutex->lock();
        }

        /**
         * Locks and wraps the designated mutex.
         *
         * @param mtx mutex to lock
         */
        Lock(const boost::scoped_ptr<Mutex>& mtx) : mutex(mtx.get()) {
            if (mutex)
                mutex->lock();
        }

        /**
         * Unlocks the wrapped mutex, if any.
         */
        ~Lock() {
            if (mutex)
                mutex->unlock();
        }

        /**
         * Releases control of the original Mutex and returns it without unlocking it.
         *
         * @return the original, locked Mutex
         */
        Mutex* release() {
            Mutex* ret = mutex;
            mutex = nullptr;
            return ret;
        }

    private:
        Mutex* mutex;
    };

    /**
     * RAII wrapper for a shared lock.
     */
    class XMLTOOL_API SharedLock {
        MAKE_NONCOPYABLE(SharedLock);
    public:
        /**
         * Locks and wraps the designated shared lock.
         *
         * @param lock      lock to acquire
         * @param lockit    true if the lock should be acquired here, false if already acquired
         */
        SharedLock(RWLock* lock, bool lockit=true) : rwlock(lock) {
            if (rwlock && lockit)
                rwlock->rdlock();
        }

        /**
         * Locks and wraps the designated shared lock.
         *
         * @param lock      lock to acquire
         * @param lockit    true if the lock should be acquired here, false if already acquired
         */
        SharedLock(const std::auto_ptr<RWLock>& lock, bool lockit=true) : rwlock(lock.get()) {
            if (rwlock && lockit)
                rwlock->rdlock();
        }

        /**
         * Locks and wraps the designated shared lock.
         *
         * @param lock      lock to acquire
         * @param lockit    true if the lock should be acquired here, false if already acquired
         */
        SharedLock(const boost::scoped_ptr<RWLock>& lock, bool lockit=true) : rwlock(lock.get()) {
            if (rwlock && lockit)
                rwlock->rdlock();
        }

        /**
         * Unlocks the wrapped shared lock, if any.
         */
        ~SharedLock() {
            if (rwlock)
                rwlock->unlock();
        }

        /**
         * Releases control of the original shared lock and returns it without unlocking it.
         *
         * @return the original shared lock
         */
        RWLock* release() {
            RWLock* ret = rwlock;
            rwlock = nullptr;
            return ret;
        }

    private:
        RWLock* rwlock;
    };

}

#endif /* _xmltooling_threads_h */