Skip to content

[WIP] added a new mutex for ftFileCreator, preventing global lock of the UI when writing large file chunks #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/ft/ftfilecreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
***********************************************************/

ftFileCreator::ftFileCreator(const std::string& path, uint64_t size, const RsFileHash& hash,bool assume_availability)
: ftFileProvider(path,size,hash), chunkMap(size,assume_availability)
: ftFileProvider(path,size,hash), chunkMap(size,assume_availability), diskWriteMutex("ftFileCreator")
{
/*
* FIXME any inits to do?
Expand Down Expand Up @@ -166,7 +166,8 @@ void ftFileCreator::closeFile()
#ifdef FILE_DEBUG
std::cerr << "CLOSED FILE " << (void*)fd << " (" << file_name << ")." << std::endl ;
#endif
fclose(fd) ;
RsStackMutex stack2(diskWriteMutex); /********** STACK LOCKED MTX ******/
fclose(fd) ;
}

fd = NULL ;
Expand Down Expand Up @@ -196,11 +197,14 @@ bool ftFileCreator::addFileData(uint64_t offset, uint32_t chunk_size, void *data

bool complete = false ;
{
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
RsStackMutex stack(diskWriteMutex); /********** STACK LOCKED MTX ******/

if (fd == NULL)
if (!locked_initializeFileAttrs())
{
RsStackMutex stack2(ftcMutex); /********** STACK LOCKED MTX ******/
if (!locked_initializeFileAttrs())
return false;
}

/*
* check its at the correct location
Expand Down Expand Up @@ -238,7 +242,8 @@ bool ftFileCreator::addFileData(uint64_t offset, uint32_t chunk_size, void *data
/*
* Notify ftFileChunker about chunks received
*/
locked_notifyReceived(offset,chunk_size);
RsStackMutex stack2(ftcMutex); /********** STACK LOCKED MTX ******/
locked_notifyReceived(offset,chunk_size);

complete = chunkMap.isComplete();
}
Expand Down
2 changes: 2 additions & 0 deletions src/ft/ftfilecreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class ftFileCreator: public ftFileProvider

rstime_t _last_recv_time_t ; /// last time stamp when data was received. Used for queue control.
rstime_t _creation_time ; /// time at which the file creator was created. Used to spot long-inactive transfers.

RsMutex diskWriteMutex;
};

#endif // FT_FILE_CREATOR_HEADER