Skip to content

Commit

Permalink
some fix
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanocasazza committed Dec 9, 2015
1 parent 83573aa commit a4043a7
Show file tree
Hide file tree
Showing 16 changed files with 1,123 additions and 865 deletions.
10 changes: 0 additions & 10 deletions include/ulib/event/event_time.h
Expand Up @@ -126,16 +126,6 @@ class U_EXPORT UEventTime : public UTimeVal {
UTimeVal::setMilliSecond(ms = timeoutMS);
}

void setMilliSecond()
{
U_TRACE_NO_PARAM(0, "UEventTime::setMilliSecond()")

ms = ((ctime.tv_sec + tv_sec - timeout1.tv_sec) * 1000L) +
((ctime.tv_usec + tv_usec - timeout1.tv_usec) / 1000L);

U_ASSERT(checkTolerance())
}

bool checkMilliSecond() const
{
U_TRACE_NO_PARAM(0, "UEventTime::checkMilliSecond()")
Expand Down
13 changes: 7 additions & 6 deletions include/ulib/file.h
Expand Up @@ -852,8 +852,8 @@ class U_EXPORT UFile : public stat {
bool write(const struct iovec* iov, int n, bool append = false, bool bmkdirs = false);
bool write(const UString& data, bool append = false, bool bmkdirs = false) { return write(U_STRING_TO_PARAM(data), append, bmkdirs); }

static int setSysParam( const char* name, int value, bool force = false);
static int getSysParam( const char* name);
static long setSysParam( const char* name, long value, bool force = false);
static long getSysParam( const char* name);
static UString getSysContent(const char* name);

static bool writeToTmp(const char* data, uint32_t sz, bool append, const char* fmt, ...);
Expand Down Expand Up @@ -950,7 +950,7 @@ class U_EXPORT UFile : public stat {
# if defined(U_LINUX) && defined(U_MEMALLOC_WITH_HUGE_PAGE) && (defined(MAP_HUGE_1GB) || defined(MAP_HUGE_2MB)) // (since Linux 3.8)
if (nr_hugepages)
{
U_INTERNAL_DUMP("nr_hugepages = %u rlimit_memfree = %u", nr_hugepages, rlimit_memfree)
U_INTERNAL_DUMP("nr_hugepages = %ld rlimit_memfree = %u", nr_hugepages, rlimit_memfree)

U_INTERNAL_ASSERT_EQUALS(rlimit_memfree, U_2M)

Expand All @@ -973,7 +973,7 @@ class U_EXPORT UFile : public stat {
# if defined(U_LINUX) && defined(U_MEMALLOC_WITH_HUGE_PAGE) && (defined(MAP_HUGE_1GB) || defined(MAP_HUGE_2MB)) // (since Linux 3.8)
if (nr_hugepages)
{
U_INTERNAL_DUMP("nr_hugepages = %u rlimit_memfree = %u", nr_hugepages, rlimit_memfree)
U_INTERNAL_DUMP("nr_hugepages = %ld rlimit_memfree = %u", nr_hugepages, rlimit_memfree)

U_INTERNAL_ASSERT_EQUALS(rlimit_memfree, U_2M)

Expand Down Expand Up @@ -1067,8 +1067,9 @@ class U_EXPORT UFile : public stat {
static char* cwd_save;
static uint32_t cwd_save_len;

static char* pfree;
static uint32_t nfree, rlimit_memfree, rlimit_memalloc, nr_hugepages;
static char* pfree;
static long nr_hugepages;
static uint32_t nfree, rlimit_memfree, rlimit_memalloc;

void substitute(UFile& file);
bool creatForWrite(bool append, bool bmkdirs);
Expand Down
10 changes: 6 additions & 4 deletions include/ulib/string.h
Expand Up @@ -1283,6 +1283,8 @@ class U_EXPORT UString {
{
U_TRACE(0, "UString::substr(%.*S,%u)", tlen, t, tlen)

if (tlen == 0) return *string_null;

UString result(rep, t, tlen);

U_RETURN_STRING(result);
Expand Down Expand Up @@ -1398,7 +1400,7 @@ class U_EXPORT UString {
void swap(UString& lhs, UString& rhs) { lhs.swap(rhs); }

#ifdef U_COMPILER_RVALUE_REFS
# if defined(DEBUG) || !defined(__GNUC__) // || GCC_VERSION_NUM >= 60000 // hope
# if !defined(__GNUC__) // || GCC_VERSION_NUM >= 60000 // hope
UString(UString && str)
{
U_TRACE_NO_PARAM(0, "UString::UString(move)")
Expand Down Expand Up @@ -1562,9 +1564,9 @@ class U_EXPORT UString {

// operator +

friend UString operator+(const UString& lhs, const char* rhs) { UString str(lhs); (void) str.append(rhs, u__strlen(rhs, __PRETTY_FUNCTION__)); return str; }
friend UString operator+(const UString& lhs, char rhs) { UString str(lhs); (void) str.append(1U, rhs); return str; }
friend UString operator+(const UString& lhs, const UString& rhs) { UString str(lhs); (void) str.append(rhs); return str; }
friend UString operator+(const UString& lhs, const char* rhs);
friend UString operator+(const UString& lhs, char rhs);
friend UString operator+(const UString& lhs, const UString& rhs);
friend UString operator+(char lhs, const UString& rhs);
friend UString operator+(const char* lhs, const UString& rhs);

Expand Down
2 changes: 1 addition & 1 deletion include/ulib/tokenizer.h
Expand Up @@ -184,7 +184,7 @@ class U_EXPORT UTokenizer {
}

UString getTokenQueryParser();
int getTokenId(UString& token);
int getTokenId(UString* ptoken);
bool tokenSeen(const UString* x);

bool skipNumber(bool& isReal);
Expand Down
66 changes: 43 additions & 23 deletions src/ulib/file.cpp
Expand Up @@ -24,8 +24,8 @@

char* UFile::cwd_save;
char* UFile::pfree;
long UFile::nr_hugepages;
uint32_t UFile::nfree;
uint32_t UFile::nr_hugepages;
uint32_t UFile::cwd_save_len;

#if defined(U_LINUX) && (defined(MAP_HUGE_1GB) || defined(MAP_HUGE_2MB)) // (since Linux 3.8)
Expand Down Expand Up @@ -482,7 +482,7 @@ char* UFile::mmap_anon_huge(uint32_t* plength, int flags)
char* ptr;
uint32_t length;

U_INTERNAL_DUMP("nr_hugepages = %u rlimit_memfree = %u", nr_hugepages, rlimit_memfree)
U_INTERNAL_DUMP("nr_hugepages = %ld rlimit_memfree = %u", nr_hugepages, rlimit_memfree)

U_INTERNAL_ASSERT_EQUALS(rlimit_memfree, U_2M)

Expand Down Expand Up @@ -527,11 +527,13 @@ char* UFile::mmap_anon_huge(uint32_t* plength, int flags)

u_get_memusage(&vsz, &rss);

U_ERROR("cannot allocate %u bytes (%u MB) of memory MAP_HUGE_2MB - "
"address space usage: %.2f MBytes - "
"rss usage: %.2f MBytes",
*plength, *plength / (1024U*1024U), (double)vsz / (1024.0 * 1024.0),
(double)rss / (1024.0 * 1024.0));
U_WARNING("cannot allocate %u bytes (%u MB) of memory MAP_HUGE_2MB - "
"address space usage: %.2f MBytes - "
"rss usage: %.2f MBytes",
*plength, *plength / (1024U*1024U), (double)vsz / (1024.0 * 1024.0),
(double)rss / (1024.0 * 1024.0));

nr_hugepages = 0;
}
# endif
}
Expand Down Expand Up @@ -589,14 +591,13 @@ char* UFile::mmap(uint32_t* plength, int _fd, int prot, int flags, uint32_t offs
{
U_DEBUG("we are going to allocate from file system (%u KB - %u bytes)", *plength / 1024, *plength);

if (fallocate(fd, *plength))
{
_ptr = (char*)U_SYSCALL(mmap, "%d,%u,%d,%d,%d,%u", 0, *plength, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_NORESERVE, fd, 0);

if (_ptr != (char*)MAP_FAILED) return _ptr;
}
_ptr = (fallocate(fd, *plength)
? (char*)U_SYSCALL(mmap, "%d,%u,%d,%d,%d,%u", 0, *plength, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_NORESERVE, fd, 0)
: (char*)MAP_FAILED);

close(fd);

if (_ptr != (char*)MAP_FAILED) return _ptr;
}

if (_abort)
Expand Down Expand Up @@ -1219,46 +1220,65 @@ UString UFile::getSysContent(const char* name)
U_RETURN_STRING(fileContent);
}

int UFile::getSysParam(const char* name)
long UFile::getSysParam(const char* name)
{
U_TRACE(0, "UFile::getSysParam(%S)", name)

int value = -1,
fd = open(name, O_RDONLY, PERM_FILE);
long value = -1;
int fd = open(name, O_RDONLY, PERM_FILE);

if (fd != -1)
{
char buffer[32];

if (U_SYSCALL(read, "%d,%p,%u", fd, buffer, sizeof(buffer)-1) > 0) value = strtol(buffer, 0, 10);
ssize_t bytes_read = U_SYSCALL(read, "%d,%p,%u", fd, buffer, sizeof(buffer)-1);

if (bytes_read > 0)
{
U_INTERNAL_ASSERT_MINOR((uint32_t)bytes_read, sizeof(buffer))

buffer[bytes_read] = '\0';

value = strtol(buffer, 0, 10);
}

close(fd);
}

U_RETURN(value);
}

int UFile::setSysParam(const char* name, int value, bool force)
long UFile::setSysParam(const char* name, long value, bool force)
{
U_TRACE(0, "UFile::setSysParam(%S,%u,%b)", name, value, force)
U_TRACE(0, "UFile::setSysParam(%S,%ld,%b)", name, value, force)

int old_value = -1,
fd = open(name, O_RDWR, PERM_FILE);
long old_value = -1;
int fd = open(name, O_RDWR, PERM_FILE);

if (fd != -1)
{
char buffer[32];

if (U_SYSCALL(read, "%d,%p,%u", fd, buffer, sizeof(buffer)-1) > 0)
ssize_t bytes_read = U_SYSCALL(read, "%d,%p,%u", fd, buffer, sizeof(buffer)-1);

if (bytes_read > 0)
{
U_INTERNAL_ASSERT_MINOR((uint32_t)bytes_read, sizeof(buffer))

buffer[bytes_read] = '\0';

old_value = strtol(buffer, 0, 10);

if (force ||
old_value < value)
{
char* ptr = buffer;

# if SIZEOF_LONG == 4
if (pwrite(fd, buffer, u_num2str32s(ptr, value), 0) > 0) old_value = value;
# else
if (pwrite(fd, buffer, u_num2str64s(ptr, value), 0) > 0) old_value = value;
# endif
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ulib/internal/memory_pool.cpp
Expand Up @@ -619,7 +619,7 @@ void UMemoryPool::deallocate(void* ptr, uint32_t length)

# if defined(U_LINUX) && defined(HAVE_ARCH64)
# if defined(MAP_HUGE_1GB) || defined(MAP_HUGE_2MB) // (since Linux 3.8)
U_INTERNAL_DUMP("UFile::nr_hugepages = %u", UFile::nr_hugepages)
U_INTERNAL_DUMP("UFile::nr_hugepages = %ld", UFile::nr_hugepages)

if (UFile::nr_hugepages == 0) // NB: MADV_DONTNEED cannot be applied to locked pages, Huge TLB pages, or VM_PFNMAP pages...
# endif
Expand Down

0 comments on commit a4043a7

Please sign in to comment.