File: FuseThread.cpp

package info (click to toggle)
cryfs 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,412 kB
  • sloc: cpp: 150,187; asm: 10,493; python: 1,455; javascript: 65; sh: 50; makefile: 17; xml: 7
file content (37 lines) | stat: -rw-r--r-- 1,167 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <sys/types.h>
#include "FuseThread.h"
#include <csignal>
#include <cpp-utils/assert/assert.h>
#include "fspp/fuse/Fuse.h"

using boost::thread;
using boost::chrono::seconds;
using std::string;
using std::vector;
namespace bf = boost::filesystem;

using fspp::fuse::Fuse;

FuseThread::FuseThread(Fuse *fuse)
  :_fuse(fuse), _child() {
}

void FuseThread::start(const bf::path &mountDir, const vector<string> &fuseOptions) {
  _child = thread([this, mountDir, fuseOptions] () {
    _fuse->runInForeground(mountDir, fuseOptions);
  });
  //Wait until it is running (busy waiting is simple and doesn't hurt much here)
  while(!_fuse->running()) {}
#ifdef __APPLE__
  // On Mac OS X, _fuse->running() returns true too early, because macFUSE calls init() when it's not ready yet. Give it a bit time.
  std::this_thread::sleep_for(std::chrono::milliseconds(200));
#endif
}

void FuseThread::stop() {
  _fuse->stop();
  const bool thread_stopped = _child.try_join_for(seconds(10));
  ASSERT(thread_stopped, "FuseThread could not be stopped");
  //Wait until it is properly shutdown (busy waiting is simple and doesn't hurt much here)
  while (_fuse->running()) {}
}