Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2018-04-01 18:49:43 +0300
committerDavid Crocker <dcrocker@eschertech.com>2018-04-01 18:49:43 +0300
commit97e7b46202b9f71075101ed86b6967904f87fa98 (patch)
tree4852f94f2497ae43f6f2ba69c6a72ace6f1f7fd0 /src/Storage
parent4d151a5d02a8bca3810e4a75bf225136548fa1ab (diff)
More RTOS work
Refactored mutex and task interface Output channels, tool list and message box data are now thread safe
Diffstat (limited to 'src/Storage')
-rw-r--r--src/Storage/FileInfoParser.cpp4
-rw-r--r--src/Storage/FileInfoParser.h3
-rw-r--r--src/Storage/MassStorage.cpp50
-rw-r--r--src/Storage/MassStorage.h10
4 files changed, 31 insertions, 36 deletions
diff --git a/src/Storage/FileInfoParser.cpp b/src/Storage/FileInfoParser.cpp
index fcd78500..013caf1d 100644
--- a/src/Storage/FileInfoParser.cpp
+++ b/src/Storage/FileInfoParser.cpp
@@ -31,12 +31,12 @@ FileInfoParser::FileInfoParser()
: parseState(notParsing), fileBeingParsed(nullptr), accumulatedParseTime(0), accumulatedReadTime(0), accumulatedSeekTime(0), fileOverlapLength(0)
{
parsedFileInfo.Init();
- parserMutexHandle = RTOSIface::CreateMutex(parserMutexStorage);
+ parserMutex.Create();
}
bool FileInfoParser::GetFileInfo(const char *directory, const char *fileName, GCodeFileInfo& info, bool quitEarly)
{
- Locker lock(parserMutexHandle, MAX_FILEINFO_PROCESS_TIME);
+ MutexLocker lock(parserMutex, MAX_FILEINFO_PROCESS_TIME);
if (!lock)
{
return false;
diff --git a/src/Storage/FileInfoParser.h b/src/Storage/FileInfoParser.h
index 059d775c..49f3572e 100644
--- a/src/Storage/FileInfoParser.h
+++ b/src/Storage/FileInfoParser.h
@@ -68,8 +68,7 @@ private:
unsigned int FindFilamentUsed(const char* buf, size_t len, float *filamentUsed, size_t maxFilaments) const;
// We parse G-Code files in multiple stages. These variables hold the required information
- MutexHandle parserMutexHandle;
- MutexStorage parserMutexStorage;
+ Mutex parserMutex;
FileParseState parseState;
String<MaxFilenameLength> filenameBeingParsed;
diff --git a/src/Storage/MassStorage.cpp b/src/Storage/MassStorage.cpp
index 3026271d..1aa083ce 100644
--- a/src/Storage/MassStorage.cpp
+++ b/src/Storage/MassStorage.cpp
@@ -64,8 +64,8 @@ MassStorage::MassStorage(Platform* p) : freeWriteBuffers(nullptr)
void MassStorage::Init()
{
// Create the mutexes
- fsMutexHandle = RTOSIface::CreateMutex(fsMutexStorage);
- dirMutexHandle = RTOSIface::CreateMutex(dirMutexStorage);
+ fsMutex.Create();
+ dirMutex.Create();
for (size_t i = 0; i < NumFileWriteBuffers; ++i)
{
@@ -79,7 +79,7 @@ void MassStorage::Init()
inf.mounting = inf.isMounted = false;
inf.cdPin = SdCardDetectPins[card];
inf.cardState = CardDetectState::present;
- inf.volMutexHandle = RTOSIface::CreateMutex(inf.volMutexStorage);
+ inf.volMutex.Create();
}
sd_mmc_init(SdWriteProtectPins, SdSpiCSPins); // initialize SD MMC stack
@@ -101,7 +101,7 @@ void MassStorage::Init()
FileWriteBuffer *MassStorage::AllocateWriteBuffer()
{
- Locker lock(fsMutexHandle);
+ MutexLocker lock(fsMutex);
if (freeWriteBuffers == nullptr)
{
return nullptr;
@@ -115,7 +115,7 @@ FileWriteBuffer *MassStorage::AllocateWriteBuffer()
void MassStorage::ReleaseWriteBuffer(FileWriteBuffer *buffer)
{
- Locker lock(fsMutexHandle);
+ MutexLocker lock(fsMutex);
buffer->SetNext(freeWriteBuffers);
freeWriteBuffers = buffer;
}
@@ -123,7 +123,7 @@ void MassStorage::ReleaseWriteBuffer(FileWriteBuffer *buffer)
FileStore* MassStorage::OpenFile(const char* directory, const char* fileName, OpenMode mode)
{
{
- Locker lock(fsMutexHandle);
+ MutexLocker lock(fsMutex);
for (size_t i = 0; i < MAX_FILES; i++)
{
if (!files[i].inUse)
@@ -147,7 +147,7 @@ FileStore* MassStorage::OpenFile(const char* directory, const char* fileName, Op
// Close all files
void MassStorage::CloseAllFiles()
{
- Locker lock(fsMutexHandle);
+ MutexLocker lock(fsMutex);
for (FileStore& f : files)
{
while (f.inUse)
@@ -217,7 +217,7 @@ bool MassStorage::FindFirst(const char *directory, FileInfo &file_info)
loc[len - 1] = 0;
}
- if (!RTOSIface::TakeMutex(dirMutexHandle, 10000))
+ if (!dirMutex.Take(10000))
{
return false;
}
@@ -250,7 +250,7 @@ bool MassStorage::FindFirst(const char *directory, FileInfo &file_info)
}
}
- RTOSIface::ReleaseMutex(dirMutexHandle);
+ dirMutex.Release();
return false;
}
@@ -258,7 +258,7 @@ bool MassStorage::FindFirst(const char *directory, FileInfo &file_info)
// If it returns false then it also releases the mutex.
bool MassStorage::FindNext(FileInfo &file_info)
{
- if (RTOSIface::GetMutexHolder(dirMutexHandle) != RTOSIface::GetCurrentTask())
+ if (dirMutex.GetHolder() != RTOSIface::GetCurrentTask())
{
return false; // error, we don't hold the mutex
}
@@ -271,7 +271,7 @@ bool MassStorage::FindNext(FileInfo &file_info)
if (f_readdir(&findDir, &entry) != FR_OK || entry.fname[0] == 0)
{
//f_closedir(findDir);
- RTOSIface::ReleaseMutex(dirMutexHandle);
+ dirMutex.Release();
return false;
}
@@ -290,9 +290,9 @@ bool MassStorage::FindNext(FileInfo &file_info)
// Quit searching for files. Needed to avoid hanging on to the mutex.
void MassStorage::AbandonFindNext()
{
- if (RTOSIface::GetMutexHolder(dirMutexHandle) == RTOSIface::GetCurrentTask())
+ if (dirMutex.GetHolder() == RTOSIface::GetCurrentTask())
{
- RTOSIface::ReleaseMutex(dirMutexHandle);
+ dirMutex.Release();
}
}
@@ -315,7 +315,7 @@ bool MassStorage::Delete(const char* directory, const char* fileName, bool silen
// Start new scope to lock the filesystem for the minimum time
{
- Locker lock(fsMutexHandle);
+ MutexLocker lock(fsMutex);
// First check whether the file is open - don't allow it to be deleted if it is
FIL file;
@@ -461,8 +461,8 @@ GCodeResult MassStorage::Mount(size_t card, const StringRef& reply, bool reportS
}
SdCardInfo& inf = info[card];
- Locker lock1(fsMutexHandle);
- Locker lock2(inf.volMutexHandle);
+ MutexLocker lock1(fsMutex);
+ MutexLocker lock2(inf.volMutex);
if (!inf.mounting)
{
if (inf.isMounted)
@@ -568,7 +568,7 @@ bool MassStorage::CheckDriveMounted(const char* path)
// Return true if any files are open on the file system
bool MassStorage::AnyFileOpen(const FATFS *fs) const
{
- Locker lock(fsMutexHandle);
+ MutexLocker lock(fsMutex);
for (const FileStore & fil : files)
{
if (fil.IsOpenOn(fs))
@@ -583,7 +583,7 @@ bool MassStorage::AnyFileOpen(const FATFS *fs) const
unsigned int MassStorage::InvalidateFiles(const FATFS *fs, bool doClose)
{
unsigned int invalidated = 0;
- Locker lock(fsMutexHandle);
+ MutexLocker lock(fsMutex);
for (FileStore & fil : files)
{
if (fil.Invalidate(fs, doClose))
@@ -618,8 +618,8 @@ bool MassStorage::IsCardDetected(size_t card) const
bool MassStorage::InternalUnmount(size_t card, bool doClose)
{
SdCardInfo& inf = info[card];
- Locker lock1(fsMutexHandle);
- Locker lock2(inf.volMutexHandle);
+ MutexLocker lock1(fsMutex);
+ MutexLocker lock2(inf.volMutex);
const bool invalidated = InvalidateFiles(&inf.fileSystem, doClose);
f_mount(card, nullptr);
memset(&inf.fileSystem, 0, sizeof(inf.fileSystem));
@@ -631,7 +631,7 @@ bool MassStorage::InternalUnmount(size_t card, bool doClose)
unsigned int MassStorage::GetNumFreeFiles() const
{
unsigned int numFreeFiles = 0;
- Locker lock(fsMutexHandle);
+ MutexLocker lock(fsMutex);
for (const FileStore & fil : files)
{
if (!fil.inUse)
@@ -703,7 +703,7 @@ void MassStorage::Spin()
// Check if any files are supposed to be closed
{
- Locker lock(fsMutexHandle);
+ MutexLocker lock(fsMutex);
for (FileStore & fil : files)
{
if (fil.closeRequested)
@@ -757,21 +757,21 @@ extern "C"
// Create a sync object. We already created it, we just need to copy the handle.
int ff_cre_syncobj (BYTE vol, _SYNC_t* psy)
{
- *psy = reprap.GetPlatform().GetMassStorage()->GetVolumeMutexHandle(vol);
+ *psy = &reprap.GetPlatform().GetMassStorage()->GetVolumeMutex(vol);
return 1;
}
// Lock sync object
int ff_req_grant (_SYNC_t sy)
{
- xSemaphoreTakeRecursive(sy, portMAX_DELAY);
+ sy->Take();
return 1;
}
// Unlock sync object
void ff_rel_grant (_SYNC_t sy)
{
- xSemaphoreGiveRecursive(sy);
+ sy->Release();
}
// Delete a sync object
diff --git a/src/Storage/MassStorage.h b/src/Storage/MassStorage.h
index e73716f3..51d29c69 100644
--- a/src/Storage/MassStorage.h
+++ b/src/Storage/MassStorage.h
@@ -51,7 +51,7 @@ public:
void CloseAllFiles();
unsigned int GetNumFreeFiles() const;
void Spin();
- MutexHandle GetVolumeMutexHandle(size_t vol) const { return info[vol].volMutexHandle; }
+ const Mutex& GetVolumeMutex(size_t vol) const { return info[vol].volMutex; }
bool GetFileInfo(const char *directory, const char *fileName, GCodeFileInfo& info, bool quitEarly) { return infoParser.GetFileInfo(directory, fileName, info, quitEarly); }
enum class InfoResult : uint8_t
@@ -87,8 +87,7 @@ private:
FATFS fileSystem;
uint32_t cdChangedTime;
uint32_t mountStartTime;
- MutexHandle volMutexHandle;
- MutexStorage volMutexStorage;
+ Mutex volMutex;
Pin cdPin;
bool mounting;
bool isMounted;
@@ -100,10 +99,7 @@ private:
SdCardInfo info[NumSdCards];
- MutexHandle fsMutexHandle;
- MutexHandle dirMutexHandle;
- MutexStorage fsMutexStorage;
- MutexStorage dirMutexStorage;
+ Mutex fsMutex, dirMutex;
FileInfoParser infoParser;
DIR findDir;