Changeset 5a9481e


Ignore:
Timestamp:
05/29/15 04:19:35 (9 years ago)
Author:
Hal Finkel <hfinkel@…>
Branches:
master
Children:
966f5de
Parents:
bdaf020
git-author:
Hal Finkel <hfinkel@…> (05/29/15 04:19:35)
git-committer:
Hal Finkel <hfinkel@…> (05/29/15 04:19:35)
Message:

obtain lock to close files, etc.; misc. rearranging

File:
1 edited

Legend:

Unmodified
Added
Removed
  • memlog.c

    r1e5cce6 r5a9481e  
    5959  in_malloc = 1; 
    6060 
     61  // Avoid any racing by obtaining the lock. 
     62  if (pthread_mutex_lock(&log_mutex)) 
     63    return; 
     64 
    6165  (void) fflush(log_file); 
    6266  (void) fclose(log_file); 
     67} 
     68 
     69// dladdr is, relatively, quit slow. For this to work on a large application, 
     70// we need to cache the lookup results. 
     71static int dladdr_cached(void *addr, Dl_info *info) { 
     72  return dladdr(addr, info); 
    6373} 
    6474 
     
    8090 
    8191  int found_caller = 0; 
    82   caller =  __builtin_extract_return_addr((void*) caller); 
    8392  for (int pci = 0; pci < num_pcs; ++pci) { 
    8493    intptr_t pc = (intptr_t) pcs[pci]; 
     
    98107    const char *file_name; 
    99108    Dl_info dlinfo; 
    100     if (dladdr((void *) pc, &dlinfo) && dlinfo.dli_fname && 
     109    if (dladdr_cached((void *) pc, &dlinfo) && dlinfo.dli_fname && 
    101110        *dlinfo.dli_fname) { 
    102111      intptr_t saddr = (intptr_t) dlinfo.dli_saddr; 
     
    181190 
    182191void *FUNC(malloc)(size_t size) { 
    183   const void *caller = __builtin_return_address(0); 
     192  const void *caller = 
     193    __builtin_extract_return_addr(__builtin_return_address(0)); 
    184194 
    185195  if (in_malloc) 
     
    197207 
    198208void *FUNC(realloc)(void *ptr, size_t size) { 
    199   const void *caller = __builtin_return_address(0); 
     209  const void *caller = 
     210    __builtin_extract_return_addr(__builtin_return_address(0)); 
    200211 
    201212  if (in_malloc) 
     
    216227 
    217228void *FUNC(calloc)(size_t nmemb, size_t size) { 
    218   const void *caller = __builtin_return_address(0); 
     229  const void *caller = 
     230    __builtin_extract_return_addr(__builtin_return_address(0)); 
    219231 
    220232  if (in_malloc) 
     
    233245 
    234246void *FUNC(memalign)(size_t boundary, size_t size) { 
    235   const void *caller = __builtin_return_address(0); 
     247  const void *caller = 
     248    __builtin_extract_return_addr(__builtin_return_address(0)); 
    236249 
    237250  if (in_malloc) 
     
    250263 
    251264void FUNC(free)(void *ptr) { 
    252   const void *caller = __builtin_return_address(0); 
     265  const void *caller = 
     266    __builtin_extract_return_addr(__builtin_return_address(0)); 
    253267 
    254268  if (in_malloc || !ptr) 
Note: See TracChangeset for help on using the changeset viewer.