Changeset 18732
- Timestamp:
- Jul 24, 2008, 5:10:43 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/lib.shell/VariableOps.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/VariableOps.c
r17419 r18732 129 129 ALLOCATE (local, char, strlen(name) + strlen(MacroName) + 2); 130 130 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 131 135 for (i = 0; i < Nvariables; i++) { /* find the variable mentioned */ 132 136 if (!strcmp(local, variables[i].name)) { 137 pthread_mutex_unlock (&mutex); 133 138 free (local); 134 139 return (variables[i].value); 135 140 } 136 141 } 142 pthread_mutex_unlock (&mutex); 137 143 free (local); 138 144 return (NULL); … … 161 167 if (local != NULL) return (local); 162 168 169 /* need to use a mutex to prevent another thread from misleading on size of Nvariables */ 170 pthread_mutex_lock (&mutex); 171 163 172 /* look for global variable */ 164 173 for (i = 0; i < Nvariables; i++) { /* find the variable mentioned */ 165 174 if (!strcmp(name, variables[i].name)) { 175 pthread_mutex_unlock (&mutex); 166 176 return (variables[i].value); 167 177 } 168 178 } 179 pthread_mutex_unlock (&mutex); 169 180 return (NULL); 170 181 } … … 238 249 239 250 int i, j; 251 252 /* need to use a mutex to prevent two threads from simultaneously modifying Nvariables */ 253 pthread_mutex_lock (&mutex); 240 254 241 255 for (i = 0; i < Nvariables; i++) { … … 248 262 Nvariables --; 249 263 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); 253 269 return (FALSE); 254 270 } … … 258 274 int i; 259 275 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); 263 286 return (FALSE); 264 287 } … … 273 296 } 274 297 298 /* need to use a mutex to prevent another thread from misleading on size of Nvariables */ 299 pthread_mutex_lock (&mutex); 300 275 301 for (i = 0; i < Nvariables; i++) { 276 302 gprint (GP_ERR, "%s = %s\n", variables[i].name, variables[i].value); 277 303 } 304 305 pthread_mutex_unlock (&mutex); 278 306 return; 279 307 }
Note:
See TracChangeset
for help on using the changeset viewer.
