Skip to content

Commit

Permalink
Squashed 'src/deps/miniasync/' changes from 93283586e..dd06ea790
Browse files Browse the repository at this point in the history
dd06ea790 Merge pull request pmem#54 from lplewa/vdm
9c6390dcb masync: make vdm and future header only
e23ab21b1 Merge pull request pmem#52 from wlemkows/KW-fixes
ad4651146 common: fix KW issues
bab51d2fc Merge pull request pmem#51 from DamianDuy/fixNonStandardExtensionWinWarnings
0c232c340 common: remove unnecessary wrappers for allocators
d2ca2230f Merge pull request pmem#49 from DamianDuy/fixTypeMismatchWinWarnings
a53362da8 common: fix type mismatch warnings on Windows

git-subtree-dir: src/deps/miniasync
git-subtree-split: dd06ea7907b27b8cdafaf957488e74dd1cb921a2
  • Loading branch information
lplewa committed Feb 24, 2022
1 parent 52ffd91 commit 555662f
Show file tree
Hide file tree
Showing 27 changed files with 248 additions and 320 deletions.
12 changes: 12 additions & 0 deletions examples/basic-async/basic-async.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ main(void)
struct runtime *r = runtime_new();

struct data_mover_threads *dmt = data_mover_threads_default();
if (dmt == NULL) {
fprintf(stderr, "Failed to allocate data mover.\n");
runtime_delete(r);
return 1;
}
struct vdm *vdm = data_mover_threads_get_vdm(dmt);

/*
Expand All @@ -31,6 +36,13 @@ main(void)
char *dst1 = malloc(TEST_SIZE * sizeof(char));
char *src2 = malloc(TEST_SIZE * 2 * sizeof(char));
char *dst2 = malloc(TEST_SIZE * 2 * sizeof(char));
if (src1 == NULL || dst1 == NULL ||
src2 == NULL || dst2 == NULL) {
fprintf(stderr, "Failed to allocate memory.\n");
runtime_delete(r);
data_mover_threads_delete(dmt);
return 1;
}

memset(src1, 7, TEST_SIZE);
memset(src2, 6, TEST_SIZE * 2);
Expand Down
13 changes: 13 additions & 0 deletions examples/basic/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,27 @@ main(void)
size_t otherbuf_size = strlen("otherbuf");

char *buf_a = malloc(testbuf_size + 1);
if (buf_a == NULL) {
fprintf(stderr, "Failed to create buf_a\n");
return 1;
}
char *buf_b = malloc(otherbuf_size + 1);
if (buf_b == NULL) {
fprintf(stderr, "Failed to create buf_b\n");
return 1;
}

memcpy(buf_a, "testbuf", testbuf_size + 1);
memcpy(buf_b, "otherbuf", otherbuf_size + 1);

struct runtime *r = runtime_new();

struct data_mover_threads *dmt = data_mover_threads_default();
if (dmt == NULL) {
fprintf(stderr, "Failed to allocate data mover.\n");
runtime_delete(r);
return 1;
}
struct vdm *thread_mover = data_mover_threads_get_vdm(dmt);

/*
Expand Down
1 change: 0 additions & 1 deletion extras/dml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ set(DML_SOURCES
)

set(DML_CORE_DEPS
${CORE_SOURCE_DIR}/alloc.c
${CORE_SOURCE_DIR}/cpu.c
${CORE_SOURCE_DIR}/os_posix.c
${CORE_SOURCE_DIR}/os_thread_posix.c
Expand Down
3 changes: 0 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ add_check_whitespace(src
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt)

set(SOURCES
future.c
runtime.c
vdm.c
data_mover_threads.c
data_mover_sync.c
)
Expand All @@ -39,7 +37,6 @@ else()
endif()

set(CORE_DEPS ${CORE_DEPS}
${CORE_SOURCE_DIR}/alloc.c
${CORE_SOURCE_DIR}/cpu.c
${CORE_SOURCE_DIR}/membuf.c
${CORE_SOURCE_DIR}/out.c
Expand Down
59 changes: 0 additions & 59 deletions src/core/alloc.c

This file was deleted.

41 changes: 0 additions & 41 deletions src/core/alloc.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/core/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cpuid(unsigned func, unsigned subfunc, unsigned cpuinfo[4])
static inline void
cpuid(unsigned func, unsigned subfunc, unsigned cpuinfo[4])
{
__cpuidex(cpuinfo, func, subfunc);
__cpuidex((int *)cpuinfo, (int)func, (int)subfunc);
}

#else
Expand Down
4 changes: 3 additions & 1 deletion src/core/membuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ membuf_get_threadbuf(struct membuf *membuf)
* from contained pointers to access metadata (like user_data).
*/
tbuf = util_aligned_malloc(MEMBUF_ALIGNMENT, MEMBUF_LEN);
if (tbuf == NULL)
if (tbuf == NULL) {
os_mutex_unlock(&membuf->lists_lock);
return NULL;
}

tbuf->next = membuf->tbuf_first;
membuf->tbuf_first = tbuf;
Expand Down
6 changes: 3 additions & 3 deletions src/core/os_thread_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,9 @@ void
os_cpu_set(size_t cpu, os_cpu_set_t *set)
{
internal_os_cpu_set_t *internal_set = (internal_os_cpu_set_t *)set;
int sum = 0;
int group_max = GetActiveProcessorGroupCount();
int group = 0;
size_t sum = 0;
WORD group_max = GetActiveProcessorGroupCount();
WORD group = 0;
while (group < group_max) {
sum += GetActiveProcessorCount(group);
if (sum > cpu) {
Expand Down
9 changes: 4 additions & 5 deletions src/core/os_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include <errno.h>
#include <stdlib.h>

#include "alloc.h"
#include "util.h"
#include "os.h"
#include "out.h"
Expand Down Expand Up @@ -268,7 +267,7 @@ os_mkstemp(char *temp)
return -1;
}

wchar_t *npath = Malloc(sizeof(*npath) * wcslen(path) + _MAX_FNAME);
wchar_t *npath = malloc(sizeof(*npath) * wcslen(path) + _MAX_FNAME);
if (npath == NULL) {
util_free_UTF16(utemp);
return -1;
Expand Down Expand Up @@ -299,7 +298,7 @@ os_mkstemp(char *temp)
S_IWRITE | S_IREAD);

out:
Free(npath);
free(npath);
return ret;
}

Expand Down Expand Up @@ -620,7 +619,7 @@ os_execv(const char *path, char *const argv[])
argc++;

int ret;
wchar_t **wargv = Zalloc((argc + 1) * sizeof(wargv[0]));
wchar_t **wargv = calloc(argc + 1, sizeof(wargv[0]));
if (!wargv) {
ret = -1;
goto wargv_alloc_failed;
Expand All @@ -643,7 +642,7 @@ os_execv(const char *path, char *const argv[])
end:
for (int i = 0; i < argc; ++i)
util_free_UTF16(wargv[i]);
Free(wargv);
free(wargv);

wargv_alloc_failed:
util_free_UTF16(wpath);
Expand Down
12 changes: 1 addition & 11 deletions src/core/out.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2021, Intel Corporation */
/* Copyright 2014-2022, Intel Corporation */

/*
* out.c -- support for logging, tracing, and assertion output
Expand Down Expand Up @@ -238,16 +238,6 @@ out_init(const char *log_prefix, const char *log_level_var,
"compiled with support for Valgrind drd";
LOG(1, "%s", drd_msg);
#endif /* VG_DRD_ENABLED */
#if SDS_ENABLED
static __attribute__((used)) const char *shutdown_state_msg =
"compiled with support for shutdown state";
LOG(1, "%s", shutdown_state_msg);
#endif
#if NDCTL_ENABLED
static __attribute__((used)) const char *ndctl_ge_63_msg =
"compiled with libndctl 63+";
LOG(1, "%s", ndctl_ge_63_msg);
#endif

Last_errormsg_key_alloc();
}
Expand Down
9 changes: 4 additions & 5 deletions src/core/ringbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "os.h"
#include "os_thread.h"
#include "sys_util.h"
#include "alloc.h"

#ifdef _WIN32
#define __sync_synchronize() MemoryBarrier()
Expand Down Expand Up @@ -61,18 +60,18 @@ ringbuf_new(unsigned length)
return NULL;

struct ringbuf *rbuf =
Zalloc(sizeof(*rbuf) + (length * sizeof(void *)));
calloc(length * sizeof(void *), sizeof(*rbuf));
if (rbuf == NULL)
return NULL;

if (os_semaphore_init(&rbuf->nfree, length)) {
Free(rbuf);
free(rbuf);
return NULL;
}

if (os_semaphore_init(&rbuf->nused, 0)) {
util_semaphore_destroy(&rbuf->nfree);
Free(rbuf);
free(rbuf);
return NULL;
}

Expand Down Expand Up @@ -131,7 +130,7 @@ ringbuf_delete(struct ringbuf *rbuf)
ASSERTeq(rbuf->read_pos, rbuf->write_pos);
util_semaphore_destroy(&rbuf->nfree);
util_semaphore_destroy(&rbuf->nused);
Free(rbuf);
free(rbuf);
}

/*
Expand Down
9 changes: 4 additions & 5 deletions src/core/util.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2021, Intel Corporation */
/* Copyright 2014-2022, Intel Corporation */

/*
* util.c -- very basic utilities
Expand All @@ -17,7 +17,6 @@
#include "util.h"
#include "os.h"
#include "valgrind_internal.h"
#include "alloc.h"

/* library-wide page size */
unsigned long long Pagesize;
Expand Down Expand Up @@ -485,16 +484,16 @@ util_readline(FILE *fh)

do {
char *tmp = buffer;
buffer = Realloc(buffer, bufsize);
buffer = realloc(buffer, bufsize);
if (buffer == NULL) {
Free(tmp);
free(tmp);
return NULL;
}

/* ensure if we can cast bufsize to int */
char *s = util_fgets(buffer + position, (int)bufsize / 2, fh);
if (s == NULL) {
Free(buffer);
free(buffer);
return NULL;
}

Expand Down
Loading

0 comments on commit 555662f

Please sign in to comment.