IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16887


Ignore:
Timestamp:
Mar 8, 2008, 11:25:11 AM (18 years ago)
Author:
eugene
Message:

add thread safety to create/delete of vectors

File:
1 edited

Legend:

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

    r16443 r16887  
    44static int     Nvectors;
    55 
     6static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
     7
     8// this function is NOT thread protected : it is only used in startup and/or shutdown
    69void InitVectors () {
    710  Nvectors = 0;
     
    912}
    1013
     14// this function is NOT thread protected : it is only used in startup and/or shutdown
    1115void FreeVectors () {
    1216
     
    6468  if (i == Nvectors) {
    6569    if (mode == OLDVECTOR) goto error;
    66     Nvectors += 1;
     70    pthread_mutex_lock (&mutex);
     71    Nvectors ++;
    6772    REALLOCATE (vectors, Vector *, Nvectors);
    6873    vectors[i] = InitVector ();
    6974    strcpy (vectors[i][0].name, name);
     75    pthread_mutex_unlock (&mutex);
    7076    return (vectors[i]);
    7177  }
     
    9197  free (vectors[i][0].elements);
    9298  free (vectors[i]);
     99
     100  pthread_mutex_lock (&mutex);
    93101  for (j = i; j < Nvectors - 1; j++) vectors[j] = vectors[j + 1];
    94 
    95   Nvectors -= 1;
     102  Nvectors --;
    96103  REALLOCATE (vectors, Vector *, MAX (Nvectors, 1));
     104  pthread_mutex_unlock (&mutex);
    97105  return (TRUE);
    98106}
     
    109117  free (vectors[i][0].elements);
    110118  free (vectors[i]);
     119
     120  pthread_mutex_lock (&mutex);
    111121  for (j = i; j < Nvectors - 1; j++) vectors[j] = vectors[j + 1];
    112 
    113   Nvectors -= 1;
     122  Nvectors --;
    114123  REALLOCATE (vectors, Vector *, MAX (Nvectors, 1));
     124  pthread_mutex_unlock (&mutex);
    115125  return (TRUE);
    116126}
     
    154164  }
    155165
     166  pthread_mutex_lock (&mutex);
    156167  for (j = i; j < Nvectors - 1; j++) vectors[j] = vectors[j + 1];
    157   Nvectors -= 1;
     168  Nvectors --;
    158169  REALLOCATE (vectors, Vector *, MAX (Nvectors, 1));
    159170  free (in);
     171  pthread_mutex_unlock (&mutex);
    160172  return (TRUE);
    161173}
Note: See TracChangeset for help on using the changeset viewer.