libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
MarshallerThread.h
Go to the documentation of this file.
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of libdap, A C++ implementation of the OPeNDAP Data
5// Access Protocol.
6
7// Copyright (c) 2015 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26/*
27 * MarshallerThread.h
28 *
29 * Created on: Aug 27, 2015
30 * Author: jimg
31 */
32
33#ifndef MARSHALLERTHREAD_H_
34#define MARSHALLERTHREAD_H_
35
36#include <pthread.h>
37
38#include <iostream>
39#include <ostream>
40#include <string>
41
42namespace libdap {
43
52class Locker {
53public:
54 Locker() = delete;
55 Locker(pthread_mutex_t &lock, pthread_cond_t &cond, int &count);
56 virtual ~Locker();
57
58private:
59 pthread_mutex_t &m_mutex;
60
61 Locker(const Locker &rhs);
62};
63
75public:
76 ChildLocker() = delete;
77 ChildLocker(const Locker &rhs) = delete;
78 ChildLocker(pthread_mutex_t &lock, pthread_cond_t &cond, int &count);
79 virtual ~ChildLocker();
80
81private:
82 pthread_mutex_t &m_mutex;
83 pthread_cond_t &m_cond;
84 int &m_count;
85};
86
96private:
97 pthread_t d_thread = 0;
98 pthread_attr_t d_thread_attr;
99
100 pthread_mutex_t d_out_mutex;
101 pthread_cond_t d_out_cond;
102
103 int d_child_thread_count = 0; // 0 or 1
104 std::string d_thread_error; // non-null indicates an error
105
112 struct write_args {
113 pthread_mutex_t &d_mutex;
114 pthread_cond_t &d_cond;
115 int &d_count;
116 std::string &d_error;
117 std::ostream &d_out; // The output stream protected by the mutex, ...
118 int d_out_file; // file descriptor; if not -1, use this.
119 char *d_buf; // The data to write to the stream
120 std::streamsize d_num; // The size of d_buf
121
125 write_args(pthread_mutex_t &m, pthread_cond_t &c, int &count, std::string &e, std::ostream &s, char *vals,
126 std::streamsize num)
127 : 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) {}
128
133 write_args(pthread_mutex_t &m, pthread_cond_t &c, int &count, std::string &e, int fd, char *vals,
134 std::streamsize num)
135 : d_mutex(m), d_cond(c), d_count(count), d_error(e), d_out(std::cerr), d_out_file(fd), d_buf(vals),
136 d_num(num) {}
137 };
138
139public:
141 virtual ~MarshallerThread();
142
143 pthread_mutex_t &get_mutex() { return d_out_mutex; }
144 pthread_cond_t &get_cond() { return d_out_cond; }
145
146 int &get_child_thread_count() { return d_child_thread_count; }
147 void increment_child_thread_count() { ++d_child_thread_count; }
148
149 void start_thread(void *(*thread)(void *arg), std::ostream &out, char *byte_buf, std::streamsize bytes_written);
150 void start_thread(void *(*thread)(void *arg), int fd, char *byte_buf, std::streamsize bytes_written);
151
152 // These are static so they will have c-linkage - required because they
153 // are passed to pthread_create()
154 static void *write_thread(void *arg);
155 static void *write_thread_part(void *arg);
156};
157
158} // namespace libdap
159
160#endif /* MARSHALLERTHREAD_H_ */
ChildLocker(const Locker &rhs)=delete
Locker()=delete
static void * write_thread(void *arg)
void start_thread(void *(*thread)(void *arg), std::ostream &out, char *byte_buf, std::streamsize bytes_written)
pthread_mutex_t & get_mutex()
static void * write_thread_part(void *arg)
pthread_cond_t & get_cond()
top level DAP object to house generic methods
Definition AISConnect.cc:30