Commit a336e284 authored by Victor Kotlyar's avatar Victor Kotlyar
Browse files

Removed unused castor::server:: classes

Replaced castor file header with CTA file header

Moved castor::server::
  BlockingQueue
  Semaphores
  AtomicCounter
  AtomicFlag
into cta::threading::
parent e00de2de
......@@ -108,6 +108,7 @@ set (COMMON_LIB_SRC_FILES
threading/SocketPair.cpp
threading/System.cpp
threading/Threading.cpp
threading/Semaphores.cpp
utils/utils.cpp
utils/strerror_r_wrapper.cpp
CreationLog.cpp
......
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "castor/server/MutexLocker.hpp"
#include "castor/server/Threading.hpp"
#include "common/threading/MutexLocker.hpp"
#include "common/threading/Threading.hpp"
namespace castor {
namespace server {
namespace cta {
namespace threading {
/**
* A helper class managing a thread safe message counter
* When C++11 will be used, just delete it to use std::atomic
......@@ -36,24 +31,24 @@ namespace server {
template <class T> struct AtomicCounter{
AtomicCounter(T init = 0): m_val(init) {};
T operator ++ () {
MutexLocker ml(&m_mutex);
MutexLocker ml(m_mutex);
return ++m_val;
}
T operator ++ (int) {
MutexLocker ml(&m_mutex);
MutexLocker ml(m_mutex);
return m_val++;
}
T operator -- () {
MutexLocker ml(&m_mutex);
MutexLocker ml(m_mutex);
return --m_val;
}
operator T() const {
MutexLocker ml(&m_mutex);
MutexLocker ml(m_mutex);
return m_val;
}
T getAndReset(){
MutexLocker ml(&m_mutex);
MutexLocker ml(m_mutex);
T old =m_val;
m_val=0;
return old;
......@@ -62,6 +57,6 @@ template <class T> struct AtomicCounter{
T m_val;
mutable Mutex m_mutex;
};
}}
} // namespace threading
} // namespace cta
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "castor/server/MutexLocker.hpp"
#include "castor/server/Threading.hpp"
#include "common/threading/MutexLocker.hpp"
#include "common/threading/Threading.hpp"
namespace castor {
namespace server {
namespace cta {
namespace threading {
//A 1 way flag : Once set, it can be reset
struct AtomicFlag{
AtomicFlag(): m_set(false) {};
void set() {
MutexLocker ml(&m_mutex);
MutexLocker ml(m_mutex);
m_set=true;
}
operator bool() const {
MutexLocker ml(&m_mutex);
MutexLocker ml(m_mutex);
return m_set;
}
private:
......@@ -46,4 +41,5 @@ struct AtomicFlag{
mutable Mutex m_mutex;
};
}}
} // namespace threading
} // namespace cta
\ No newline at end of file
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
/*
* Author: dcome
*
* Created on March 5, 2014, 5:06 PM
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
......@@ -31,12 +21,12 @@
#include <queue>
#include <exception>
#include "castor/server/MutexLocker.hpp"
#include "castor/server/Threading.hpp"
#include "castor/server/Semaphores.hpp"
#include "common/threading/MutexLocker.hpp"
#include "common/threading/Threading.hpp"
#include "common/threading/Semaphores.hpp"
namespace castor {
namespace server {
namespace cta {
namespace threading {
/***
* This simple class provides a thread-safe blocking queue
......@@ -61,7 +51,7 @@ public:
*/
void push(const C& e) {
{
MutexLocker ml(&m_mutex);
MutexLocker ml(m_mutex);
m_queue.push(e);
}
m_sem.release();
......@@ -92,7 +82,7 @@ public:
* return the number of elements currently in the queue
*/
size_t size() const {
MutexLocker ml(&m_mutex);
MutexLocker ml(m_mutex);
return m_queue.size();
}
......@@ -117,7 +107,7 @@ private:
* of the queue after pop
*/
C popCriticalSection(size_t * sz = NULL) {
MutexLocker ml(&m_mutex);
MutexLocker ml(m_mutex);
C ret = m_queue.front();
m_queue.pop();
if (sz)
......@@ -127,4 +117,5 @@ private:
};
}}
} // namespace threading
} // namespace cta
\ No newline at end of file
......@@ -16,35 +16,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "ChildProcess.hpp"
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
void cta::threading::ChildProcess::start(Cleanup & cleanup) {
namespace cta {
namespace threading {
void ChildProcess::start(Cleanup & cleanup) {
m_pid = fork();
if (!m_pid) {
/* We are the child process. Do our stuff and exit. */
......@@ -58,7 +38,7 @@ void cta::threading::ChildProcess::start(Cleanup & cleanup) {
m_started = true;
}
void cta::threading::ChildProcess::parseStatus(int status) {
void ChildProcess::parseStatus(int status) {
if (WIFEXITED(status)) {
m_finished = true;
m_exited = true;
......@@ -69,7 +49,7 @@ void cta::threading::ChildProcess::parseStatus(int status) {
}
}
bool cta::threading::ChildProcess::running() {
bool ChildProcess::running() {
/* Checking for a running process before starting gets an exception */
if (!m_started) throw ProcessNeverStarted();
/* If we are not aware of process exiting, let's check and collect exit code */
......@@ -84,7 +64,7 @@ bool cta::threading::ChildProcess::running() {
return !m_finished;
}
void cta::threading::ChildProcess::wait() {
void ChildProcess::wait() {
/* Checking for a running process before starting gets an exception */
if (!m_started) throw ProcessNeverStarted();
if (m_finished) return;
......@@ -98,7 +78,7 @@ void cta::threading::ChildProcess::wait() {
throw cta::exception::Exception("Process did not exit after waitpid().");
}
int cta::threading::ChildProcess::exitCode() {
int ChildProcess::exitCode() {
if (!m_started) throw ProcessNeverStarted();
if (!m_finished) {
int status, ret;
......@@ -117,7 +97,10 @@ int cta::threading::ChildProcess::exitCode() {
return m_exitCode;
}
void cta::threading::ChildProcess::kill() {
void ChildProcess::kill() {
if (!m_started) throw ProcessNeverStarted();
::kill(m_pid, SIGTERM);
}
} // namespace threading
} // namespace cta
\ No newline at end of file
......@@ -16,28 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include "common/exception/Errnum.hpp"
......@@ -115,4 +93,6 @@ namespace threading {
virtual int run() = 0;
void parseStatus(int status);
};
}}
} // namespace threading
} // namespace cta
/*******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author Castor Dev team, castor-dev@cern.ch
******************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/exception/Errnum.hpp"
#include "common/threading/Daemon.hpp"
......
/*******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author Castor Dev team, castor-dev@cern.ch
******************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
......
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/log/DummyLogger.hpp"
#include "common/threading/Daemon.hpp"
......
......@@ -20,10 +20,13 @@
#include "common/exception/Errnum.hpp"
#include "common/exception/Exception.hpp"
namespace cta {
namespace threading {
//------------------------------------------------------------------------------
//constructor
//------------------------------------------------------------------------------
cta::threading::Mutex::Mutex() {
Mutex::Mutex() {
pthread_mutexattr_t attr;
cta::exception::Errnum::throwOnReturnedErrno(
pthread_mutexattr_init(&attr),
......@@ -46,13 +49,13 @@ cta::threading::Mutex::Mutex() {
//------------------------------------------------------------------------------
//destructor
//------------------------------------------------------------------------------
cta::threading::Mutex::~Mutex() {
Mutex::~Mutex() {
pthread_mutex_destroy(&m_mutex);
}
//------------------------------------------------------------------------------
//lock
//------------------------------------------------------------------------------
void cta::threading::Mutex::lock() {
void Mutex::lock() {
cta::exception::Errnum::throwOnReturnedErrno(
pthread_mutex_lock(&m_mutex),
"Error from pthread_mutex_lock in cta::threading::Mutex::lock()");
......@@ -60,8 +63,11 @@ void cta::threading::Mutex::lock() {
//------------------------------------------------------------------------------
//unlock
//------------------------------------------------------------------------------
void cta::threading::Mutex::unlock() {
void Mutex::unlock() {
cta::exception::Errnum::throwOnReturnedErrno(
pthread_mutex_unlock(&m_mutex),
"Error from pthread_mutex_unlock in cta::threading::Mutex::unlock()");
}
} // namespace threading
} // namespace cta
\ No newline at end of file
......@@ -16,29 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
* Payload.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include <pthread.h>
......@@ -46,17 +23,20 @@
namespace cta {
namespace threading {
/**
* A simple exception throwing wrapper for pthread mutexes.
* Inspired from the interface of Qt.
*/
class Mutex {
public:
Mutex() ;
~Mutex();
void lock() ;
void unlock();
private:
pthread_mutex_t m_mutex;
};
}}
/**
* A simple exception throwing wrapper for pthread mutexes.
* Inspired from the interface of Qt.
*/
class Mutex {
public:
Mutex() ;
~Mutex();
void lock() ;
void unlock();
private:
pthread_mutex_t m_mutex;
};
} // namespace threading
} // namespace cta
......@@ -22,7 +22,8 @@
#include <pthread.h>
#include <semaphore.h>
namespace cta { namespace threading {
namespace cta {
namespace threading {
/**
* A simple scoped locker for mutexes. Highly recommended as
......@@ -61,4 +62,5 @@ private:
}; // class MutexLocker
}} // namespace cta::threading
} // namespace threading
} // namespace cta
#include "castor/server/MutexLocker.hpp"
#include "castor/server/Semaphores.hpp"
#include "castor/server/Threading.hpp"
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/threading/MutexLocker.hpp"
#include "common/threading/Semaphores.hpp"