summaryrefslogtreecommitdiff
path: root/netfs/fuse/fuseFiles.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'netfs/fuse/fuseFiles.cpp')
-rw-r--r--netfs/fuse/fuseFiles.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp
index e31b4db..e81dd45 100644
--- a/netfs/fuse/fuseFiles.cpp
+++ b/netfs/fuse/fuseFiles.cpp
@@ -39,6 +39,7 @@ NetFS::FuseApp::clearFileProxy(uint64_t localID)
void
NetFS::FuseApp::OpenFile::wait() const
{
+ SharedLock(_lock);
for (const auto & w : bg) {
w->waitForCompleted();
}
@@ -47,6 +48,7 @@ NetFS::FuseApp::OpenFile::wait() const
void
NetFS::FuseApp::OpenFile::flush()
{
+ Lock(_lock);
while (!bg.empty()) {
auto w = bg.front();
bg.pop_front();
@@ -55,6 +57,24 @@ NetFS::FuseApp::OpenFile::flush()
}
}
+void
+NetFS::FuseApp::OpenFile::nonBlockingFlush()
+{
+ boost::unique_lock<boost::shared_mutex> lock(_lock, boost::try_to_lock);
+ if (lock.owns_lock()) {
+ for (auto wi = bg.begin(); wi != bg.end(); ) {
+ auto w = *wi;
+ if (w->isCompleted()) {
+ wi = bg.erase(wi);
+ w->throwLocalException();
+ }
+ else {
+ wi++;
+ }
+ }
+ }
+}
+
int
NetFS::FuseApp::open(const char * p, struct fuse_file_info * fi)
{
@@ -138,7 +158,10 @@ NetFS::FuseApp::write(const char *, const char * buf, size_t s, off_t o, struct
auto remote = of->remote;
auto r = remote->begin_write(o, s, NetFS::Buffer(buf, buf + s));
if (fcr->Async) {
- of->bg.push_back(r);
+ ScopeLock(of->_lock) {
+ of->bg.push_back(r);
+ }
+ of->nonBlockingFlush();
}
else {
r->throwLocalException();