annotate src/neon/rb.c @ 1719:29c35cb8873e

- Add neon HTTP transport plugin sources (for real)
author Ralf Ertzinger <ralf@skytale.net>
date Mon, 17 Sep 2007 21:46:53 +0200
parents
children dc83901850df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
2 * Ringbuffer implementation
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
3 *
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
4 * GPL
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
5 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
6 #include <string.h>
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
7 #include "rb.h"
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
8 #include "debug.h"
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
9
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
10 #ifdef RB_DEBUG
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
11 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
12 * An internal assertion function to make sure that the
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
13 * ringbuffer structure is consistient.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
14 *
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
15 * WARNING: This function will call abort() if the ringbuffer
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
16 * is found to be inconsistient.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
17 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
18 static void _assert_rb(struct ringbuf* rb) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
19
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
20 unsigned int realused;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
21
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
22 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
23
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
24 _DEBUG("rb->buf=%p, rb->end=%p, rb->wp=%p, rb->rp=%p, rb->free=%u, rb->used=%u, rb->size=%u",
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
25 rb->buf, rb->end, rb->wp, rb->rp, rb->free, rb->used, rb->size);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
26
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
27 if (0 == rb->size) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
28 _ERROR("Buffer size is 0");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
29 abort();
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
30 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
31
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
32 if (NULL == rb->buf) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
33 _ERROR("Buffer start is NULL");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
34 abort();
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
35 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
36
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
37 if (rb->used+rb->free != rb->size) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
38 _ERROR("rb->free and rb->used do not add up to rb->size");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
39 abort();
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
40 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
41
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
42 if (rb->buf+(rb->size-1) != rb->end) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
43 _ERROR("rb->buf and rb->end not rb->size bytes apart");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
44 abort();
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
45 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
46
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
47 if ((rb->wp < rb->buf) || (rb->wp > rb->end)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
48 _ERROR("Write pointer outside buffer space");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
49 abort();
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
50 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
51
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
52 if ((rb->rp < rb->buf) || (rb->rp > rb->end)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
53 _ERROR("Read pointer outside buffer space");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
54 abort();
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
55 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
56
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
57 if (rb->rp <= rb->wp) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
58 realused = rb->wp - rb->rp;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
59 } else {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
60 realused = (rb->end - rb->rp) + 1 + (rb->wp-rb->buf);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
61 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
62
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
63 if (rb->used != realused) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
64 _ERROR("Usage count is inconsistient (is %d, should be %d)", rb->used, realused);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
65 abort();
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
66 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
67
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
68 _LEAVE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
69 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
70 #endif
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
71
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
72 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
73 * Reset a ringbuffer structure (i.e. discard
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
74 * all data inside of it)
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
75 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
76 void reset_rb(struct ringbuf* rb) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
77
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
78 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
79
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
80 pthread_mutex_lock(&rb->lock);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
81
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
82 rb->wp = rb->buf;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
83 rb->rp = rb->buf;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
84 rb->free = rb->size;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
85 rb->used = 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
86 rb->end = rb->buf+(rb->size-1);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
87
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
88 pthread_mutex_unlock(&rb->lock);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
89
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
90 _LEAVE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
91 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
92
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
93 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
94 * Initialize a ringbuffer structure (including
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
95 * memory allocation.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
96 *
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
97 * Return -1 on error
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
98 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
99 int init_rb(struct ringbuf* rb, unsigned int size) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
100
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
101 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
102
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
103 if (0 == size) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
104 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
105 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
106
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
107 if (0 != pthread_mutex_init(&rb->lock, NULL)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
108 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
109 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
110
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
111 if (NULL == (rb->buf = malloc(size))) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
112 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
113 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
114 rb->size = size;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
115 reset_rb(rb);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
116
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
117 ASSERT_RB(rb);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
118
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
119 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
120 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
121
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
122 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
123 * Write size bytes at buf into the ringbuffer.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
124 * Return -1 on error (not enough space in buffer)
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
125 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
126 int write_rb(struct ringbuf* rb, void* buf, unsigned int size) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
127
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
128 int ret = -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
129 int endfree;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
130
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
131 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
132
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
133 pthread_mutex_lock(&rb->lock);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
134
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
135 ASSERT_RB(rb);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
136
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
137 if (rb->free < size) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
138 ret = -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
139 goto out;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
140 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
141
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
142 endfree = (rb->end - rb->wp)+1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
143 if (endfree < size) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
144 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
145 * There is enough space in the buffer, but not in
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
146 * one piece. We need to split the copy into two parts.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
147 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
148 memcpy(rb->wp, buf, endfree);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
149 memcpy(rb->buf, buf+endfree, size-endfree);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
150 rb->wp = rb->buf + (size-endfree);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
151 } else if (endfree > size) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
152 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
153 * There is more space than needed at the end
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
154 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
155 memcpy(rb->wp, buf, size);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
156 rb->wp += size;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
157 } else {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
158 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
159 * There is exactly the space needed at the end.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
160 * We need to wrap around the read pointer.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
161 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
162 memcpy(rb->wp, buf, size);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
163 rb->wp = rb->buf;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
164 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
165
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
166 rb->free -= size;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
167 rb->used += size;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
168
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
169 ret = 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
170
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
171 out:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
172 ASSERT_RB(rb);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
173 pthread_mutex_unlock(&rb->lock);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
174
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
175 _LEAVE ret;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
176 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
177
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
178 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
179 * Read size byes from buffer into buf.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
180 * Return -1 on error (not enough data in buffer)
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
181 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
182 int read_rb(struct ringbuf* rb, void* buf, unsigned int size) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
183
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
184 int ret;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
185
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
186 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
187
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
188 pthread_mutex_lock(&rb->lock);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
189 ret = read_rb_locked(rb, buf, size);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
190 pthread_mutex_unlock(&rb->lock);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
191
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
192 _LEAVE ret;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
193 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
194
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
195 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
196 * Read size bytes from buffer into buf, assuming the buffer lock
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
197 * is already held.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
198 * Return -1 on error (not enough data in buffer)
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
199 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
200 int read_rb_locked(struct ringbuf* rb, void* buf, unsigned int size) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
201
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
202 int endused;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
203
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
204 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
205
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
206 ASSERT_RB(rb);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
207
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
208 if (rb->used < size) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
209 /* Not enough bytes in buffer */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
210 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
211 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
212
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
213 if (rb->rp < rb->wp) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
214 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
215 Read pointer is behind write pointer, all the data is available in one cunk
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
216 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
217 memcpy(buf, rb->rp, size);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
218 rb->rp += size;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
219 } else {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
220 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
221 * Read pointer is before write pointer
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
222 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
223 endused = (rb->end - rb->rp)+1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
224
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
225 if (size < endused) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
226 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
227 * Data is available in one chunk
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
228 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
229 memcpy(buf, rb->rp, size);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
230 rb->rp += size;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
231 } else {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
232 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
233 * There is enough data in the buffer, but it is fragmented.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
234 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
235 memcpy(buf, rb->rp, endused);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
236 memcpy(buf+endused, rb->buf, size-endused);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
237 rb->rp = rb->buf + (size-endused);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
238 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
239 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
240
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
241 rb->free += size;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
242 rb->used -= size;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
243
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
244 ASSERT_RB(rb);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
245
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
246 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
247 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
248
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
249 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
250 * Return the amount of free space currently in the rb
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
251 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
252 unsigned int free_rb(struct ringbuf* rb) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
253
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
254 unsigned int f;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
255
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
256 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
257
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
258 pthread_mutex_lock(&rb->lock);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
259 f = rb->free;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
260 pthread_mutex_unlock(&rb->lock);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
261
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
262 _LEAVE f;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
263 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
264
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
265
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
266 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
267 * Return the amount of used space currently in the rb
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
268 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
269 unsigned int used_rb(struct ringbuf* rb) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
270
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
271 unsigned int u;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
272
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
273 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
274
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
275 pthread_mutex_lock(&rb->lock);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
276 u = rb->used;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
277 pthread_mutex_unlock(&rb->lock);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
278
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
279 _LEAVE u;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
280 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
281
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
282
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
283 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
284 * destroy a ringbuffer
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
285 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
286 void destroy_rb(struct ringbuf* rb) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
287
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
288 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
289 pthread_mutex_lock(&rb->lock);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
290 free(rb->buf);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
291 pthread_mutex_unlock(&rb->lock);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
292
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
293 _LEAVE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
294 }