~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/transaction_log/write_buffer.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
35
#include <vector>
 
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
  {
 
72
    return &buffer[0];
 
73
  }
 
74
  /**
 
75
   * Returns the size of the write buffer
 
76
   */
 
77
  size_t getCapacity()
 
78
  {
 
79
    return buffer.size();
 
80
  }
 
81
private:
 
82
  /* Prohibit these */
 
83
  WriteBuffer(const WriteBuffer&);
 
84
  WriteBuffer &operator=(const WriteBuffer&);
 
85
 
 
86
  std::vector<uint8_t> buffer; ///< Raw memory buffer managed by the log
 
87
  pthread_mutex_t latch; ///< Lock around the synchronized parts of the log (the write buffer)
 
88
};
 
89
 
 
90
#endif /* PLUGIN_TRANSACTION_LOG_WRITE_BUFFER_H */