diff --git a/mount.go b/mount.go index 543f55b..fb64c5f 100644 --- a/mount.go +++ b/mount.go @@ -20,6 +20,7 @@ import ( "net" "os" "os/exec" + "sync/atomic" "syscall" ) @@ -71,6 +72,9 @@ func Mount( if cfgCopy.OpContext == nil { cfgCopy.OpContext = context.Background() } + if cfgCopy.ReaderThreads < 1 { + cfgCopy.ReaderThreads = 1 + } // Create a Connection object wrapping the device. connection, err := newConnection( @@ -83,11 +87,16 @@ func Mount( } // Serve the connection in the background. When done, set the join status. - go func() { - server.ServeOps(connection) - mfs.joinStatus = connection.close() - close(mfs.joinStatusAvailable) - }() + atomic.AddInt64(&mfs.joinRemaining, int64(cfgCopy.ReaderThreads)) + for i := 0; i < cfgCopy.ReaderThreads; i++ { + go func() { + server.ServeOps(connection) + if atomic.AddInt64(&mfs.joinRemaining, -1) == 0 { + mfs.joinStatus = connection.close() + close(mfs.joinStatusAvailable) + } + }() + } // Wait for the mount process to complete. if err := <-ready; err != nil { diff --git a/mount_config.go b/mount_config.go index 5d827ab..813a0d2 100644 --- a/mount_config.go +++ b/mount_config.go @@ -161,6 +161,11 @@ type MountConfig struct { // the data is already in memory when they return it to FUSE. UseVectoredRead bool + // Number of goroutines (and hopefully threads) to use for reading from + // the FUSE file descriptor. You can try to use more than 1 if memory + // copying during write operations is a bottleneck for you + ReaderThreads int + // OS X only. // // The name of the mounted volume, as displayed in the Finder. If empty, a diff --git a/mounted_file_system.go b/mounted_file_system.go index bb9bb35..0e0f443 100644 --- a/mounted_file_system.go +++ b/mounted_file_system.go @@ -23,6 +23,7 @@ type MountedFileSystem struct { // The result to return from Join. Not valid until the channel is closed. joinStatus error + joinRemaining int64 joinStatusAvailable chan struct{} }