blob: 7d9d8c8a16d862cb5c058d22d3183b2301dd7b81 [file] [log] [blame]
William Lallemand24a7a752017-10-09 14:17:39 +02001#ifndef __TYPES_SHCTX
2#define __TYPES_SHCTX
3
William Lallemand24a7a752017-10-09 14:17:39 +02004#ifndef SHSESS_BLOCK_MIN_SIZE
5#define SHSESS_BLOCK_MIN_SIZE 128
6#endif
7
8#ifndef SHSESS_MAX_DATA_LEN
9#define SHSESS_MAX_DATA_LEN 4096
10#endif
11
12#ifndef SHCTX_APPNAME
13#define SHCTX_APPNAME "haproxy"
14#endif
15
16#define SHCTX_E_ALLOC_CACHE -1
17#define SHCTX_E_INIT_LOCK -2
18
William Lallemand4f45bb92017-10-30 20:08:51 +010019#define SHCTX_F_REMOVING 0x1 /* Removing flag, does not accept new */
William Lallemand24a7a752017-10-09 14:17:39 +020020
William Lallemand4f45bb92017-10-30 20:08:51 +010021/* generic shctx struct */
William Lallemand24a7a752017-10-09 14:17:39 +020022struct shared_block {
William Lallemand4f45bb92017-10-30 20:08:51 +010023 struct list list;
William Lallemand111bfef2017-11-21 20:01:25 +010024 unsigned int len; /* data length for the row */
25 unsigned int block_count; /* number of blocks */
William Lallemand4f45bb92017-10-30 20:08:51 +010026 unsigned int refcount;
Frédéric Lécaille0bec8072018-10-22 17:55:57 +020027 struct shared_block *last_reserved;
28 struct shared_block *last_append;
William Lallemand4f45bb92017-10-30 20:08:51 +010029 unsigned char data[0];
William Lallemand24a7a752017-10-09 14:17:39 +020030};
31
32struct shared_context {
33#ifndef USE_PRIVATE_CACHE
34#ifdef USE_PTHREAD_PSHARED
35 pthread_mutex_t mutex;
36#else
37 unsigned int waiters;
38#endif
39#endif
William Lallemand4f45bb92017-10-30 20:08:51 +010040 struct list avail; /* list for active and free blocks */
41 struct list hot; /* list for locked blocks */
42 unsigned int nbav; /* number of available blocks */
Frédéric Lécailleb80bc272018-10-25 20:31:40 +020043 unsigned int max_obj_size; /* maximum object size (in bytes). */
William Lallemand4f45bb92017-10-30 20:08:51 +010044 void (*free_block)(struct shared_block *first, struct shared_block *block);
45 short int block_size;
46 unsigned char data[0];
William Lallemand24a7a752017-10-09 14:17:39 +020047};
48
William Lallemand24a7a752017-10-09 14:17:39 +020049#endif