mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-23 00:00:06 +01:00

Optimizations for memory-tight systems. Check all previous gaps first for any usage, so gaps we created when faced with perhaps a relatively large allocation that left a lot of the last chunk on the table can be backfilled with smaller things as it goes on. Separate the members that only live in the head object out of the buffer management object, reducing the cost of new chunks. Allocate the head object members as the first thing in the first chunk, and adjust all the code to look there for them.
62 lines
2.2 KiB
C
62 lines
2.2 KiB
C
/*
|
|
* libwebsockets - small server side websockets and web server implementation
|
|
*
|
|
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to
|
|
* deal in the Software without restriction, including without limitation the
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
* IN THE SOFTWARE.
|
|
*/
|
|
|
|
#if !defined(__LWS_PRIVATE_LIB_MISC_LWSAC_H__)
|
|
#define __LWS_PRIVATE_LIB_MISC_LWSAC_H__
|
|
|
|
#if !defined(LWS_PLAT_OPTEE)
|
|
#include <sys/stat.h>
|
|
#endif
|
|
|
|
/* under page size of 4096 to allow overhead */
|
|
#define LWSAC_CHUNK_SIZE 4000
|
|
|
|
/*
|
|
* the chunk list members all point back to the head themselves so the list
|
|
* can be detached from the formal head and free itself when its reference
|
|
* count reaches zero.
|
|
*/
|
|
|
|
struct lwsac {
|
|
struct lwsac *next;
|
|
struct lwsac *head; /* pointer back to the first chunk */
|
|
size_t alloc_size;
|
|
size_t ofs; /* next writeable position inside chunk */
|
|
};
|
|
|
|
struct lwsac_head {
|
|
struct lwsac *curr; /* applies to head chunk only */
|
|
size_t total_alloc_size; /* applies to head chunk only */
|
|
int refcount; /* applies to head chunk only */
|
|
int total_blocks; /* applies to head chunk only */
|
|
char detached; /* if our refcount gets to zero, free the chunk list */
|
|
};
|
|
|
|
#if !defined(LWS_PLAT_OPTEE)
|
|
struct cached_file_info {
|
|
struct stat s;
|
|
time_t last_confirm;
|
|
};
|
|
#endif
|
|
#endif
|