diff --git a/.gitattributes b/.gitattributes index 9b8f53dffb42572f4b5d6f9de0ef0ed6e8553299..ed275413234cf606a09d534d4879af055fb4d82a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -897,6 +897,7 @@ MAC/APL/PAC/ITRFCalServer/src/LBACalibration.cc -text MAC/APL/PAC/ITRFCalServer/src/LBACalibration.h -text MAC/APL/PAC/ITRFCalServer/src/RequestPool.cc -text MAC/APL/PAC/ITRFCalServer/src/RequestPool.h -text +MAC/APL/PAC/ITRFCalServer/src/SharedResource.h -text MAC/APL/PAC/ITRFCalServer/src/SourceCatalog.conf.in -text MAC/APL/PAC/ITRFCalServer/src/SubArrayMgr.cc -text MAC/APL/PAC/ITRFCalServer/src/SubArrayMgr.h -text diff --git a/MAC/APL/PAC/ITRFCalServer/src/CMakeLists.txt b/MAC/APL/PAC/ITRFCalServer/src/CMakeLists.txt index 889eb121d945b28cf4c02a2acd9e5f6a2f50d1fa..00388e8e44beb98174b1bcd50cdd785739198260 100644 --- a/MAC/APL/PAC/ITRFCalServer/src/CMakeLists.txt +++ b/MAC/APL/PAC/ITRFCalServer/src/CMakeLists.txt @@ -32,7 +32,7 @@ target_link_libraries(iCalServer ${CMAKE_CURRENT_BINARY_DIR}/../../LBA_Calibration/src/liblba_calibration.so /usr/local/matlab-2008a/bin/glnx86/libmwmclmcrrt.so) -foreach(file CalServer.conf SourceCatalog.conf) +foreach(file iCalServer.conf SourceCatalog.conf) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/${file}.in ${CMAKE_CURRENT_BINARY_DIR}/${file}) diff --git a/MAC/APL/PAC/ITRFCalServer/src/SharedResource.h b/MAC/APL/PAC/ITRFCalServer/src/SharedResource.h new file mode 100644 index 0000000000000000000000000000000000000000..103008aae7bbd560e4ebda8585c729dd7c4c2f9e --- /dev/null +++ b/MAC/APL/PAC/ITRFCalServer/src/SharedResource.h @@ -0,0 +1,146 @@ +//# -*- mode: c++ -*- +//# SharedResource.h: Locking for shared resources. Not thread safe. +//# +//# Copyright (C) 2002-2004 +//# ASTRON (Netherlands Foundation for Research in Astronomy) +//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl +//# +//# 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 +//# +//# $Id: SharedResource.h 10637 2007-11-05 10:37:26Z overeem $ + +#ifndef SHAREDRESOURCE_H_ +#define SHAREDRESOURCE_H_ + +#define CHECK_LOCKS + +#ifdef CHECK_LOCKS +#undef PACKAGE +#undef VERSION +#include <lofar_config.h> +#include <Common/LofarLogger.h> +#endif + +#include <pthread.h> + +namespace LOFAR { + namespace ICAL { + +class SharedResource +{ +public: + explicit SharedResource(int maxreaders = 1, int maxwriters = 1) : + itsSemaphore(0), + itsMaxreaders(maxreaders), + itsMaxwriters(maxwriters) + { + (void)pthread_mutex_init(&itsMutex, 0); + } + virtual ~SharedResource() {} + + inline int mutex_lock() { return pthread_mutex_lock(&itsMutex); } + inline int mutex_unlock() { return pthread_mutex_unlock(&itsMutex); } + + /*@{*/ + // Lock the resource for reading or writing. + // @return true if the locking succeeded, false otherwise. + inline bool writeLock() { + mutex_lock(); + int success = itsSemaphore; + if (itsSemaphore <= 0 && itsSemaphore > -itsMaxwriters) + itsSemaphore--; + success -= itsSemaphore; + mutex_unlock(); + return success; + } + + inline bool readLock() { + mutex_lock(); + int success = itsSemaphore; + if (itsSemaphore >= 0 && itsSemaphore < itsMaxreaders) + itsSemaphore++; + success -= itsSemaphore; + mutex_unlock(); + return success; + } + /*@}*/ + + /*@{*/ + // Unlock the resource. + inline void writeUnlock() { + mutex_lock(); + itsSemaphore++; + if (itsSemaphore > 0) { +#ifdef CHECK_LOCKS + LOG_WARN("no matching writeLock for writeUnlock"); +#endif + itsSemaphore = 0; + } + mutex_unlock(); + } + + inline void readUnlock() { + mutex_lock(); + itsSemaphore--; + if (itsSemaphore < 0) { +#ifdef CHECK_LOCKS + LOG_WARN("no matching readLock for readUnlock"); +#endif + itsSemaphore = 0; + } + mutex_unlock(); + } + /*@}*/ + + /*@{*/ + // Check whether the resource is locked for + // reading or writing, or for reading + // @return true if the resource is locked, false otherwise. + bool isLocked() { + bool success; + mutex_lock(); + success = (0 != itsSemaphore); + mutex_unlock(); + return success; + } + + bool isWriteLocked() { + mutex_lock(); + bool success; + success = (itsSemaphore < 0); + mutex_unlock(); + return success; + } + + bool isReadLocked() { + mutex_lock(); + bool success; + success = (itsSemaphore > 0); + mutex_unlock(); + return success; + } + +private: + int itsSemaphore; + int itsMaxreaders; + int itsMaxwriters; + pthread_mutex_t itsMutex; +}; + + }; // namespace ICAL +}; // namespace LOFAR + +#endif /* SHAREDRESOURCE_H_ */ + diff --git a/MAC/APL/PAC/ITRFCalServer/src/iCalServer.conf.in b/MAC/APL/PAC/ITRFCalServer/src/iCalServer.conf.in index f8fb82e2b37318bd81170d1f691c5877dc50c83f..e2dc3b002ff9a313282b1ae6eb3984c8c1f21ff5 100644 --- a/MAC/APL/PAC/ITRFCalServer/src/iCalServer.conf.in +++ b/MAC/APL/PAC/ITRFCalServer/src/iCalServer.conf.in @@ -10,8 +10,9 @@ CalServer.firstSubband=1 CalServer.lastSubband=511 # -# Set name for various configuration files -CalServer.SourceCatalogFile=SourceCatalog.conf +# setup values for the Baseline Restriction +CalServer.relativeBRinWaves = 4 +CalServer.maxAbsBRinMeters = 10 # # For testing purposes, read ACC from file