Ignore:
Timestamp:
04/18/11 16:25:46 (13 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
  • test/regfi-threadtest.c

    r185 r228  
    22 * A program to stress test regfi under multithreaded use.
    33 *
    4  * Copyright (C) 2005-2010 Timothy D. Morgan
     4 * Copyright (C) 2005-2011 Timothy D. Morgan
    55 * Copyright (C) 2002 Richard Sharpe, rsharpe@richardsharpe.com
    66 *
     
    4646
    4747
    48 
    4948void traverseValueList(REGFI_ITERATOR* iter)
    5049{
    51   const REGFI_VK_REC* value;
    52 
    53   value = regfi_iterator_first_value(iter);
    54   while(value != NULL)
    55   {
     50  const REGFI_VK* value;
     51  bool ret;
     52
     53  for(ret=regfi_iterator_first_value(iter);
     54      ret;
     55      ret=regfi_iterator_next_value(iter))
     56  {
     57    value = regfi_iterator_cur_value(iter);
    5658    printMsgs(iter->f);
    5759    regfi_free_record(value);
    58     value = regfi_iterator_next_value(iter);
    5960  }
    6061}
     
    6364void traverseKeyTree(REGFI_ITERATOR* iter)
    6465{
    65   const REGFI_NK_REC* root = NULL;
    66   const REGFI_NK_REC* cur = NULL;
    67   const REGFI_NK_REC* sub = NULL;
    68   const REGFI_SK_REC* sk;
     66  const REGFI_NK* root = NULL;
     67  const REGFI_NK* cur = NULL;
     68  const REGFI_NK* sub = NULL;
     69  const REGFI_SK* sk;
    6970  bool print_this = true;
    7071
    7172  root = cur = regfi_iterator_cur_key(iter);
    72   sub = regfi_iterator_first_subkey(iter);
     73  regfi_iterator_first_subkey(iter);
     74  sub = regfi_iterator_cur_subkey(iter);
    7375  printMsgs(iter->f);
    7476
     
    8688      {
    8789        /* We're done with this sub-tree, going up and hitting other branches. */
     90        regfi_free_record(cur);
    8891        if(!regfi_iterator_up(iter))
    8992        {
     
    9598        /*      fprintf(stderr, "%s\n", cur->keyname);*/
    9699        printMsgs(iter->f);
    97         sk = regfi_iterator_cur_sk(iter);
    98         printMsgs(iter->f);
    99100        if(cur == NULL)
    100101          bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: unexpected NULL for key.\n");
    101      
    102         sub = regfi_iterator_next_subkey(iter);
     102        sk = regfi_fetch_sk(iter->f, cur);
     103        printMsgs(iter->f);
     104        regfi_free_record(sk);
     105
     106        regfi_iterator_next_subkey(iter);
     107        sub = regfi_iterator_cur_subkey(iter);
    103108      }
    104109      print_this = false;
     
    108113       * Let's move down and print this first sub-tree out.
    109114       */
     115      regfi_free_record(cur);
    110116      if(!regfi_iterator_down(iter))
    111117      {
     
    118124      regfi_free_record(sub);
    119125
    120       sub = regfi_iterator_first_subkey(iter);
     126      regfi_iterator_first_subkey(iter);
     127      sub = regfi_iterator_cur_subkey(iter);
    121128      printMsgs(iter->f);
    122129      print_this = true;
     
    124131    printMsgs(iter->f);
    125132  } while(!((cur == root) && (sub == NULL)));
     133  regfi_free_record(root);
    126134
    127135  if(print_verbose)
     
    138146  regfi_log_set_mask(REGFI_LOG_INFO|REGFI_LOG_WARN|REGFI_LOG_ERROR);
    139147
    140   iter = regfi_iterator_new((REGFI_FILE*)f, REGFI_ENCODING_ASCII);
     148  iter = regfi_iterator_new((REGFI_FILE*)f);
    141149  if(iter == NULL)
    142150  {
     
    198206  }
    199207
    200   f = regfi_alloc(fd);
     208  f = regfi_alloc(fd, REGFI_ENCODING_ASCII);
    201209  if(f == NULL)
    202210  {
     
    214222    pthread_join(threads[i], NULL);
    215223
     224  free(threads);
    216225  regfi_free(f);
    217226  close(fd);
Note: See TracChangeset for help on using the changeset viewer.