Commit 67b6748f authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

util: add ability to release a last piece from a shared pool (v2)

v2: s/shfree/shfree_last
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent ae70bc0a
......@@ -319,5 +319,6 @@ static inline int read_img_str(int fd, char **pstr, int size)
}
extern void *shmalloc(size_t bytes);
extern void shfree_last(void *ptr);
#endif /* UTIL_H_ */
......@@ -297,6 +297,7 @@ int is_anon_link_type(int lfd, char *type)
static void *sh_buf;
static unsigned int sh_bytes_left;
static size_t sh_last_size;
#define SH_BUF_CHUNK 4096
void *shmalloc(size_t bytes)
......@@ -322,6 +323,16 @@ void *shmalloc(size_t bytes)
ret = sh_buf;
sh_buf += bytes;
sh_bytes_left -= bytes;
sh_last_size = bytes;
return ret;
}
/* Only last chunk can be released */
void shfree_last(void *ptr)
{
BUG_ON(sh_buf - sh_last_size != ptr);
sh_buf -= sh_last_size;
sh_bytes_left += sh_last_size;
sh_last_size = 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment