Skip to content

Commit

Permalink
Merge pull request #301 from Tarsnap/libcperciva-import
Browse files Browse the repository at this point in the history
Libcperciva import and fix whitespace
  • Loading branch information
cperciva authored Dec 20, 2024
2 parents 57f5be4 + af901b2 commit 1e7e002
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lbs-dynamodb-init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ request(const char * key_id, const char * key_secret, const char * region,

/* Send the request and wait for it to complete. */
C.done = 0;
if (dynamodb_request(sas_ddb, key_id, key_secret, region, reqtype,
(const uint8_t *)req, strlen(req), 4096,
callback_reqdone, &C) == NULL) {
if (dynamodb_request(sas_ddb, key_id, key_secret, region, reqtype,
(const uint8_t *)req, strlen(req), 4096,
callback_reqdone, &C) == NULL) {
warnp("Failure sending DynamoDB request");
goto err0;
}
Expand Down
2 changes: 1 addition & 1 deletion libcperciva/alg/sha256_sse2.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mm_bswap_epi32(__m128i a)
{

/* Swap bytes in each 16-bit word. */
a = _mm_or_si128(_mm_slli_epi16(a, 8), _mm_srli_epi16(a, 8));
a = _mm_or_si128(_mm_slli_epi16(a, 8), _mm_srli_epi16(a, 8));

/* Swap all 16-bit words. */
a = _mm_shufflelo_epi16(a, _MM_SHUFFLE(2, 3, 0, 1));
Expand Down
21 changes: 21 additions & 0 deletions libcperciva/datastruct/mpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ static inline void
mpool_atexit(struct mpool * M)
{

/* Free all items on the stack. */
while (M->stacklen)
free(M->allocs[--M->stacklen]);

/* If we allocated a stack, free it. */
if (M->allocs != M->allocs_static)
free(M->allocs);
}
Expand All @@ -43,14 +46,23 @@ static inline void *
mpool_malloc(struct mpool * M, size_t len)
{

/* Count the total number of allocation requests. */
M->nallocs++;

/* If we have an object on the stack, use that. */
if (M->stacklen)
return (M->allocs[--(M->stacklen)]);

/* Count allocation requests where the pool was already empty. */
M->nempties++;

/* Initialize the atexit function (the first time we reach here). */
if (M->state == 0) {
atexit(M->atexitfunc);
M->state = 1;
}

/* Allocate a new object. */
return (malloc(len));
}

Expand All @@ -59,18 +71,25 @@ mpool_free(struct mpool * M, void * p)
{
void ** allocs_new;

/* Behave consistently with free(NULL). */
if (p == NULL)
return;

/* If we have space in the stack, cache the object. */
if (M->stacklen < M->allocsize) {
M->allocs[M->stacklen++] = p;
return;
}

/*
* Autotuning: If more than 1/256 of mpool_malloc() calls resulted in
* a malloc(), double the stack.
*/
if (M->nempties > (M->nallocs >> 8)) {
/* Sanity check. */
assert(M->allocsize > 0);

/* Allocate new stack and copy pointers into it. */
allocs_new = (void **)malloc(M->allocsize * 2 * sizeof(void *));
if (allocs_new) {
memcpy(allocs_new, M->allocs,
Expand All @@ -84,6 +103,8 @@ mpool_free(struct mpool * M, void * p)
free(p);
} else
free(p);

/* Reset statistics. */
M->nempties = 0;
M->nallocs = 0;
}
Expand Down
7 changes: 7 additions & 0 deletions libcperciva/http/https_internal.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#ifndef HTTPS_INTERNAL_H_
#define HTTPS_INTERNAL_H_

#include <stddef.h>

/* Forward definitions. */
struct http_request;
struct http_response;
struct sock_addr;

/*
* Function pointers defined in http.c; we set them from https_request in
* order to avoid requiring unencrypted HTTP code to link to libssl.
Expand Down
2 changes: 1 addition & 1 deletion libcperciva/netbuf/netbuf_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void
netbuf_read_free(struct netbuf_read * R)
{

/* Behave consistently with free(NULL). */
/* Behave consistently with free(NULL). */
if (R == NULL)
return;

Expand Down
2 changes: 1 addition & 1 deletion libcperciva/netbuf/netbuf_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ netbuf_write_free(struct netbuf_write * W)
{
struct writebuf * WB;

/* Behave consistently with free(NULL). */
/* Behave consistently with free(NULL). */
if (W == NULL)
return;

Expand Down
2 changes: 1 addition & 1 deletion perf/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ main(int argc, char * argv[])

/* Close and free the connection. */
dispatch_done(dstate);
} while (opt_1 == 0);
} while (opt_1 == 0);

/* Output and free performance tracking state */
perfstats_done(P);
Expand Down

0 comments on commit 1e7e002

Please sign in to comment.