This file is indexed.

/usr/include/libdap/MarshallerThread.h is in libdap-dev 3.15.1-7.

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
// -*- mode: c++; c-basic-offset:4 -*-

// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.

// Copyright (c) 2015 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// 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
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.

/*
 * MarshallerThread.h
 *
 *  Created on: Aug 27, 2015
 *      Author: jimg
 */

#ifndef MARSHALLERTHREAD_H_
#define MARSHALLERTHREAD_H_

#include <pthread.h>

#include <iostream>
#include <ostream>
#include <string>

namespace libdap {

/**
 * RAII for the MarshallerThread mutex and condition variable. Used by the
 * Main thread. The constructor locks the mutex and then, if the count of
 * child threads is not zero, blocks on the associated condition variable.
 * When signaled by the child thread using the condition variable (the child
 * thread count should then be zero), the mutex is (re)locked and the ctor
 * returns. The destructor unlocks the mutex.
 */
class Locker {
public:
    Locker(pthread_mutex_t &lock, pthread_cond_t &cond, int &count);
    virtual ~Locker();

private:
    pthread_mutex_t& m_mutex;

    Locker();
    Locker(const Locker &rhs);
};

/**
 * RAII (for MarshallerThread) used by the child thread. The ctor simply
 * locks the mutex; the dtor clears the child thread count, signals that
 * count has changed and unlocks the mutex.
 */
class ChildLocker {
public:
    ChildLocker(pthread_mutex_t &lock, pthread_cond_t &cond, int &count);
    virtual ~ChildLocker();

private:
    pthread_mutex_t& m_mutex;
    pthread_cond_t& m_cond;
    int& m_count;

    ChildLocker();
    ChildLocker(const Locker &rhs);
};

class MarshallerThread {
private:
    pthread_t d_thread;
    pthread_attr_t d_thread_attr;

    pthread_mutex_t d_out_mutex;
    pthread_cond_t d_out_cond;

    int d_child_thread_count;   // 0 or 1
    std::string d_thread_error; // non-null indicates an error

    static bool print_time; // false by default

    /**
     * Used to pass information into the static methods that run the
     * simple stream writer threads. This can pass both an ostream or
     * a file descriptor. If a fd is passed, the ostream reference is
     * set to stderr (i.e., std::cerr).
     */
    struct write_args {
        pthread_mutex_t &d_mutex;
        pthread_cond_t &d_cond;
        int &d_count;
        std::string &d_error;
        std::ostream &d_out;     // The output stream protected by the mutex, ...
        int d_out_file;       // file descriptor; if not -1, use this.
        char *d_buf;        // The data to write to the stream
        int d_num;          // The size of d_buf

        /**
         * Build args for an ostream. The file descriptor is set to -1
         */
        write_args(pthread_mutex_t &m, pthread_cond_t &c, int &count, std::string &e, std::ostream &s, char *vals, int num) :
            d_mutex(m), d_cond(c), d_count(count), d_error(e), d_out(s), d_out_file(-1), d_buf(vals), d_num(num)
        {
        }

        /**
         * Build args for a file descriptr. The ostream is set to cerr (because it is
         * a reference and has to be initialized to something).
         */
        write_args(pthread_mutex_t &m, pthread_cond_t &c, int &count, std::string &e, int fd, char *vals, int num) :
            d_mutex(m), d_cond(c), d_count(count), d_error(e), d_out(std::cerr), d_out_file(fd), d_buf(vals), d_num(num)
        {
        }
   };

public:
    MarshallerThread();
    virtual ~MarshallerThread();

    pthread_mutex_t &get_mutex() { return d_out_mutex; }
    pthread_cond_t &get_cond() { return d_out_cond; }

    int &get_child_thread_count() { return d_child_thread_count; }
    void increment_child_thread_count() { ++d_child_thread_count; }

    void start_thread(void* (*thread)(void *arg), std::ostream &out, char *byte_buf, unsigned int bytes_written);
    void start_thread(void* (*thread)(void *arg), int fd, char *byte_buf, unsigned int bytes_written);

    // These are static so they will have c-linkage - required because they
    // are passed to pthread_create()
    static void *write_thread(void *arg);
    static void *write_thread_part(void *arg);

    static void set_print_time(bool state) { print_time = state; }
    static bool get_print_time() { return print_time; }
};

}

#endif /* MARSHALLERTHREAD_H_ */