diff --git a/src/ft/ftfilecreator.cc b/src/ft/ftfilecreator.cc index 53a1036b4..a96c03731 100644 --- a/src/ft/ftfilecreator.cc +++ b/src/ft/ftfilecreator.cc @@ -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? @@ -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 ; @@ -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 @@ -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(); } diff --git a/src/ft/ftfilecreator.h b/src/ft/ftfilecreator.h index 01a990414..bf288d19a 100644 --- a/src/ft/ftfilecreator.h +++ b/src/ft/ftfilecreator.h @@ -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