IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 86


Ignore:
Timestamp:
May 28, 2003, 2:14:52 PM (23 years ago)
Author:
eugene
Message:

locking improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/imregister/imreg/db.c

    r70 r86  
    5353
    5454  lockstate = (output.modify || output.delete) ? LCK_HARD : LCK_SOFT;
     55  header.buffer = matrix.buffer = theader.buffer = table.buffer = (char *) NULL;
    5556
    5657  if (dBFile == (char *) NULL) {
     
    6162  /* lock database (soft) */
    6263  f = fsetlockfile (dBFile, 300.0, lockstate, &dbstate);
     64  if (dbstate == LCK_EMPTY) return (0);
    6365  if (f == (FILE *) NULL) {
    6466    fprintf (stderr, "ERROR: can't set lock on %s\n", dBFile);
    6567    exit (1);
    6668  }
    67   if (dbstate == LCK_EMPTY) return (0);
    68 
    69   /* load in table data */
     69
     70  /* init & load in table data */
    7071  table.header = &theader;
    71   if (!fits_fread_header (f, &header))                     escape (UNLOCK, "ERROR: can't read primary header");
    72   if (!fits_fread_matrix (f, &matrix, &header))            escape (UNLOCK, "ERROR: can't read primary header");
    73   if (!fits_fread_ftable  (f, &table, "IMAGE_DATABASE"))  escape (UNLOCK, "ERROR: can't read primary header");
     72  if (!fits_fread_header (f, &header))                  escape (UNLOCK, "ERROR: can't read primary header");
     73  if (!fits_fread_matrix (f, &matrix, &header))         escape (UNLOCK, "ERROR: can't read primary header");
     74  if (!fits_fread_ftable (f, &table, "IMAGE_DATABASE")) escape (UNLOCK, "ERROR: can't read primary header");
    7475
    7576  /* convert to internal format */
     
    9495  make_backup (dBFile);
    9596  Fseek (f, 0, SEEK_SET);
    96   if (!fits_fwrite_header (f, &header))   escape (LOCK, "ERROR: can't update db");
    97   if (!fits_fwrite_matrix (f, &matrix))   escape (LOCK, "ERROR: can't update db");
     97  if (!fits_fwrite_header  (f, &header))  escape (LOCK, "ERROR: can't update db");
     98  if (!fits_fwrite_matrix  (f, &matrix))  escape (LOCK, "ERROR: can't update db");
    9899  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db");
    99100  if (!fits_fwrite_table   (f, &table))   escape (LOCK, "ERROR: can't update db");
     101
     102  fits_free_header (&header);
     103  fits_free_matrix (&matrix);
     104  fits_free_header (&theader);
     105  fits_free_table  (&table);
     106
    100107  fclearlockfile (dBFile, f, lockstate, &dbstate);
    101108  return (TRUE);
     
    137144  if (!fits_fwrite_Theader (f, &theader)) escape (LOCK, "ERROR: can't update db");
    138145  if (!fits_fwrite_vtable   (f, &vtable)) escape (LOCK, "ERROR: can't update db");
     146
     147  fits_free_header (&header);
     148  fits_free_matrix (&matrix);
     149  fits_free_header (&theader);
     150  fits_free_vtable (&vtable);
     151  fits_free_table  (&table);
     152
    139153  fclearlockfile (dBFile, f, lockstate, &dbstate);
    140154  return (TRUE);
     
    158172  if (!fits_fwrite_vtable   (f, &vtable)) escape (LOCK, "ERROR: can't append to db");
    159173
     174  fits_free_header (&header);
     175  fits_free_matrix (&matrix);
     176  fits_free_header (&theader);
     177  fits_free_vtable (&vtable);
     178
    160179  fclearlockfile (dBFile, f, lockstate, &dbstate);
    161180  return (TRUE);
     
    177196
    178197int close_db () {
     198
     199  fits_free_header (&header);
     200  fits_free_matrix (&matrix);
     201  fits_free_header (&theader);
     202  fits_free_table  (&table);
     203
    179204  if (dbstate == LCK_UNLOCK) return (TRUE);
    180205  fclearlockfile (dBFile, f, lockstate, &dbstate);
     
    183208
    184209int close_lock_db () {
    185   close (f);
     210
     211  fits_free_header (&header);
     212  fits_free_matrix (&matrix);
     213  fits_free_header (&theader);
     214  fits_free_table  (&table);
     215
     216  if (dbstate == LCK_UNLOCK) return (TRUE);
     217  fclearlockfile (dBFile, f, LCK_XCLD, &dbstate);
    186218  return (TRUE);
    187219
     220
     221int print_db_status (char *message) {
     222
     223  int fd;
     224
     225  if (!output.verbose) return (0);
     226  if (f == (FILE *) NULL) {
     227    fprintf (stderr, "%s - db: %s - fd: %d\n", message, "null", -1);
     228    return (0);
     229  }
     230  fd = fileno (f);
     231  fprintf (stderr, "%s - db: %s - fd: %d\n", message, dBFile, fd);
     232  return (1);
     233}
    188234
    189235int escape (int mode, char *message) {
Note: See TracChangeset for help on using the changeset viewer.