diff options
author | daniel <danieruru@gmail.com> | 2012-10-07 19:46:17 +0900 |
---|---|---|
committer | daniel <danieruru@gmail.com> | 2012-10-07 19:46:17 +0900 |
commit | 3870833ae365162eccd5e1416682de02c498467b (patch) | |
tree | 7eb21d1aab245e094d7e51b9ad252115094e050e /flash.c | |
parent | db682a18e8c7b1711f101d655a4f12e53c71b73d (diff) | |
parent | b2c2c72d381ab1b32fa5b5fc4e890fef6c2bf1e0 (diff) |
Merge branch 'master' of grenfell.avtechpulse.com:Instrument
Conflicts:
instr-daemon.c
Diffstat (limited to 'flash.c')
-rw-r--r-- | flash.c | 40 |
1 files changed, 30 insertions, 10 deletions
@@ -259,7 +259,7 @@ bool persistence_unfreeze(char* dest, void* result, unsigned int len, uint32_t v } -int readUserBlock(FlashStruct *mem) +static int readUserBlock(FlashStruct *mem) { // try to unfreeze the main file @@ -272,7 +272,11 @@ int readUserBlock(FlashStruct *mem) // hopefully we can use the backup.. if (persistence_unfreeze(BACKUPFILE, mem, sizeof(*mem), 0)) { // if the backup was good overwrite the main file - persistence_copyfile(BACKUPFILE, MAINFILE); + if (!globals.Flags.shutdown_started) { + globals.Flags.flash_write_in_progress = TRUE; + persistence_copyfile(BACKUPFILE, MAINFILE); + globals.Flags.flash_write_in_progress = FALSE; + } return sizeof(*mem); } // deadend :( @@ -291,21 +295,37 @@ void writeUserBlock(FlashStruct *mem, int addr, int numbytes) // *** that the main file is valid before backing it up I guess... *** // *** but I don't think this situation should arise. *** + static GMutex mutex; + + g_mutex_lock (&mutex); + if (!globals.Flags.flash_writes_suspended) { // backup the main copy of the file - if (persistence_copyfile(MAINFILE, BACKUPFILE)) { - if (!persistence_freeze(MAINFILE, mem, addr, numbytes, sizeof(*mem), 0)) { - if (errno != PERSIST_ERR_COULDNTWRITE) { - printf("Error while trying to write, %d. **Write did not happen!!!**\n", errno); - } else { - printf("Error while writing data to disk. **File is potentially corrupt!**\n"); + if (!globals.Flags.shutdown_started) { + + globals.Flags.flash_write_in_progress = TRUE; + bool backup_ok = persistence_copyfile(MAINFILE, BACKUPFILE); + globals.Flags.flash_write_in_progress = FALSE; + + if (backup_ok && !globals.Flags.shutdown_started) { + globals.Flags.flash_write_in_progress = TRUE; + + if (!persistence_freeze(MAINFILE, mem, addr, numbytes, sizeof(*mem), 0)) { + if (errno != PERSIST_ERR_COULDNTWRITE) { + printf("Error while trying to write, %d. **Write did not happen!!!**\n", errno); + } else { + printf("Error while writing data to disk. **File is potentially corrupt!**\n"); + } } + globals.Flags.flash_write_in_progress = FALSE; + } else { + printf("Could not backup current file. **Write did not happen!!!**\n"); } - } else { - printf("Could not backup current file. **Write did not happen!!!**\n"); } } + + g_mutex_unlock (&mutex); } |