Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XrdCl: Provide atomicity for PostMaster value using built-in functions #266

Merged
merged 1 commit into from
Jul 20, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/XrdCl/XrdClDefaultEnv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "XrdCl/XrdClTransportManager.hh"
#include "XrdCl/XrdClPlugInManager.hh"
#include "XrdOuc/XrdOucPreload.hh"
#include "XrdSys/XrdSysAtomics.hh"
#include "XrdSys/XrdSysUtils.hh"
#include "XrdSys/XrdSysPwd.hh"
#include "XrdVersion.hh"
Expand Down Expand Up @@ -311,36 +312,39 @@ namespace XrdCl
//----------------------------------------------------------------------------
PostMaster *DefaultEnv::GetPostMaster()
{
if( unlikely(!sPostMaster) )
PostMaster* postMaster = AtomicGet(sPostMaster);

if( unlikely( !postMaster ) )
{
XrdSysMutexHelper scopedLock( sInitMutex );
postMaster = AtomicGet(sPostMaster);

if( sPostMaster )
return sPostMaster;
if( postMaster )
return postMaster;

PostMaster* post_master = new PostMaster();
postMaster = new PostMaster();

if( !post_master->Initialize() )
if( !postMaster->Initialize() )
{
delete post_master;
post_master = 0;
delete postMaster;
postMaster = 0;
return 0;
}

if( !post_master->Start() )
if( !postMaster->Start() )
{
post_master->Finalize();
delete post_master;
post_master = 0;
postMaster->Finalize();
delete postMaster;
postMaster = 0;
return 0;
}

sForkHandler->RegisterPostMaster( post_master );
post_master->GetTaskManager()->RegisterTask( sFileTimer, time(0), false );
sPostMaster = post_master;
sForkHandler->RegisterPostMaster( postMaster );
postMaster->GetTaskManager()->RegisterTask( sFileTimer, time(0), false );
AtomicCAS(sPostMaster, sPostMaster, postMaster);
}

return sPostMaster;
return postMaster;
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -608,6 +612,7 @@ namespace XrdCl

if( sMonitorLibHandle )
sMonitorLibHandle->Unload();

delete sMonitorLibHandle;
sMonitorLibHandle = 0;

Expand Down