William Lallemand | 24a7a75 | 2017-10-09 14:17:39 +0200 | [diff] [blame] | 1 | #ifndef __TYPES_SHCTX |
| 2 | #define __TYPES_SHCTX |
| 3 | |
William Lallemand | 24a7a75 | 2017-10-09 14:17:39 +0200 | [diff] [blame] | 4 | #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 Lallemand | 4f45bb9 | 2017-10-30 20:08:51 +0100 | [diff] [blame] | 19 | #define SHCTX_F_REMOVING 0x1 /* Removing flag, does not accept new */ |
William Lallemand | 24a7a75 | 2017-10-09 14:17:39 +0200 | [diff] [blame] | 20 | |
William Lallemand | 4f45bb9 | 2017-10-30 20:08:51 +0100 | [diff] [blame] | 21 | /* generic shctx struct */ |
William Lallemand | 24a7a75 | 2017-10-09 14:17:39 +0200 | [diff] [blame] | 22 | struct shared_block { |
William Lallemand | 4f45bb9 | 2017-10-30 20:08:51 +0100 | [diff] [blame] | 23 | struct list list; |
William Lallemand | 111bfef | 2017-11-21 20:01:25 +0100 | [diff] [blame] | 24 | unsigned int len; /* data length for the row */ |
| 25 | unsigned int block_count; /* number of blocks */ |
William Lallemand | 4f45bb9 | 2017-10-30 20:08:51 +0100 | [diff] [blame] | 26 | unsigned int refcount; |
Frédéric Lécaille | 0bec807 | 2018-10-22 17:55:57 +0200 | [diff] [blame] | 27 | struct shared_block *last_reserved; |
| 28 | struct shared_block *last_append; |
William Lallemand | 4f45bb9 | 2017-10-30 20:08:51 +0100 | [diff] [blame] | 29 | unsigned char data[0]; |
William Lallemand | 24a7a75 | 2017-10-09 14:17:39 +0200 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | struct 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 Lallemand | 4f45bb9 | 2017-10-30 20:08:51 +0100 | [diff] [blame] | 40 | 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écaille | b80bc27 | 2018-10-25 20:31:40 +0200 | [diff] [blame] | 43 | unsigned int max_obj_size; /* maximum object size (in bytes). */ |
William Lallemand | 4f45bb9 | 2017-10-30 20:08:51 +0100 | [diff] [blame] | 44 | void (*free_block)(struct shared_block *first, struct shared_block *block); |
| 45 | short int block_size; |
| 46 | unsigned char data[0]; |
William Lallemand | 24a7a75 | 2017-10-09 14:17:39 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
William Lallemand | 24a7a75 | 2017-10-09 14:17:39 +0200 | [diff] [blame] | 49 | #endif |