IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18732


Ignore:
Timestamp:
Jul 24, 2008, 5:10:43 PM (18 years ago)
Author:
eugene
Message:

add additional mutex locks to avoid conflicts on Nvariables

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/lib.shell/VariableOps.c

    r17419 r18732  
    129129  ALLOCATE (local, char, strlen(name) + strlen(MacroName) + 2);
    130130  sprintf (local, "%s.%s", MacroName, name);
     131
     132  /* need to use a mutex to prevent another thread from misleading on size of Nvariables */
     133  pthread_mutex_lock (&mutex);
     134
    131135  for (i = 0; i < Nvariables; i++) { /* find the variable mentioned */
    132136    if (!strcmp(local, variables[i].name)) {
     137      pthread_mutex_unlock (&mutex);
    133138      free (local);
    134139      return (variables[i].value);
    135140    }
    136141  }
     142  pthread_mutex_unlock (&mutex);
    137143  free (local);
    138144  return (NULL);
     
    161167  if (local != NULL) return (local);
    162168
     169  /* need to use a mutex to prevent another thread from misleading on size of Nvariables */
     170  pthread_mutex_lock (&mutex);
     171
    163172  /* look for global variable */
    164173  for (i = 0; i < Nvariables; i++) { /* find the variable mentioned */
    165174    if (!strcmp(name, variables[i].name)) {
     175      pthread_mutex_unlock (&mutex);
    166176      return (variables[i].value);
    167177    }
    168178  }
     179  pthread_mutex_unlock (&mutex);
    169180  return (NULL);
    170181}
     
    238249
    239250  int i, j;
     251
     252  /* need to use a mutex to prevent two threads from simultaneously modifying Nvariables */
     253  pthread_mutex_lock (&mutex);
    240254
    241255  for (i = 0; i < Nvariables; i++) {
     
    248262      Nvariables --;
    249263      REALLOCATE (variables, Variable, MAX (Nvariables, 1));
    250       return (TRUE);
    251     }
    252   }
     264      pthread_mutex_unlock (&mutex);
     265      return (TRUE);
     266    }
     267  }
     268  pthread_mutex_unlock (&mutex);
    253269  return (FALSE);
    254270}
     
    258274  int i;
    259275
    260   for (i = 0; i < Nvariables; i++) {
    261     if (!strcmp (name, variables[i].name)) return (TRUE);
    262   }
     276  /* need to use a mutex to prevent another thread from misleading on size of Nvariables */
     277  pthread_mutex_lock (&mutex);
     278
     279  for (i = 0; i < Nvariables; i++) {
     280    if (!strcmp (name, variables[i].name)) {
     281      pthread_mutex_unlock (&mutex);
     282      return (TRUE);
     283    }
     284  }
     285  pthread_mutex_unlock (&mutex);
    263286  return (FALSE);
    264287}
     
    273296  }
    274297
     298  /* need to use a mutex to prevent another thread from misleading on size of Nvariables */
     299  pthread_mutex_lock (&mutex);
     300
    275301  for (i = 0; i < Nvariables; i++) {
    276302    gprint (GP_ERR, "%s = %s\n", variables[i].name, variables[i].value);
    277303  }
     304
     305  pthread_mutex_unlock (&mutex);
    278306  return;
    279307}
Note: See TracChangeset for help on using the changeset viewer.