From 980ea96b05f7e38ce960b5fa45769a6c587ca182 Mon Sep 17 00:00:00 2001 From: Thomas Clark Date: Fri, 25 Jul 2014 17:00:41 -0400 Subject: [PATCH] Fixed Preferences in C++ The file name was never updated from the old path, a deadlock occured sometimes. A "resource not found" message was also set when fopen() returns an error, which should be an errno message because it's a C library error. Change-Id: Ic913a08f6f5d73219cb6625198f5a4519c039956 --- wpilibc/wpilibC++/lib/Preferences.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wpilibc/wpilibC++/lib/Preferences.cpp b/wpilibc/wpilibC++/lib/Preferences.cpp index 3cce8a1e76..30129122e2 100644 --- a/wpilibc/wpilibC++/lib/Preferences.cpp +++ b/wpilibc/wpilibC++/lib/Preferences.cpp @@ -18,7 +18,7 @@ static const char *kTableName = "Preferences"; /** The value of the save field */ static const char *kSaveField = "~S A V E~"; /** The file to save to */ -static const char *kFileName = "/c/wpilib-preferences.ini"; +static const char *kFileName = "wpilib-preferences.ini"; /** The characters to put between a field and value */ static const char *kValuePrefix = "=\""; /** The characters to put after the value */ @@ -33,9 +33,9 @@ Preferences::Preferences() : m_readTask("PreferencesReadTask", (FUNCPTR)Preferences::InitReadTask), m_writeTask("PreferencesWriteTask", (FUNCPTR)Preferences::InitWriteTask) { - m_fileLock = initializeMutexNormal(); + m_fileLock = initializeMutexRecursive(); m_fileOpStarted = initializeSemaphore (SEMAPHORE_EMPTY); - m_tableLock = initializeMutexNormal(); + m_tableLock = initializeMutexRecursive(); Synchronized sync(m_fileLock); m_readTask.Start((uint32_t)this); @@ -424,7 +424,7 @@ void Preferences::ReadTaskRun() { value = fgetc(file); } while (value == ' ' || value == '\t'); - + if (value == '\n' || value == ';') { if (value == '\n') @@ -511,7 +511,7 @@ void Preferences::ReadTaskRun() } else { - wpi_setWPIErrorWithContext(NoAvailableResources, "Failed to open preferences file."); + wpi_setErrnoErrorWithContext("Opening preferences file"); } if (file != NULL) @@ -519,7 +519,7 @@ void Preferences::ReadTaskRun() if (!comment.empty()) m_endComment = comment; - + NetworkTable::GetTable(kTableName)->PutBoolean(kSaveField, false); NetworkTable::GetTable(kTableName)->AddTableListener(this); }