#include "TLockFile.h"
#include "TSystem.h"
#include "TFile.h"
#include <time.h>
ClassImp(TLockFile)
TLockFile::TLockFile(const char *path, Int_t timeLimit) : fPath(path)
{
   
   
   
   while (1) {
      if (Lock(fPath, timeLimit))
         break;
      if (gDebug > 0)
         Info("TLockFile", "did not aquire lock %s, sleeping...", fPath.Data());
      gSystem->Sleep(1000);
   }
}
TLockFile::~TLockFile()
{
   
   if (gDebug > 0)
      Info("~TLockFile", "releasing lock %s", fPath.Data());
   gSystem->Unlink(fPath);
}
Bool_t TLockFile::Lock(const char *path, Int_t timeLimit)
{
   
   Long_t modTime = 0;
   if (gSystem->GetPathInfo(path, 0, (Long_t*) 0, 0, &modTime) == 0) {
      if (timeLimit > 0) {
         if (gDebug > 0)
            Info("Lock", "%s modification time %ld, %d seconds ago", path, modTime, time(0) - modTime);
         if (time(0) - modTime > timeLimit){
            gSystem->Unlink(path);
            if (gDebug > 0)
               Info("Lock", "time expired, removed %s", path);
         } else
            return kFALSE;
      } else
         return kFALSE;
   }
   TString spath = path;
   spath += "?filetype=raw";
   TFile *file = TFile::Open(spath, "CREATE");
   if (!file)
      return kFALSE;
   file->Close();
   delete file;
   
   gSystem->Chmod(path, 0666);
   if (gDebug > 0)
      Info("Lock", "obtained lock %s", path);
   return kTRUE;
}
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.