~drizzle-trunk/drizzle/development

1405.4.1 by Jay Pipes
Adds a vector of write buffers to the transaction log applier
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (c) 2010 Jay Pipes <jaypipes@gmail.com>
5
 *
6
 *  Authors:
7
 *
8
 *  Jay Pipes <jaypipes@gmail.com>
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  (at your option) any later version.
14
 *
15
 *  This program 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
18
 *  GNU General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
21
 *  along with this program; if not, write to the Free Software
22
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23
 */
24
25
/**
26
 * @file
27
 *
28
 * Defines a simple structure for maintaining a write buffer.
29
 */
30
31
#ifndef PLUGIN_TRANSACTION_LOG_WRITE_BUFFER_H
32
#define PLUGIN_TRANSACTION_LOG_WRITE_BUFFER_H
33
34
#include <stdint.h>
1405.5.1 by Jay Pipes
Changes uint8_t * to vector<uint8_t>.
35
#include <vector>
1405.4.1 by Jay Pipes
Adds a vector of write buffers to the transaction log applier
36
#include <pthread.h>
37
38
class WriteBuffer
39
{
40
public:
41
  static const size_t DEFAULT_WRITE_BUFFER_SIZE= 1024; /* Many GPB messages are < 1 KB... */
42
  /**
43
   * Constructor.
44
   */
45
  WriteBuffer();
46
  ~WriteBuffer();
47
  /**
48
   * Locks the log write buffer
49
   */
50
  void lock()
51
  {
52
    pthread_mutex_lock(&latch);
53
  }
54
  /**
55
   * Unlocks the log's write buffer
56
   */
57
  void unlock()
58
  {
59
    pthread_mutex_unlock(&latch);
60
  }
61
  /**
62
   * Resizes the internal raw byte buffer
63
   *
64
   * @param[in] New size to allocate
65
   */
66
  void resize(size_t new_size);
67
  /**
68
   * Returns the pointer to the raw bytes.
69
   */
70
  uint8_t *getRawBytes()
71
  {
1405.5.1 by Jay Pipes
Changes uint8_t * to vector<uint8_t>.
72
    return &buffer[0];
1405.4.1 by Jay Pipes
Adds a vector of write buffers to the transaction log applier
73
  }
74
  /**
75
   * Returns the size of the write buffer
76
   */
77
  size_t getCapacity()
78
  {
1405.5.1 by Jay Pipes
Changes uint8_t * to vector<uint8_t>.
79
    return buffer.size();
1405.4.1 by Jay Pipes
Adds a vector of write buffers to the transaction log applier
80
  }
81
private:
82
  /* Prohibit these */
83
  WriteBuffer(const WriteBuffer&);
84
  WriteBuffer &operator=(const WriteBuffer&);
85
1405.5.1 by Jay Pipes
Changes uint8_t * to vector<uint8_t>.
86
  std::vector<uint8_t> buffer; ///< Raw memory buffer managed by the log
1405.4.1 by Jay Pipes
Adds a vector of write buffers to the transaction log applier
87
  pthread_mutex_t latch; ///< Lock around the synchronized parts of the log (the write buffer)
88
};
89
1405.4.12 by Jay Pipes
Fix cpplint header guard.
90
#endif /* PLUGIN_TRANSACTION_LOG_WRITE_BUFFER_H */