Update brace style.

Add braces around single-line blocks, and remove line breaks before
function-opening braces.

This resolves #537.
This commit is contained in:
Jason Evans
2017-01-15 16:56:30 -08:00
parent 5154ff32ee
commit c4c2592c83
119 changed files with 2971 additions and 3572 deletions

View File

@@ -97,75 +97,65 @@ double genrand_res53_mix(sfmt_t *ctx);
#if (defined(JEMALLOC_ENABLE_INLINE) || defined(SFMT_C_))
/* These real versions are due to Isaku Wada */
/** generates a random number on [0,1]-real-interval */
JEMALLOC_INLINE double to_real1(uint32_t v)
{
JEMALLOC_INLINE double to_real1(uint32_t v) {
return v * (1.0/4294967295.0);
/* divided by 2^32-1 */
}
/** generates a random number on [0,1]-real-interval */
JEMALLOC_INLINE double genrand_real1(sfmt_t *ctx)
{
JEMALLOC_INLINE double genrand_real1(sfmt_t *ctx) {
return to_real1(gen_rand32(ctx));
}
/** generates a random number on [0,1)-real-interval */
JEMALLOC_INLINE double to_real2(uint32_t v)
{
JEMALLOC_INLINE double to_real2(uint32_t v) {
return v * (1.0/4294967296.0);
/* divided by 2^32 */
}
/** generates a random number on [0,1)-real-interval */
JEMALLOC_INLINE double genrand_real2(sfmt_t *ctx)
{
JEMALLOC_INLINE double genrand_real2(sfmt_t *ctx) {
return to_real2(gen_rand32(ctx));
}
/** generates a random number on (0,1)-real-interval */
JEMALLOC_INLINE double to_real3(uint32_t v)
{
JEMALLOC_INLINE double to_real3(uint32_t v) {
return (((double)v) + 0.5)*(1.0/4294967296.0);
/* divided by 2^32 */
}
/** generates a random number on (0,1)-real-interval */
JEMALLOC_INLINE double genrand_real3(sfmt_t *ctx)
{
JEMALLOC_INLINE double genrand_real3(sfmt_t *ctx) {
return to_real3(gen_rand32(ctx));
}
/** These real versions are due to Isaku Wada */
/** generates a random number on [0,1) with 53-bit resolution*/
JEMALLOC_INLINE double to_res53(uint64_t v)
{
JEMALLOC_INLINE double to_res53(uint64_t v) {
return v * (1.0/18446744073709551616.0L);
}
/** generates a random number on [0,1) with 53-bit resolution from two
* 32 bit integers */
JEMALLOC_INLINE double to_res53_mix(uint32_t x, uint32_t y)
{
JEMALLOC_INLINE double to_res53_mix(uint32_t x, uint32_t y) {
return to_res53(x | ((uint64_t)y << 32));
}
/** generates a random number on [0,1) with 53-bit resolution
*/
JEMALLOC_INLINE double genrand_res53(sfmt_t *ctx)
{
JEMALLOC_INLINE double genrand_res53(sfmt_t *ctx) {
return to_res53(gen_rand64(ctx));
}
}
/** generates a random number on [0,1) with 53-bit resolution
using 32bit integer.
*/
JEMALLOC_INLINE double genrand_res53_mix(sfmt_t *ctx)
{
JEMALLOC_INLINE double genrand_res53_mix(sfmt_t *ctx) {
uint32_t x, y;
x = gen_rand32(ctx);
y = gen_rand32(ctx);
return to_res53_mix(x, y);
}
}
#endif
#endif

View File

@@ -8,13 +8,12 @@ btalloc_n_proto(1)
#define btalloc_n_gen(n) \
void * \
btalloc_##n(size_t size, unsigned bits) \
{ \
btalloc_##n(size_t size, unsigned bits) { \
void *p; \
\
if (bits == 0) \
if (bits == 0) { \
p = mallocx(size, 0); \
else { \
} else { \
switch (bits & 0x1U) { \
case 0: \
p = (btalloc_0(size, bits >> 1)); \

View File

@@ -73,8 +73,7 @@ static bool did_merge;
static void *
extent_alloc_hook(extent_hooks_t *extent_hooks, void *new_addr, size_t size,
size_t alignment, bool *zero, bool *commit, unsigned arena_ind)
{
size_t alignment, bool *zero, bool *commit, unsigned arena_ind) {
void *ret;
TRACE_HOOK("%s(extent_hooks=%p, new_addr=%p, size=%zu, alignment=%zu, "
@@ -86,8 +85,9 @@ extent_alloc_hook(extent_hooks_t *extent_hooks, void *new_addr, size_t size,
assert_ptr_eq(extent_hooks->alloc, extent_alloc_hook,
"Wrong hook function");
called_alloc = true;
if (!try_alloc)
if (!try_alloc) {
return (NULL);
}
ret = default_hooks->alloc(default_hooks, new_addr, size, alignment,
zero, commit, 0);
did_alloc = (ret != NULL);
@@ -96,8 +96,7 @@ extent_alloc_hook(extent_hooks_t *extent_hooks, void *new_addr, size_t size,
static bool
extent_dalloc_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
bool committed, unsigned arena_ind)
{
bool committed, unsigned arena_ind) {
bool err;
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, committed=%s, "
@@ -108,8 +107,9 @@ extent_dalloc_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
assert_ptr_eq(extent_hooks->dalloc, extent_dalloc_hook,
"Wrong hook function");
called_dalloc = true;
if (!try_dalloc)
if (!try_dalloc) {
return (true);
}
err = default_hooks->dalloc(default_hooks, addr, size, committed, 0);
did_dalloc = !err;
return (err);
@@ -117,8 +117,7 @@ extent_dalloc_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
static bool
extent_commit_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
size_t offset, size_t length, unsigned arena_ind)
{
size_t offset, size_t length, unsigned arena_ind) {
bool err;
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, offset=%zu, "
@@ -129,8 +128,9 @@ extent_commit_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
assert_ptr_eq(extent_hooks->commit, extent_commit_hook,
"Wrong hook function");
called_commit = true;
if (!try_commit)
if (!try_commit) {
return (true);
}
err = default_hooks->commit(default_hooks, addr, size, offset, length,
0);
did_commit = !err;
@@ -139,8 +139,7 @@ extent_commit_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
static bool
extent_decommit_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
size_t offset, size_t length, unsigned arena_ind)
{
size_t offset, size_t length, unsigned arena_ind) {
bool err;
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, offset=%zu, "
@@ -151,8 +150,9 @@ extent_decommit_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
assert_ptr_eq(extent_hooks->decommit, extent_decommit_hook,
"Wrong hook function");
called_decommit = true;
if (!try_decommit)
if (!try_decommit) {
return (true);
}
err = default_hooks->decommit(default_hooks, addr, size, offset, length,
0);
did_decommit = !err;
@@ -161,8 +161,7 @@ extent_decommit_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
static bool
extent_purge_lazy_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
size_t offset, size_t length, unsigned arena_ind)
{
size_t offset, size_t length, unsigned arena_ind) {
bool err;
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, offset=%zu, "
@@ -173,8 +172,9 @@ extent_purge_lazy_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
assert_ptr_eq(extent_hooks->purge_lazy, extent_purge_lazy_hook,
"Wrong hook function");
called_purge_lazy = true;
if (!try_purge_lazy)
if (!try_purge_lazy) {
return (true);
}
err = default_hooks->purge_lazy == NULL ||
default_hooks->purge_lazy(default_hooks, addr, size, offset, length,
0);
@@ -184,8 +184,7 @@ extent_purge_lazy_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
static bool
extent_purge_forced_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
size_t offset, size_t length, unsigned arena_ind)
{
size_t offset, size_t length, unsigned arena_ind) {
bool err;
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, offset=%zu, "
@@ -196,8 +195,9 @@ extent_purge_forced_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
assert_ptr_eq(extent_hooks->purge_forced, extent_purge_forced_hook,
"Wrong hook function");
called_purge_forced = true;
if (!try_purge_forced)
if (!try_purge_forced) {
return (true);
}
err = default_hooks->purge_forced == NULL ||
default_hooks->purge_forced(default_hooks, addr, size, offset,
length, 0);
@@ -207,8 +207,7 @@ extent_purge_forced_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
static bool
extent_split_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
size_t size_a, size_t size_b, bool committed, unsigned arena_ind)
{
size_t size_a, size_t size_b, bool committed, unsigned arena_ind) {
bool err;
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, size_a=%zu, "
@@ -220,8 +219,9 @@ extent_split_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
assert_ptr_eq(extent_hooks->split, extent_split_hook,
"Wrong hook function");
called_split = true;
if (!try_split)
if (!try_split) {
return (true);
}
err = (default_hooks->split == NULL ||
default_hooks->split(default_hooks, addr, size, size_a, size_b,
committed, 0));
@@ -231,8 +231,7 @@ extent_split_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
static bool
extent_merge_hook(extent_hooks_t *extent_hooks, void *addr_a, size_t size_a,
void *addr_b, size_t size_b, bool committed, unsigned arena_ind)
{
void *addr_b, size_t size_b, bool committed, unsigned arena_ind) {
bool err;
TRACE_HOOK("%s(extent_hooks=%p, addr_a=%p, size_a=%zu, addr_b=%p "
@@ -244,8 +243,9 @@ extent_merge_hook(extent_hooks_t *extent_hooks, void *addr_a, size_t size_a,
assert_ptr_eq(extent_hooks->merge, extent_merge_hook,
"Wrong hook function");
called_merge = true;
if (!try_merge)
if (!try_merge) {
return (true);
}
err = (default_hooks->merge == NULL ||
default_hooks->merge(default_hooks, addr_a, size_a, addr_b, size_b,
committed, 0));
@@ -254,8 +254,7 @@ extent_merge_hook(extent_hooks_t *extent_hooks, void *addr_a, size_t size_a,
}
static void
extent_hooks_prep(void)
{
extent_hooks_prep(void) {
size_t sz;
sz = sizeof(default_hooks);

View File

@@ -159,8 +159,9 @@ static const bool config_debug =
} while (0)
#define assert_not_implemented(e) do { \
if (!(e)) \
if (!(e)) { \
not_implemented(); \
} \
} while (0)
#ifdef __cplusplus

View File

@@ -16,8 +16,7 @@ double pt_gamma(double p, double shape, double scale, double ln_gamma_shape);
* [S14]. Communications of the ACM 9(9):684.
*/
JEMALLOC_INLINE double
ln_gamma(double x)
{
ln_gamma(double x) {
double f, z;
assert(x > 0.0);
@@ -31,8 +30,9 @@ ln_gamma(double x)
}
x = z;
f = -log(f);
} else
} else {
f = 0.0;
}
z = 1.0 / (x * x);
@@ -51,8 +51,7 @@ ln_gamma(double x)
* Applied Statistics 19:285-287.
*/
JEMALLOC_INLINE double
i_gamma(double x, double p, double ln_gamma_p)
{
i_gamma(double x, double p, double ln_gamma_p) {
double acu, factor, oflo, gin, term, rn, a, b, an, dif;
double pn[6];
unsigned i;
@@ -60,8 +59,9 @@ i_gamma(double x, double p, double ln_gamma_p)
assert(p > 0.0);
assert(x >= 0.0);
if (x == 0.0)
if (x == 0.0) {
return (0.0);
}
acu = 1.0e-10;
oflo = 1.0e30;
@@ -99,8 +99,9 @@ i_gamma(double x, double p, double ln_gamma_p)
b += 2.0;
term += 1.0;
an = a * term;
for (i = 0; i < 2; i++)
for (i = 0; i < 2; i++) {
pn[i+4] = b * pn[i+2] - an * pn[i];
}
if (pn[5] != 0.0) {
rn = pn[4] / pn[5];
dif = fabs(gin - rn);
@@ -110,12 +111,14 @@ i_gamma(double x, double p, double ln_gamma_p)
}
gin = rn;
}
for (i = 0; i < 4; i++)
for (i = 0; i < 4; i++) {
pn[i] = pn[i+2];
}
if (fabs(pn[4]) >= oflo) {
for (i = 0; i < 4; i++)
for (i = 0; i < 4; i++) {
pn[i] /= oflo;
}
}
}
}
@@ -132,8 +135,7 @@ i_gamma(double x, double p, double ln_gamma_p)
* distribution. Applied Statistics 37(3):477-484.
*/
JEMALLOC_INLINE double
pt_norm(double p)
{
pt_norm(double p) {
double q, r, ret;
assert(p > 0.0 && p < 1.0);
@@ -153,10 +155,11 @@ pt_norm(double p)
r + 6.8718700749205790830e2) * r + 4.2313330701600911252e1)
* r + 1.0));
} else {
if (q < 0.0)
if (q < 0.0) {
r = p;
else
} else {
r = 1.0 - p;
}
assert(r > 0.0);
r = sqrt(-log(r));
@@ -198,8 +201,9 @@ pt_norm(double p)
5.99832206555887937690e-1)
* r + 1.0));
}
if (q < 0.0)
if (q < 0.0) {
ret = -ret;
}
return (ret);
}
}
@@ -219,8 +223,7 @@ pt_norm(double p)
* points of the Chi^2 distribution. Applied Statistics 40(1):233-235.
*/
JEMALLOC_INLINE double
pt_chi2(double p, double df, double ln_gamma_df_2)
{
pt_chi2(double p, double df, double ln_gamma_df_2) {
double e, aa, xx, c, ch, a, q, p1, p2, t, x, b, s1, s2, s3, s4, s5, s6;
unsigned i;
@@ -236,8 +239,9 @@ pt_chi2(double p, double df, double ln_gamma_df_2)
if (df < -1.24 * log(p)) {
/* Starting approximation for small Chi^2. */
ch = pow(p * xx * exp(ln_gamma_df_2 + xx * aa), 1.0 / xx);
if (ch - e < 0.0)
if (ch - e < 0.0) {
return (ch);
}
} else {
if (df > 0.32) {
x = pt_norm(p);
@@ -263,8 +267,9 @@ pt_chi2(double p, double df, double ln_gamma_df_2)
* (13.32 + 3.0 * ch)) / p2;
ch -= (1.0 - exp(a + ln_gamma_df_2 + 0.5 * ch +
c * aa) * p2 / p1) / t;
if (fabs(q / ch - 1.0) - 0.01 <= 0.0)
if (fabs(q / ch - 1.0) - 0.01 <= 0.0) {
break;
}
}
}
}
@@ -273,8 +278,9 @@ pt_chi2(double p, double df, double ln_gamma_df_2)
/* Calculation of seven-term Taylor series. */
q = ch;
p1 = 0.5 * ch;
if (p1 < 0.0)
if (p1 < 0.0) {
return (-1.0);
}
p2 = p - i_gamma(p1, xx, ln_gamma_df_2);
t = p2 * exp(xx * aa + ln_gamma_df_2 + p1 - c * log(ch));
b = t / ch;
@@ -290,8 +296,9 @@ pt_chi2(double p, double df, double ln_gamma_df_2)
s6 = (120.0 + c * (346.0 + 127.0 * c)) / 5040.0;
ch += t * (1.0 + 0.5 * t * s1 - b * c * (s1 - b * (s2 - b * (s3
- b * (s4 - b * (s5 - b * s6))))));
if (fabs(q / ch - 1.0) <= e)
if (fabs(q / ch - 1.0) <= e) {
break;
}
}
return (ch);
@@ -303,8 +310,7 @@ pt_chi2(double p, double df, double ln_gamma_df_2)
* p.
*/
JEMALLOC_INLINE double
pt_gamma(double p, double shape, double scale, double ln_gamma_shape)
{
pt_gamma(double p, double shape, double scale, double ln_gamma_shape) {
return (pt_chi2(p, shape * 2.0, ln_gamma_shape) * 0.5 * scale);
}
#endif

View File

@@ -37,20 +37,19 @@ typedef struct { \
a_attr bool \
a_prefix##init(a_mq_type *mq) { \
\
if (mtx_init(&mq->lock)) \
if (mtx_init(&mq->lock)) { \
return (true); \
} \
ql_new(&mq->msgs); \
mq->count = 0; \
return (false); \
} \
a_attr void \
a_prefix##fini(a_mq_type *mq) \
{ \
a_prefix##fini(a_mq_type *mq) { \
mtx_fini(&mq->lock); \
} \
a_attr unsigned \
a_prefix##count(a_mq_type *mq) \
{ \
a_prefix##count(a_mq_type *mq) { \
unsigned count; \
\
mtx_lock(&mq->lock); \
@@ -59,8 +58,7 @@ a_prefix##count(a_mq_type *mq) \
return (count); \
} \
a_attr a_mq_msg_type * \
a_prefix##tryget(a_mq_type *mq) \
{ \
a_prefix##tryget(a_mq_type *mq) { \
a_mq_msg_type *msg; \
\
mtx_lock(&mq->lock); \
@@ -73,32 +71,33 @@ a_prefix##tryget(a_mq_type *mq) \
return (msg); \
} \
a_attr a_mq_msg_type * \
a_prefix##get(a_mq_type *mq) \
{ \
a_prefix##get(a_mq_type *mq) { \
a_mq_msg_type *msg; \
unsigned ns; \
\
msg = a_prefix##tryget(mq); \
if (msg != NULL) \
if (msg != NULL) { \
return (msg); \
} \
\
ns = 1; \
while (true) { \
mq_nanosleep(ns); \
msg = a_prefix##tryget(mq); \
if (msg != NULL) \
if (msg != NULL) { \
return (msg); \
} \
if (ns < 1000*1000*1000) { \
/* Double sleep time, up to max 1 second. */ \
ns <<= 1; \
if (ns > 1000*1000*1000) \
if (ns > 1000*1000*1000) { \
ns = 1000*1000*1000; \
} \
} \
} \
} \
a_attr void \
a_prefix##put(a_mq_type *mq, a_mq_msg_type *msg) \
{ \
a_prefix##put(a_mq_type *mq, a_mq_msg_type *msg) { \
\
mtx_lock(&mq->lock); \
ql_elm_new(msg, a_field); \

View File

@@ -298,8 +298,7 @@ typedef void (test_t)(void);
#define TEST_BEGIN(f) \
static void \
f(void) \
{ \
f(void) { \
p_test_init(#f);
#define TEST_END \