small fixes required by use of lib codebase at work

This was SVN commit r5796.
This commit is contained in:
janwas 2008-03-29 18:29:26 +00:00
parent 74a820c2e8
commit a9fcc1a87c
7 changed files with 32 additions and 35 deletions

View File

@ -10,7 +10,7 @@ PageAlignedDeleter::PageAlignedDeleter(size_t size)
debug_assert(m_size != 0);
}
void PageAlignedDeleter::operator()(u8* p)
void PageAlignedDeleter::operator()(void* p)
{
debug_assert(m_size != 0);
page_aligned_free(p, m_size);

View File

@ -2,11 +2,11 @@
#define INCLUDED_SHARED_PTR
// adapter that allows calling page_aligned_free as a shared_ptr deleter.
class PageAlignedDeleter
class LIB_API PageAlignedDeleter
{
public:
PageAlignedDeleter(size_t size);
void operator()(u8* p);
void operator()(void* p);
private:
size_t m_size;

View File

@ -9,21 +9,13 @@
// license: GPL; see lib/license.txt
#include "precompiled.h"
#include "bits.h"
#if ARCH_IA32
# include "lib/sysdep/ia32/ia32_asm.h" // ia32_asm_log2_of_pow2
#endif
bool is_pow2(uint n)
{
// 0 would pass the test below but isn't a POT.
if(n == 0)
return false;
return (n & (n-1ul)) == 0;
}
int log2_of_pow2(uint n)
{
int bit_index;
@ -48,20 +40,6 @@ int log2_of_pow2(uint n)
}
uint ceil_log2(uint x)
{
uint bit = 1;
uint l = 0;
while(bit < x && bit != 0) // must detect overflow
{
l++;
bit += bit;
}
return l;
}
int floor_log2(const float x)
{
const u32 i = *(u32*)&x;
@ -70,10 +48,6 @@ int floor_log2(const float x)
}
// round_up_to_pow2 implementation assumes 32-bit int.
// if 64, add "x |= (x >> 32);"
cassert(sizeof(int)*CHAR_BIT == 32);
uint round_up_to_pow2(uint x)
{
// fold upper bit into lower bits; leaves same MSB set but
@ -83,6 +57,9 @@ uint round_up_to_pow2(uint x)
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
// if ints are 64 bits, add "x |= (x >> 32);"
cassert(sizeof(int)*CHAR_BIT == 32);
return x+1;
}

View File

@ -75,7 +75,14 @@ inline u64 bits64(u64 num, uint lo_idx, uint hi_idx)
/**
* @return whether the given number is a power of two.
**/
extern bool is_pow2(uint n);
inline bool is_pow2(uint n)
{
// 0 would pass the test below but isn't a POT.
if(n == 0)
return false;
return (n & (n-1ul)) == 0;
}
/**
* @return the (integral) base 2 logarithm, or -1 if the number
@ -89,7 +96,19 @@ extern int log2_of_pow2(uint n);
* @param n (integer) input; MUST be > 0, else results are undefined.
* @return ceiling of the base-2 logarithm (i.e. rounded up).
**/
extern uint ceil_log2(uint x);
inline uint ceil_log2(uint x)
{
uint bit = 1;
uint l = 0;
while(bit < x && bit != 0) // must detect overflow
{
l++;
bit += bit;
}
return l;
}
/**
* floor(log2(f))

View File

@ -16,7 +16,7 @@
// memory will be allocated from the heap, not the (limited) file cache.
// this makes sense for write buffers that are never used again,
// because we avoid having to displace some other cached items.
shared_ptr<u8> io_Allocate(size_t size, off_t ofs = 0);
LIB_API shared_ptr<u8> io_Allocate(size_t size, off_t ofs = 0);
/**
* called after a block IO has completed.

View File

@ -134,6 +134,7 @@ void debug_set_thread_name(const char* name)
__except(EXCEPTION_EXECUTE_HANDLER)
{
// if we get here, the debugger didn't handle the exception.
debug_assert(0); // thread name hack doesn't work under this debugger
// this happens if profiling with Dependency Walker; debug_assert
// must not be called because we may be in critical init.
}
}

View File

@ -260,7 +260,7 @@ static LibError ia32_walk_stack(_tagSTACKFRAME64* sf)
if(!debug_is_stack_ptr(fp))
WARN_RETURN(ERR::_14);
if(!debug_is_code_ptr(ret_addr))
WARN_RETURN(ERR::_15);
return ERR::FAIL; // NOWARN (invalid address)
void* target;
LibError err = ia32_GetCallTarget(ret_addr, &target);