Skip to content

Commit

Permalink
MacPmem now uses binary search instead of a bitmap for rw safety.
Browse files Browse the repository at this point in the history
- pmem_debug is no longer compiled into production builds by default.

BUG=
R=scudette@gmail.com

Review URL: https://codereview.appspot.com/260820043.
  • Loading branch information
the80srobot committed Aug 18, 2015
1 parent cd2e373 commit 40399fd
Show file tree
Hide file tree
Showing 15 changed files with 4,357 additions and 504 deletions.
30 changes: 24 additions & 6 deletions tools/osx/MacPmem/Common/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,38 @@
// actually set by MacPmem.c.
extern OSMallocTag pmem_alloc_tag;

// Allocate memory of 'size', as a void pointer.
#define PMEM_ALLOC(size) ((void *)OSMalloc((size), pmem_alloc_tag))
// Allocate memory of 'size', as a void pointer. Returns zeroed memory.
static inline void *PMEM_ALLOC(uint32_t size) {
void *result = OSMalloc(size, pmem_alloc_tag);
if (result) {
bzero(result, size);
}

return result;
}

// Free memory at void *ptr of 'size' bytes in total. The 'size' must be the
// same as what was passed to create this allocation with PMEM_ALLOC.
#define PMEM_FREE(ptr, size) OSFree((char *)(ptr), (size), pmem_alloc_tag)
static inline void PMEM_FREE(void *ptr, uint32_t size) {
OSFree(ptr, size, pmem_alloc_tag);
}

#else /* ifdef KERNEL */

#include <stdlib.h>

#define PMEM_ALLOC(size) malloc((size))
#define PMEM_FREE(ptr, size) free((ptr))
static inline void *PMEM_ALLOC(uint32_t size) {
void *result = malloc(size);
if (result) {
bzero(result, size);
}

return result;
}

static inline void PMEM_FREE(void *ptr, __unused uint32_t size) {
free(ptr);
}

#endif

Expand Down Expand Up @@ -76,7 +95,6 @@ static inline void *pmem_realloc(void *ptr, unsigned size, unsigned newsize) {
return 0;
}

bzero(newmem, newsize);
memcpy(newmem, ptr, size);
PMEM_FREE(ptr, size);

Expand Down
186 changes: 0 additions & 186 deletions tools/osx/MacPmem/Common/bitmap.c

This file was deleted.

97 changes: 0 additions & 97 deletions tools/osx/MacPmem/Common/bitmap.h

This file was deleted.

5 changes: 5 additions & 0 deletions tools/osx/MacPmem/Common/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ typedef enum {
kPmemFatal = 0,
} PmemLogLevel;

// FYI: for production builds, calls to pmem_debug are not compiled at all.
extern int pmem_logging_level;

#ifdef __cplusplus
Expand All @@ -52,7 +53,11 @@ extern "C" {
void pmem_log(PmemLogLevel lvl, const char *fmt, ...) __printflike(2, 3);
void pmem_logv(PmemLogLevel lvl, const char *fmt, va_list args);

#ifdef DEBUG
void pmem_debug(const char *fmt, ...) __printflike(1, 2);
#else
#define pmem_debug(fmt, args...)
#endif
void pmem_info(const char *fmt, ...) __printflike(1, 2);
void pmem_warn(const char * fmt, ...) __printflike(1, 2);
void pmem_error(const char *fmt, ...) __printflike(1, 2);
Expand Down
Loading

0 comments on commit 40399fd

Please sign in to comment.