Changeset 228 for trunk/lib


Ignore:
Timestamp:
04/18/11 16:25:46 (14 years ago)
Author:
tim
Message:

added a test case for pyregfi multithreaded use
updated the regfi multithreaded test case
fixed several ctypes interface problems in pyregfi
added locking to pyregfi iterators for thread safety
fixed regfi talloc race conditions with an additional lock

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/regfi.c

    r226 r228  
    16171617  }
    16181618
     1619  if(pthread_mutex_init(&rb->mem_lock, NULL) != 0)
     1620  {
     1621    regfi_log_add(REGFI_LOG_ERROR, "Failed to create mem_lock mutex.");
     1622    goto fail;
     1623  }
     1624
    16191625  rb->hbins = range_list_new();
    16201626  if(rb->hbins == NULL)
     
    16571663  pthread_rwlock_destroy(&rb->hbins_lock);
    16581664  pthread_mutex_destroy(&rb->sk_lock);
     1665  pthread_mutex_destroy(&rb->mem_lock);
    16591666
    16601667  range_list_free(rb->hbins);
     
    17211728/******************************************************************************
    17221729 *****************************************************************************/
    1723 void regfi_free_record(const void* record)
    1724 {
     1730void regfi_free_record(REGFI_FILE* file, const void* record)
     1731{
     1732  if(!regfi_lock(file, &file->mem_lock, "regfi_free_record"))
     1733    return;
     1734
    17251735  talloc_unlink(NULL, (void*)record);
     1736
     1737  regfi_unlock(file, &file->mem_lock, "regfi_free_record");
    17261738}
    17271739
     
    17291741/******************************************************************************
    17301742 *****************************************************************************/
    1731 bool regfi_reference_record(const void* record)
    1732 {
     1743bool regfi_reference_record(REGFI_FILE* file, const void* record)
     1744{
     1745  bool ret_val = false;
     1746  if(!regfi_lock(file, &file->mem_lock, "regfi_reference_record"))
     1747    return ret_val;
     1748 
    17331749  if(talloc_reference(NULL, record) != NULL)
    1734     return true;
    1735   return false;
     1750    ret_val = true;
     1751
     1752  regfi_unlock(file, &file->mem_lock, "regfi_reference_record");
     1753  return ret_val;
    17361754}
    17371755
     
    18231841void regfi_iterator_free(REGFI_ITERATOR* i)
    18241842{
    1825   talloc_free(i);
     1843  talloc_unlink(NULL, i);
    18261844}
    18271845
     
    18541872    talloc_unlink(NULL, subkey);
    18551873    return false;
    1856   }
     1874  } 
    18571875  talloc_reparent(NULL, i, subkey);
    18581876
     
    18751893    return false;
    18761894
     1895  if(!regfi_lock(i->f, &i->f->mem_lock, "regfi_iterator_up"))
     1896    return false;
     1897 
    18771898  talloc_unlink(i, i->cur_key);
     1899  regfi_unlock(i->f, &i->f->mem_lock, "regfi_iterator_up");
     1900
    18781901  i->cur_key = pos->nk;
    18791902  i->cur_subkey = pos->cur_subkey;
     
    19431966const REGFI_NK* regfi_iterator_cur_key(REGFI_ITERATOR* i)
    19441967{
    1945   return talloc_reference(NULL, i->cur_key);
     1968  const REGFI_NK* ret_val = NULL;
     1969  if(!regfi_lock(i->f, &i->f->mem_lock, "regfi_iterator_cur_key"))
     1970    return ret_val;
     1971
     1972  ret_val = talloc_reference(NULL, i->cur_key);
     1973
     1974  regfi_unlock(i->f, &i->f->mem_lock, "regfi_iterator_cur_key"); 
     1975  return ret_val;
    19461976}
    19471977
     
    21742204    }
    21752205
    2176     regfi_free_record(cur);
     2206    regfi_free_record(file, cur);
    21772207  }
    21782208
     
    22112241    }
    22122242
    2213     regfi_free_record(cur);
     2243    regfi_free_record(file, cur);
    22142244  }
    22152245
     
    22572287{
    22582288  if(key != NULL && key->parent_off != REGFI_OFFSET_NONE)
    2259   {
    2260     /*    fprintf(stderr, "key->parent_off=%.8X\n", key->parent_off);*/
    22612289    return regfi_load_key(file,
    22622290                          key->parent_off+REGFI_REGF_SIZE,
    22632291                          file->string_encoding, true);
    2264   }
    2265  
     2292
    22662293  return NULL;
    22672294}
Note: See TracChangeset for help on using the changeset viewer.