annotate src/neon/rb.h @ 2335:6b9d5a8b509e

automated merge
author mf0102 <0102@gmx.at>
date Wed, 23 Jan 2008 14:12:02 +0100
parents b73ea297d197
children f1b6f1b2cdb3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1751
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
1 /*
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
2 * This program is free software; you can redistribute it and/or modify
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
3 * it under the terms of the GNU General Public License as published by
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
4 * the Free Software Foundation; either version 2 of the License, or
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
5 * (at your option) any later version.
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
6 *
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
7 * This program is distributed in the hope that it will be useful,
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
10 * GNU General Public License for more details.
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
11 *
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
12 * You should have received a copy of the GNU General Public License
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
13 * along with this program; if not, write to the Free Software
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
15 */
dc83901850df - Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
16
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
17 #ifndef _RB_H
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
18 #define _RB_H
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
19
2151
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
20 #ifdef _RB_USE_GLIB
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
21 #include <glib.h>
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
22
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
23 typedef GMutex rb_mutex_t;
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
24 #define _RB_LOCK(L) g_mutex_lock(L)
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
25 #define _RB_UNLOCK(L) g_mutex_unlock(L)
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
26
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
27 #else
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
28 #include <pthread.h>
2151
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
29
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
30 typedef pthread_mutex_t rb_mutex_t;
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
31 #define _RB_LOCK(L) pthread_mutex_lock(L)
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
32 #define _RB_UNLOCK(L) pthread_mutex_unlock(L)
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
33 #endif
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
34
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
35 #include <stdlib.h>
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 #ifdef RB_DEBUG
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
38 #define ASSERT_RB(buf) _assert_rb(buf)
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
39 #else
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
40 #define ASSERT_RB(buf)
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
41 #endif
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
42
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
43 struct ringbuf {
2151
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
44 rb_mutex_t* lock;
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
45 char _free_lock;
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
46 char* buf;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
47 char* end;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
48 char* wp;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
49 char* rp;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
50 unsigned int free;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
51 unsigned int used;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
52 unsigned int size;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
53 };
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
54
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
55 int init_rb(struct ringbuf* rb, unsigned int size);
2151
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
56 int init_rb_with_lock(struct ringbuf* rb, unsigned int size, rb_mutex_t* lock);
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
57 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
58 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
59 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
60 void reset_rb(struct ringbuf* rb);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
61 unsigned int free_rb(struct ringbuf* rb);
2151
9a9f406374c6 - Update ring buffer code to newer version
Ralf Ertzinger <ralf@skytale.net>
parents: 1751
diff changeset
62 unsigned int free_rb_locked(struct ringbuf* rb);
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
63 unsigned int used_rb(struct ringbuf* rb);
2183
b73ea297d197 - New version of ringbuffer code
Ralf Ertzinger <ralf@skytale.net>
parents: 2151
diff changeset
64 unsigned int used_rb_locked(struct ringbuf* rb);
1722
2e33cfa6a872 - Correct some compiler warnings
Ralf Ertzinger <ralf@skytale.net>
parents: 1719
diff changeset
65 void destroy_rb(struct ringbuf* rb);
1719
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 #endif