mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-05-11 15:36:27 +03:00
Make buffered writer an independent module
This commit is contained in:
parent
6b6b4709b3
commit
6d8e616902
13 changed files with 76 additions and 57 deletions
36
src/buf_writer.c
Normal file
36
src/buf_writer.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#define JEMALLOC_BUF_WRITER_C_
|
||||
#include "jemalloc/internal/jemalloc_preamble.h"
|
||||
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
||||
|
||||
#include "jemalloc/internal/buf_writer.h"
|
||||
#include "jemalloc/internal/malloc_io.h"
|
||||
|
||||
void
|
||||
buf_write_flush(buf_write_arg_t *arg) {
|
||||
assert(arg->buf_end <= arg->buf_size);
|
||||
arg->buf[arg->buf_end] = '\0';
|
||||
if (arg->write_cb == NULL) {
|
||||
arg->write_cb = je_malloc_message != NULL ?
|
||||
je_malloc_message : wrtmessage;
|
||||
}
|
||||
arg->write_cb(arg->cbopaque, arg->buf);
|
||||
arg->buf_end = 0;
|
||||
}
|
||||
|
||||
void
|
||||
buf_write_cb(void *buf_write_arg, const char *s) {
|
||||
buf_write_arg_t *arg = (buf_write_arg_t *)buf_write_arg;
|
||||
size_t i, slen, n, s_remain, buf_remain;
|
||||
assert(arg->buf_end <= arg->buf_size);
|
||||
for (i = 0, slen = strlen(s); i < slen; i += n) {
|
||||
if (arg->buf_end == arg->buf_size) {
|
||||
buf_write_flush(arg);
|
||||
}
|
||||
s_remain = slen - i;
|
||||
buf_remain = arg->buf_size - arg->buf_end;
|
||||
n = s_remain < buf_remain ? s_remain : buf_remain;
|
||||
memcpy(arg->buf + arg->buf_end, s + i, n);
|
||||
arg->buf_end += n;
|
||||
}
|
||||
assert(i == slen);
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "jemalloc/internal/assert.h"
|
||||
#include "jemalloc/internal/atomic.h"
|
||||
#include "jemalloc/internal/buf_writer.h"
|
||||
#include "jemalloc/internal/ctl.h"
|
||||
#include "jemalloc/internal/extent_dss.h"
|
||||
#include "jemalloc/internal/extent_mmap.h"
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@
|
|||
/******************************************************************************/
|
||||
/* Function prototypes for non-inline static functions. */
|
||||
|
||||
static void wrtmessage(void *cbopaque, const char *s);
|
||||
#define U2S_BUFSIZE ((1U << (LG_SIZEOF_INTMAX_T + 3)) + 1)
|
||||
static char *u2s(uintmax_t x, unsigned base, bool uppercase, char *s,
|
||||
size_t *slen_p);
|
||||
|
|
@ -68,7 +67,7 @@ static char *x2s(uintmax_t x, bool alt_form, bool uppercase, char *s,
|
|||
/******************************************************************************/
|
||||
|
||||
/* malloc_message() setup. */
|
||||
static void
|
||||
void
|
||||
wrtmessage(void *cbopaque, const char *s) {
|
||||
malloc_write_fd(STDERR_FILENO, s, strlen(s));
|
||||
}
|
||||
|
|
@ -664,36 +663,6 @@ malloc_printf(const char *format, ...) {
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
buf_write_flush(buf_write_arg_t *arg) {
|
||||
assert(arg->buf_end <= arg->buf_size);
|
||||
arg->buf[arg->buf_end] = '\0';
|
||||
if (arg->write_cb == NULL) {
|
||||
arg->write_cb = je_malloc_message != NULL ?
|
||||
je_malloc_message : wrtmessage;
|
||||
}
|
||||
arg->write_cb(arg->cbopaque, arg->buf);
|
||||
arg->buf_end = 0;
|
||||
}
|
||||
|
||||
void
|
||||
buf_write_cb(void *buf_write_arg, const char *s) {
|
||||
buf_write_arg_t *arg = (buf_write_arg_t *)buf_write_arg;
|
||||
size_t i, slen, n, s_remain, buf_remain;
|
||||
assert(arg->buf_end <= arg->buf_size);
|
||||
for (i = 0, slen = strlen(s); i < slen; i += n) {
|
||||
if (arg->buf_end == arg->buf_size) {
|
||||
buf_write_flush(arg);
|
||||
}
|
||||
s_remain = slen - i;
|
||||
buf_remain = arg->buf_size - arg->buf_end;
|
||||
n = s_remain < buf_remain ? s_remain : buf_remain;
|
||||
memcpy(arg->buf + arg->buf_end, s + i, n);
|
||||
arg->buf_end += n;
|
||||
}
|
||||
assert(i == slen);
|
||||
}
|
||||
|
||||
/*
|
||||
* Restore normal assertion macros, in order to make it possible to compile all
|
||||
* C files as a single concatenation.
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
||||
|
||||
#include "jemalloc/internal/assert.h"
|
||||
#include "jemalloc/internal/buf_writer.h"
|
||||
#include "jemalloc/internal/ckh.h"
|
||||
#include "jemalloc/internal/emitter.h"
|
||||
#include "jemalloc/internal/hash.h"
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
||||
|
||||
#include "jemalloc/internal/assert.h"
|
||||
#include "jemalloc/internal/buf_writer.h"
|
||||
#include "jemalloc/internal/emitter.h"
|
||||
#include "jemalloc/internal/prof_data.h"
|
||||
#include "jemalloc/internal/prof_recent.h"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue