コード例 #1
0
ファイル: main.cpp プロジェクト: bentolor/encfs
static
void * idleMonitor(void *_arg)
{
  EncFS_Context *ctx = (EncFS_Context*)_arg;
  shared_ptr<EncFS_Args> arg = ctx->args;

  const int timeoutCycles = 60 * arg->idleTimeout / ActivityCheckInterval;
  int idleCycles = 0;

  ctx->wakeupMutex.lock();

  while(ctx->running)
  {
    int usage = ctx->getAndResetUsageCounter();

    if(usage == 0 && ctx->isMounted())
      ++idleCycles;
    else
      idleCycles = 0;

    if(idleCycles >= timeoutCycles)
    {
      int openCount = ctx->openFileCount();
      if( openCount == 0 && unmountFS( ctx ) )
      {
#ifdef CMAKE_USE_PTHREADS_INIT
        // wait for main thread to wake us up
        pthread_cond_wait( &ctx->wakeupCond, &ctx->wakeupMutex._mutex );
#endif
        break;
      }

      VLOG(1) << "num open files: " << openCount;
    }

    VLOG(1) << "idle cycle count: " << idleCycles 
      << ", timeout after " << timeoutCycles;

    struct timeval currentTime;
    gettimeofday( &currentTime, 0 );
    struct timespec wakeupTime;
    wakeupTime.tv_sec = currentTime.tv_sec + ActivityCheckInterval;
    wakeupTime.tv_nsec = currentTime.tv_usec * 1000;
#ifdef CMAKE_USE_PTHREADS_INIT
    pthread_cond_timedwait( &ctx->wakeupCond, 
        &ctx->wakeupMutex._mutex, &wakeupTime );
#endif
  }

  ctx->wakeupMutex.unlock();

  VLOG(1) << "Idle monitoring thread exiting";

  return 0;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: ghostbar/encfs.deb
static
void * idleMonitor(void *_arg)
{
    EncFS_Context *ctx = (EncFS_Context*)_arg;
    shared_ptr<EncFS_Args> arg = ctx->args;

    const int timeoutCycles = 60 * arg->idleTimeout / ActivityCheckInterval;
    int idleCycles = 0;

    pthread_mutex_lock( &ctx->wakeupMutex );
    
    while(ctx->running)
    {
	int usage = ctx->getAndResetUsageCounter();

	if(usage == 0 && ctx->isMounted())
	    ++idleCycles;
	else
	    idleCycles = 0;
	
	if(idleCycles >= timeoutCycles)
	{
	    int openCount = ctx->openFileCount();
	    if( openCount == 0 && unmountFS( ctx ) )
	    {
		// wait for main thread to wake us up
		pthread_cond_wait( &ctx->wakeupCond, &ctx->wakeupMutex );
		break;
	    }
		
	    rDebug("num open files: %i", openCount );
	}
	    
	rDebug("idle cycle count: %i, timeout after %i", idleCycles,
		timeoutCycles);

	struct timeval currentTime;
	gettimeofday( &currentTime, 0 );
	struct timespec wakeupTime;
	wakeupTime.tv_sec = currentTime.tv_sec + ActivityCheckInterval;
	wakeupTime.tv_nsec = currentTime.tv_usec * 1000;
	pthread_cond_timedwait( &ctx->wakeupCond, 
		&ctx->wakeupMutex, &wakeupTime );
    }
    
    pthread_mutex_unlock( &ctx->wakeupMutex );

    rDebug("Idle monitoring thread exiting");

    return 0;
}