Changeset 426 for trunk/matml

Show
Ignore:
Timestamp:
02/23/2009 07:38:26 PM (3 years ago)
Author:
powell
Message:

Lock for qhull structures and memory, for future thread safety.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/matml/src/ternary/qhull.c

    r425 r426  
    1212#include <stdlib.h> 
    1313#include <math.h> 
     14 
     15 
     16static int qhull_lock=0; /*+ Lock for qhull memory and structures +*/ 
    1417 
    1518 
     
    125128    { printf ("qhullCalcHull: could not allocate memory for points\n"); 
    126129      return -1; } 
     130 
     131  if (qhull_lock) 
     132    { printf ("Qhull use is currently locked\n"); return 1; } 
     133  qhull_lock=1; 
     134 
    127135  for (i=0; i<numpoints; i++) 
    128136    { 
     
    180188#endif 
    181189  if (!(*facets = realloc (*facets, *numfacets * sizeof (hull_facet)))) 
    182     { printf ("hullReturnFacets: could not reallocate memory for vertices\n"); 
    183       return -1; } 
     190    { 
     191      printf ("hullReturnFacets: could not reallocate memory for vertices\n"); 
     192      free (qpoints); 
     193      qh_freeqhull (True); 
     194      qhull_lock=0; 
     195      return -1; 
     196    } 
    184197#ifdef DEBUG 
    185198  printf ("  post-realloc 0x%lx\n", *facets); 
     
    242255    } 
    243256 
     257  free (qpoints); 
     258  qh_freeqhull (True); 
     259  qhull_lock=0; 
     260 
    244261#ifdef DEBUG 
    245262  printf ("After trimming loop: %d total facets, i=%d\n", *numfacets, i); 
     
    252269  printf ("  post-realloc 0x%lx\n", *facets); 
    253270#endif 
    254  
    255   free (qpoints); 
    256   qh_freeqhull (True); 
    257271 
    258272  return 0;