Skip to content

Commit

Permalink
[XrdEc] Restructure code and add licence to hh/cc files.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal committed Jan 12, 2021
1 parent 26155c9 commit 4756869
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 304 deletions.
1 change: 0 additions & 1 deletion src/XrdEc/CMakeLists.txt
Expand Up @@ -79,7 +79,6 @@ add_library(
XrdEcObjCfg.hh
XrdEcRedundancyProvider.hh XrdEcRedundancyProvider.cc
XrdEcUtilities.hh XrdEcUtilities.cc
XrdEcScheduleHandler.hh XrdEcScheduleHandler.cc
XrdEcWrtBuff.hh
XrdEcThreadPool.hh
XrdEcStrmWriter.hh
Expand Down
57 changes: 39 additions & 18 deletions src/XrdEc/XrdEcConfig.hh
@@ -1,36 +1,57 @@
/*
* XrdEcConfig.hh
*
* Created on: Dec 4, 2018
* Author: simonm
*/
//------------------------------------------------------------------------------
// Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
// Author: Michal Simon <michal.simon@cern.ch>
//------------------------------------------------------------------------------
// This file is part of the XRootD software suite.
//
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//
// In applying this licence, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
//------------------------------------------------------------------------------

#ifndef SRC_XRDEC_XRDECCONFIG_HH_
#define SRC_XRDEC_XRDECCONFIG_HH_

#include "XrdEc/XrdEcRedundancyProvider.hh"
#include "XrdEc/XrdEcObjCfg.hh"

#include <stdint.h>
#include <string>
#include <unordered_map>

namespace XrdEc
{
//---------------------------------------------------------------------------
//! Global configuration for the EC module
//---------------------------------------------------------------------------
class Config
{
public:

//-----------------------------------------------------------------------
//! Singleton access
//-----------------------------------------------------------------------
static Config& Instance()
{
static Config config;
return config;
}

~Config()
{
}

//-----------------------------------------------------------------------
//! Get redundancy provider for given data object configuration
//-----------------------------------------------------------------------
RedundancyProvider& GetRedundancy( const ObjCfg &objcfg )
{
std::string key;
Expand All @@ -56,17 +77,17 @@ namespace XrdEc

std::unordered_map<std::string, RedundancyProvider> redundancies;

//-----------------------------------------------------------------------
//! Constructor
//-----------------------------------------------------------------------
Config()
{
}

Config( const Config& ) = delete;

Config( Config&& ) = delete;

Config& operator=( const Config& ) = delete;

Config& operator=( Config&& ) = delete;
Config( const Config& ) = delete; //< Copy constructor
Config( Config&& ) = delete; //< Move constructor
Config& operator=( const Config& ) = delete; //< Move assigment operator
Config& operator=( Config&& ) = delete; //< Copy assigment operator
};
}

Expand Down
1 change: 0 additions & 1 deletion src/XrdEc/XrdEcReader.cc
Expand Up @@ -26,7 +26,6 @@
#include "XrdEc/XrdEcUtilities.hh"
#include "XrdEc/XrdEcConfig.hh"
#include "XrdEc/XrdEcObjCfg.hh"
#include "XrdEc/XrdEcScheduleHandler.hh"

#include "XrdZip/XrdZipLFH.hh"
#include "XrdZip/XrdZipCDFH.hh"
Expand Down
61 changes: 0 additions & 61 deletions src/XrdEc/XrdEcScheduleHandler.cc

This file was deleted.

23 changes: 0 additions & 23 deletions src/XrdEc/XrdEcScheduleHandler.hh

This file was deleted.

112 changes: 82 additions & 30 deletions src/XrdEc/XrdEcThreadPool.hh
@@ -1,21 +1,38 @@
/*
* XrdEcThreadPool.hh
*
* Created on: Jan 14, 2020
* Author: simonm
*/
//------------------------------------------------------------------------------
// Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
// Author: Michal Simon <michal.simon@cern.ch>
//------------------------------------------------------------------------------
// This file is part of the XRootD software suite.
//
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//
// In applying this licence, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
//------------------------------------------------------------------------------

#include "XrdCl/XrdClJobManager.hh"

#include <future>


#ifndef SRC_XRDEC_XRDECTHREADPOOL_HH_
#define SRC_XRDEC_XRDECTHREADPOOL_HH_

namespace XrdEc
{

//---------------------------------------------------------------------------
// A theread pool class for the XrdEc module
//---------------------------------------------------------------------------
class ThreadPool
{
private:
Expand All @@ -30,83 +47,115 @@ namespace XrdEc
template <int I, int ... Ns>
struct seq_gen<I, Ns...>
{
using type = typename seq_gen<I - 1, I - 1, Ns...>::type;
using type = typename seq_gen<I - 1, I - 1, Ns...>::type;
};

// Recursion abort
template <int ... Ns>
struct seq_gen<0, Ns...>
{
using type = sequence<Ns...>;
using type = sequence<Ns...>;
};

// call functional with arguments in a tuple (implementation)
template <typename FUNC, typename TUPL, int ... INDICES>
inline static auto tuple_call_impl( FUNC &func, TUPL &args, sequence<INDICES...> ) -> decltype( func( std::move( std::get<INDICES>( args ) )... ) )
{
return func( std::move( std::get<INDICES>( args ) )... );
return func( std::move( std::get<INDICES>( args ) )... );
}

// call functional with argumetns packaged in a tuple
template <typename FUNC, typename ... ARGs>
inline static auto tuple_call( FUNC &func, std::tuple<ARGs...> &tup ) ->decltype( tuple_call_impl( func, tup, typename seq_gen<sizeof...(ARGs)>::type{} ) )
{
return tuple_call_impl( func, tup, typename seq_gen<sizeof...(ARGs)>::type{} );
return tuple_call_impl( func, tup, typename seq_gen<sizeof...(ARGs)>::type{} );
}

//-----------------------------------------------------------------------
// Helper class implementing a job containing any functional and its
// arguments.
//-----------------------------------------------------------------------
template<typename FUNC, typename RET, typename ... ARGs>
class AnyJob : public XrdCl::Job
{

static inline void RunImpl( FUNC func, std::tuple<ARGs...> &args, std::promise<void> &prms )
{
tuple_call( func, args );
prms.set_value();
}

template<typename RETURN>
static inline void RunImpl( FUNC func, std::tuple<ARGs...> &args, std::promise<RETURN> &prms )
{
prms.set_value( tuple_call( func, args ) );
}
//---------------------------------------------------------------------
// Run the functional (returning void) with the packaged arguments
//---------------------------------------------------------------------
static inline void RunImpl( FUNC func, std::tuple<ARGs...> &args, std::promise<void> &prms )
{
tuple_call( func, args );
prms.set_value();
}

//---------------------------------------------------------------------
// Run the functional (returning anything but void) with the packaged
// arguments
//---------------------------------------------------------------------
template<typename RETURN>
static inline void RunImpl( FUNC func, std::tuple<ARGs...> &args, std::promise<RETURN> &prms )
{
prms.set_value( tuple_call( func, args ) );
}

public:

//-------------------------------------------------------------------
//! Constructor
//!
//! @param func : functional to be called
//! @param args : arguments for the functional
//-------------------------------------------------------------------
AnyJob( FUNC func, ARGs... args ) : func( std::move( func ) ),
args( std::tuple<ARGs...>( std::move( args )... ) )
{
}

//-------------------------------------------------------------------
//! Run the job
//-------------------------------------------------------------------
void Run( void *arg )
{
RunImpl( this->func, this->args, this->prms );
delete this;
}

//-------------------------------------------------------------------
//! Get the future result of the job
//-------------------------------------------------------------------
std::future<RET> GetFuture()
{
return prms.get_future();
}

protected:

FUNC func;
std::tuple<ARGs...> args;
std::promise<RET> prms;
FUNC func; //< the functional
std::tuple<ARGs...> args; //< the arguments
std::promise<RET> prms; //< the promiss that there will be a result
};

public:

//-----------------------------------------------------------------------
//! Destructor
//-----------------------------------------------------------------------
~ThreadPool()
{
threadpool.Stop();
threadpool.Finalize();
}

//-----------------------------------------------------------------------
//! Singleton access
//-----------------------------------------------------------------------
static ThreadPool& Instance()
{
static ThreadPool instance;
return instance;
}

//-----------------------------------------------------------------------
//! Schedule a functional (together with its arguments) for execution
//-----------------------------------------------------------------------
template<typename FUNC, typename ... ARGs>
inline std::future<typename std::result_of<FUNC(ARGs...)>::type>
Execute( FUNC func, ARGs... args )
Expand All @@ -120,13 +169,16 @@ namespace XrdEc

private:

//-----------------------------------------------------------------------
//! Constructor
//-----------------------------------------------------------------------
ThreadPool() : threadpool( 64 )
{
threadpool.Initialize();
threadpool.Start();
}

XrdCl::JobManager threadpool;
XrdCl::JobManager threadpool; //< the thread-pool itself
};

}
Expand Down

0 comments on commit 4756869

Please sign in to comment.