summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flash.c38
-rw-r--r--flash.h1
2 files changed, 22 insertions, 17 deletions
diff --git a/flash.c b/flash.c
index a242284..34f6e7f 100644
--- a/flash.c
+++ b/flash.c
@@ -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
@@ -295,31 +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 (globals.Flags.shutdown_started) return;
-
- globals.Flags.flash_write_in_progress = TRUE;
- bool backup_ok = persistence_copyfile(MAINFILE, BACKUPFILE);
- globals.Flags.flash_write_in_progress = FALSE;
+ if (!globals.Flags.shutdown_started) {
- if (backup_ok) {
- if (globals.Flags.shutdown_started) return;
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");
+ 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");
}
- globals.Flags.flash_write_in_progress = FALSE;
- } else {
- printf("Could not backup current file. **Write did not happen!!!**\n");
}
}
+
+ g_mutex_unlock (&mutex);
}
diff --git a/flash.h b/flash.h
index 739fefa..c2d3b0e 100644
--- a/flash.h
+++ b/flash.h
@@ -5,7 +5,6 @@
#include <glib.h>
void initFlash(FlashStruct *mem, gboolean reset_to_defaults, int starting_location);
-int readUserBlock(FlashStruct *mem);
void writeUserBlock(FlashStruct *mem, int addr, int numbytes);
void fixFlash(FlashStruct *mem);