Changeset 4c51931 for memlog.cpp


Ignore:
Timestamp:
06/03/15 01:17:08 (9 years ago)
Author:
Hal Finkel <hfinkel@…>
Branches:
master
Children:
3c9fc94
Parents:
ed8b809
git-author:
Hal Finkel <hfinkel@…> (06/03/15 01:17:08)
git-committer:
Hal Finkel <hfinkel@…> (06/03/15 01:17:08)
Message:

move cache from bring a local static to avoid deadlocking cxa_atexit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • memlog.cpp

    red8b809 r4c51931  
    1414 
    1515#include <limits.h> 
     16#include <errno.h> 
    1617#include <malloc.h> 
    1718#include <execinfo.h> 
     
    4041//   -Wl,--wrap,malloc,--wrap,free,--wrap,realloc,--wrap,calloc,--wrap,memalign /path/to/memlog_s.o -lpthread -ldl 
    4142 
    42 FILE *log_file = 0; 
     43static FILE *log_file = 0; 
    4344static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; 
    4445 
     
    4950 
    5051#ifdef __bgq__ 
    51 int on_bgq = 0; 
    52 #endif 
    53  
    54 void *initial_brk = 0; 
     52static int on_bgq = 0; 
     53#endif 
     54 
     55static void *initial_brk = 0; 
     56 
     57static unordered_map<void *, Dl_info> *dladdr_cache = 0; 
    5558 
    5659__attribute__((__constructor__)) 
     
    111114  (void) fflush(log_file); 
    112115  (void) fclose(log_file); 
     116 
     117  if (dladdr_cache) 
     118    delete dladdr_cache; 
    113119} 
    114120 
     
    116122// we need to cache the lookup results. 
    117123static int dladdr_cached(void * addr, Dl_info *info) { 
    118   static unordered_map<void *, Dl_info> dladdr_cache; 
    119  
    120   auto I = dladdr_cache.find(addr); 
    121   if (I == dladdr_cache.end()) { 
     124  if (!dladdr_cache) 
     125    dladdr_cache = new unordered_map<void *, Dl_info>; 
     126 
     127  auto I = dladdr_cache->find(addr); 
     128  if (I == dladdr_cache->end()) { 
    122129    int r; 
    123130    if (!(r = dladdr(addr, info))) 
    124131      memset(info, 0, sizeof(Dl_info)); 
    125132 
    126     dladdr_cache.insert(make_pair(addr, *info)); 
     133    dladdr_cache->insert(make_pair(addr, *info)); 
    127134    return r; 
    128135  } 
     
    246253 
    247254#ifdef __PIC__ 
    248 int (*__real_posix_memalign)(void **memptr, size_t alignment, size_t size) = 0; 
    249  
    250 void *(*__real_mmap)(void *addr, size_t length, int prot, int flags, 
    251                      int fd, off_t offset) = 0; 
    252 void *(*__real_mmap64)(void *addr, size_t length, int prot, int flags, 
    253                        int fd, off64_t offset) = 0; 
    254 int (*__real_munmap)(void *addr, size_t length) = 0; 
     255static int (*__real_posix_memalign)(void **memptr, size_t alignment, 
     256                                    size_t size) = 0; 
     257 
     258static void *(*__real_mmap)(void *addr, size_t length, int prot, int flags, 
     259                            int fd, off_t offset) = 0; 
     260static void *(*__real_mmap64)(void *addr, size_t length, int prot, int flags, 
     261                              int fd, off64_t offset) = 0; 
     262static int (*__real_munmap)(void *addr, size_t length) = 0; 
    255263#else 
    256264extern "C" { 
Note: See TracChangeset for help on using the changeset viewer.