nfs4: Fix issues with renewal thread

This commit is contained in:
Pawel Dziepak
2012-07-11 21:05:50 +02:00
parent c3b57e8e83
commit 2e115f468f
2 changed files with 13 additions and 4 deletions
@@ -16,7 +16,7 @@
NFS4Server::NFS4Server(RPC::Server* serv) NFS4Server::NFS4Server(RPC::Server* serv)
: :
fThreadCancel(true), fThreadCancel(true),
fWaitCancel(create_sem(1, NULL)), fWaitCancel(create_sem(0, NULL)),
fLeaseTime(0), fLeaseTime(0),
fClientIdLastUse(0), fClientIdLastUse(0),
fUseCount(0), fUseCount(0),
@@ -25,6 +25,8 @@ NFS4Server::NFS4Server(RPC::Server* serv)
{ {
mutex_init(&fClientIdLock, NULL); mutex_init(&fClientIdLock, NULL);
mutex_init(&fFSLock, NULL); mutex_init(&fFSLock, NULL);
mutex_init(&fThreadStartLock, NULL);
} }
@@ -39,6 +41,7 @@ NFS4Server::~NFS4Server()
delete_sem(fWaitCancel); delete_sem(fWaitCancel);
mutex_destroy(&fClientIdLock); mutex_destroy(&fClientIdLock);
mutex_destroy(&fFSLock); mutex_destroy(&fFSLock);
mutex_destroy(&fThreadStartLock);
} }
@@ -166,7 +169,7 @@ NFS4Server::AddFileSystem(FileSystem* fs)
fFileSystems->fPrev = fs; fFileSystems->fPrev = fs;
fFileSystems = fs; fFileSystems = fs;
fUseCount += fs->OpenFilesCount(); fUseCount += fs->OpenFilesCount();
if (fs->OpenFilesCount() > 0 && fThreadCancel) if (fs->OpenFilesCount() > 0)
_StartRenewing(); _StartRenewing();
} }
@@ -274,6 +277,11 @@ NFS4Server::_GetLeaseTime()
status_t status_t
NFS4Server::_StartRenewing() NFS4Server::_StartRenewing()
{ {
if (!fThreadCancel)
return B_OK;
MutexLocker _(fThreadStartLock);
if (!fThreadCancel) if (!fThreadCancel)
return B_OK; return B_OK;
@@ -43,9 +43,11 @@ private:
status_t _StartRenewing(); status_t _StartRenewing();
status_t _Renewal(); status_t _Renewal();
static status_t _RenewalThreadStart(void* ptr); static status_t _RenewalThreadStart(void* ptr);
thread_id fThread; thread_id fThread;
bool fThreadCancel; bool fThreadCancel;
sem_id fWaitCancel; sem_id fWaitCancel;
mutex fThreadStartLock;
uint32 fLeaseTime; uint32 fLeaseTime;
@@ -67,8 +69,7 @@ NFS4Server::IncUsage()
{ {
MutexLocker _(fFSLock); MutexLocker _(fFSLock);
fUseCount++; fUseCount++;
if (fThreadCancel) _StartRenewing();
_StartRenewing();
fClientIdLastUse = time(NULL); fClientIdLastUse = time(NULL);
} }