Fixing compilation on MSWindows

This commit is contained in:
Henrik Rusche 2018-06-11 15:24:51 +02:00
parent 58290b37f5
commit b23dfb3284
11 changed files with 682 additions and 20 deletions

View file

@ -43,6 +43,8 @@ Description
#include <map> #include <map>
// Windows system header files // Windows system header files
// DebugInfo macro defined in messageStream.H clashes with Windows headers
#undef DebugInfo
#include <io.h> // _close #include <io.h> // _close
#include <windows.h> #include <windows.h>
#include <signal.h> #include <signal.h>
@ -372,7 +374,7 @@ string getEnv(const word& envName)
bool setEnv bool setEnv
( (
const word& envName, const word& envName,
const string& value, const std::string& value,
const bool overwrite const bool overwrite
) )
{ {
@ -382,9 +384,8 @@ bool setEnv
} }
word hostName() string hostName(bool full)
{ {
const bool full = true;
const DWORD bufferSize = MAX_COMPUTERNAME_LENGTH + 1; const DWORD bufferSize = MAX_COMPUTERNAME_LENGTH + 1;
TCHAR buffer[bufferSize]; TCHAR buffer[bufferSize];
DWORD actualBufferSize = bufferSize; DWORD actualBufferSize = bufferSize;
@ -392,6 +393,17 @@ word hostName()
const bool success = const bool success =
::GetComputerName(buffer, &actualBufferSize); ::GetComputerName(buffer, &actualBufferSize);
const string computerName = success ? buffer : string::null; const string computerName = success ? buffer : string::null;
// implementation as per hostname from net-tools
if (full)
{
struct hostent *hp = gethostbyname(computerName.c_str());
if (hp)
{
return hp->h_name;
}
}
return computerName; return computerName;
} }
@ -405,7 +417,7 @@ string domainName()
} }
word userName() string userName()
{ {
std::string name = getEnv("USERNAME"); std::string name = getEnv("USERNAME");
@ -438,7 +450,7 @@ fileName home()
} }
fileName home(const word& userName) fileName home(const string& userName)
{ {
return home(); return home();
} }
@ -1287,7 +1299,7 @@ void* dlOpen(const fileName& libName, const bool check)
// Assumes libName = name // Assumes libName = name
winLibName = "lib"; winLibName = "lib";
winLibName += libName; winLibName += libName;
winLibName += dllExt; winLibName += ".dll";
handle = ::LoadLibrary(winLibName.c_str()); handle = ::LoadLibrary(winLibName.c_str());
} }

View file

@ -9,6 +9,17 @@ MSwindows.C
cpuTime/cpuTime.C cpuTime/cpuTime.C
clockTime/clockTime.C clockTime/clockTime.C
multiThreader/multiThreader.C multiThreader/multiThreader.C
/*
* Note: fileMonitor assumes inotify by default. Compile with -DFOAM_USE_STAT
* to use stat (=timestamps) instead of inotify
*/
fileMonitor.C
#ifdef SunOS64
dummyPrintStack.C
#else
printStack.C printStack.C
#endif
LIB = $(FOAM_LIBBIN)/libOSspecific LIB = $(FOAM_LIBBIN)/libOSspecific

View file

@ -0,0 +1,427 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.1
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "fileMonitor.H"
#include "IOstreams.H"
#include "Pstream.H"
#include "PackedList.H"
#include "PstreamReduceOps.H"
#include "OSspecific.H"
#include "regIOobject.H" // for fileModificationSkew symbol
#ifdef FOAM_USE_INOTIFY
# error "fileMonitor.C: FOAM_USE_INOTIFY is not supported on MSWindows"
#else
# include "OSspecific.H"
#endif
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::NamedEnum<Foam::fileMonitor::fileState, 3>
Foam::fileMonitor::fileStateNames_;
namespace Foam
{
defineTypeNameAndDebug(fileMonitor, 0);
template<>
const char* Foam::NamedEnum
<
Foam::fileMonitor::fileState,
3
>::names[] =
{
"unmodified",
"modified",
"deleted"
};
//- Reduction operator for PackedList of fileState
class reduceFileStates
{
public:
unsigned int operator()(const unsigned int x, const unsigned int y)
const
{
// x,y are sets of 2bits representing fileState
unsigned int mask = 3u;
unsigned int shift = 0;
unsigned int result = 0;
while (mask)
{
// Combine state
unsigned int xState = (x & mask) >> shift;
unsigned int yState = (y & mask) >> shift;
// Combine and add to result. Combine is such that UNMODIFIED
// wins.
unsigned int state = min(xState, yState);
result |= (state << shift);
shift += 2;
mask <<= 2;
}
return result;
}
};
//- Combine operator for PackedList of fileState
class combineReduceFileStates
{
public:
void operator()(unsigned int& x, const unsigned int y) const
{
x = reduceFileStates()(x, y);
}
};
//- Internal tracking via stat(3p) or inotify(7)
class fileMonitorWatcher
{
public:
const bool useInotify_;
// For inotify
//- File descriptor for the inotify instance
int inotifyFd_;
//- Current watchIDs and corresponding directory id
DynamicList<label> dirWatches_;
DynamicList<fileName> dirFiles_;
// For stat
//- From watch descriptor to modified time
DynamicList<time_t> lastMod_;
//- Initialise inotify
inline fileMonitorWatcher(const bool useInotify, const label sz = 20)
:
useInotify_(useInotify),
inotifyFd_(-1)
{
if (useInotify_)
{
FatalErrorIn("fileMonitorWatcher(const bool, const label)")
<< "You selected inotify but this file was compiled"
<< " without FOAM_USE_INOTIFY"
<< " Please select another fileModification test method"
<< exit(FatalError);
}
else
{
lastMod_.setCapacity(sz);
}
}
//- Remove all watches
inline ~fileMonitorWatcher()
{
}
inline bool addWatch(const label watchFd, const fileName& fName)
{
{
if (watchFd < lastMod_.size() && lastMod_[watchFd] != 0)
{
// Reuse of watchFd : should have lastMod set to 0.
FatalErrorIn("addWatch(const label, const fileName&)")
<< "Problem adding watch " << watchFd
<< " to file " << fName
<< abort(FatalError);
}
lastMod_(watchFd) = lastModified(fName);
}
return true;
}
inline bool removeWatch(const label watchFd)
{
if (useInotify_)
{
if (inotifyFd_ < 0)
{
return false;
}
dirWatches_[watchFd] = -1;
}
else
{
lastMod_[watchFd] = 0;
}
return true;
}
};
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fileMonitor::checkFiles() const
{
{
forAll(watcher_->lastMod_, watchFd)
{
time_t oldTime = watcher_->lastMod_[watchFd];
if (oldTime != 0)
{
const fileName& fName = watchFile_[watchFd];
time_t newTime = lastModified(fName);
if (newTime == 0)
{
localState_[watchFd] = DELETED;
}
else
{
if (newTime > (oldTime + regIOobject::fileModificationSkew()))
{
localState_[watchFd] = MODIFIED;
}
else
{
localState_[watchFd] = UNMODIFIED;
}
}
}
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileMonitor::fileMonitor(const bool useInotify)
:
useInotify_(useInotify),
localState_(20),
state_(20),
watchFile_(20),
freeWatchFds_(2),
watcher_(new fileMonitorWatcher(useInotify_, 20))
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fileMonitor::~fileMonitor()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Note: fName might not exist (on slaves if in master-only mode for
// regIOobject)
Foam::label Foam::fileMonitor::addWatch(const fileName& fName)
{
label watchFd;
label sz = freeWatchFds_.size();
if (sz)
{
watchFd = freeWatchFds_[sz-1];
freeWatchFds_.setSize(sz-1);
}
else
{
watchFd = state_.size();
}
watcher_->addWatch(watchFd, fName);
if (debug)
{
Pout<< "fileMonitor : added watch " << watchFd << " on file "
<< fName << endl;
}
if (watchFd < 0)
{
WarningIn("fileMonitor::addWatch(const fileName&)")
<< "could not add watch for file " << fName << endl;
}
else
{
localState_(watchFd) = UNMODIFIED;
state_(watchFd) = UNMODIFIED;
watchFile_(watchFd) = fName;
}
return watchFd;
}
bool Foam::fileMonitor::removeWatch(const label watchFd)
{
if (debug)
{
Pout<< "fileMonitor : removing watch " << watchFd << " on file "
<< watchFile_[watchFd] << endl;
}
freeWatchFds_.append(watchFd);
return watcher_->removeWatch(watchFd);
}
const Foam::fileName& Foam::fileMonitor::getFile(const label watchFd) const
{
return watchFile_[watchFd];
}
Foam::fileMonitor::fileState Foam::fileMonitor::getState(const label watchFd)
const
{
return state_[watchFd];
}
void Foam::fileMonitor::updateStates
(
const bool masterOnly,
const bool syncPar
) const
{
if (Pstream::master() || !masterOnly)
{
// Update the localState_
checkFiles();
}
if (syncPar)
{
// Pack local state (might be on master only)
PackedList<2> stats(state_.size(), MODIFIED);
if (Pstream::master() || !masterOnly)
{
forAll(state_, watchFd)
{
stats[watchFd] = static_cast<unsigned int>
(
localState_[watchFd]
);
}
}
// Scatter or reduce to synchronise state
if (masterOnly)
{
// Scatter
if (stats.storage().size() == 1)
{
Pstream::scatter(stats.storage()[0]);
}
else
{
Pstream::listCombineScatter(stats.storage());
}
}
else
{
// Reduce
if (stats.storage().size() == 1)
{
// Optimisation valid for most cases.
reduce(stats.storage()[0], reduceFileStates());
}
else
{
Pstream::listCombineGather
(
stats.storage(),
combineReduceFileStates()
);
}
}
// Update synchronised state
forAll(state_, watchFd)
{
// Assign synchronised state
unsigned int stat = stats[watchFd];
state_[watchFd] = fileState(stat);
if (!masterOnly)
{
// Give warning for inconsistent state
if (state_[watchFd] != localState_[watchFd])
{
if (debug)
{
Pout<< "fileMonitor : Delaying reading "
<< watchFile_[watchFd]
<< " due to inconsistent "
"file time-stamps between processors"
<< endl;
}
WarningIn
(
"fileMonitor::updateStates"
"(const bool, const bool) const"
) << "Delaying reading " << watchFile_[watchFd]
<< " due to inconsistent "
"file time-stamps between processors" << endl;
}
}
}
}
else
{
state_ = localState_;
}
}
void Foam::fileMonitor::setUnmodified(const label watchFd)
{
state_[watchFd] = UNMODIFIED;
localState_[watchFd] = UNMODIFIED;
if (!useInotify_)
{
watcher_->lastMod_[watchFd] = lastModified(watchFile_[watchFd]);
}
}
// ************************************************************************* //

View file

@ -0,0 +1,166 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 4.1
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::fileMonitor
Description
Checking for changes to files.
Note
The default is to use stat to get the timestamp.
Consider to use
FindFirstChangeNotification,
FindNextChangeNotification,
ReadDirectoryChangesW.
More info here:
http://msdn.microsoft.com/en-us/library/aa365261(VS.85).aspx
to re-implement inotify on MSWindows
SourceFiles
fileMonitor.C
\*---------------------------------------------------------------------------*/
#ifndef fileMonitor_H
#define fileMonitor_H
#include <sys/types.h>
#include "NamedEnum.H"
#include "className.H"
#include "DynamicList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class fileMonitor;
class fileMonitorWatcher;
/*---------------------------------------------------------------------------*\
Class fileMonitor Declaration
\*---------------------------------------------------------------------------*/
class fileMonitor
{
public:
// Public data types
//- Enumeration defining the file state.
enum fileState
{
UNMODIFIED = 0,
MODIFIED = 1,
DELETED = 2
};
static const NamedEnum<fileState, 3> fileStateNames_;
private:
// Private data
//- Whether to use inotify (requires -DFOAM_USE_INOTIFY, see above)
const bool useInotify_;
//- State for all watchFds based on local files
mutable DynamicList<fileState> localState_;
//- State for all watchFds - synchronised
mutable DynamicList<fileState> state_;
//- Filename for all watchFds
DynamicList<fileName> watchFile_;
//- Free watchFds
DynamicList<label> freeWatchFds_;
//- Watch mechanism (stat or inotify)
mutable autoPtr<fileMonitorWatcher> watcher_;
// Private Member Functions
//- Update localState_ from any events.
void checkFiles() const;
//- Disallow default bitwise copy construct
fileMonitor(const fileMonitor&);
//- Disallow default bitwise assignment
void operator=(const fileMonitor&);
public:
// Declare name of the class and its debug switch
ClassName("fileMonitor");
// Constructors
//- Construct null
fileMonitor(const bool useInotify);
//- Destructor
~fileMonitor();
// Member Functions
//- Add file to watch. Return watch descriptor
label addWatch(const fileName&);
//- Remove file to watch. Return true if successful
bool removeWatch(const label watchFd);
//- Get name of file being watched
const fileName& getFile(const label watchFd) const;
//- Check state using handle
fileState getState(const label watchFd) const;
//- Check state of all files. Updates state_.
void updateStates
(
const bool masterOnly,
const bool syncPar
) const;
//- Reset state (e.g. after having read it) using handle
void setUnmodified(const label watchFd);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -11,7 +11,8 @@ LIB_LIBS = $(PLIBS)\
-L$(WM_THIRD_PARTY_DIR)/packages/system/lib \ -L$(WM_THIRD_PARTY_DIR)/packages/system/lib \
-ldl \ -ldl \
-lpsapi \ -lpsapi \
-lpthread -lpthread \
-lws2_32
#else #else

View file

@ -279,7 +279,7 @@ extern messageStream Info;
//- Report write to Foam::Info if the local log switch is true //- Report write to Foam::Info if the local log switch is true
#define Log \ #define Log \
if (log) Info if (log) ::Foam::Info
//- Report an IO information message using Foam::Info //- Report an IO information message using Foam::Info
@ -297,7 +297,7 @@ extern messageStream Info;
//- Report an information message using Foam::Info //- Report an information message using Foam::Info
// if the local debug switch is true // if the local debug switch is true
#define DebugInfo \ #define DebugInfo \
if (debug) Info if (debug) ::Foam::Info
//- Report an information message using Foam::Info //- Report an information message using Foam::Info
// for FUNCTION_NAME in file __FILE__ at line __LINE__ // for FUNCTION_NAME in file __FILE__ at line __LINE__

View file

@ -50,6 +50,32 @@ inline long double ynl(const int n, const float s) { return double(yn(n, double(
#endif #endif
#endif // darwin #endif // darwin
#if defined(mingw)
#ifndef DUMMY_SCALAR_FUNCTIONS
#define DUMMY_SCALAR_FUNCTIONS
inline float j0f(float x) { return _j0(x); }
inline float j1f(float x) { return _j1(x); }
inline float y0f(float x) { return _y0(x); }
inline float y1f(float x) { return _y1(x); }
inline float jnf(const int n, float s) { return _jn(n, s); }
inline float ynf(const int n, float s) { return _yn(n, s); }
inline double j0(double x) { return _j0(x); }
inline double j1(double x) { return _j1(x); }
inline double y0(double x) { return _y0(x); }
inline double y1(double x) { return _y1(x); }
inline double jn(const int n, double s) { return _jn(n, s); }
inline double yn(const int n, double s) { return _yn(n, s); }
inline long double j0l(long double x) { return _j0(x); }
inline long double j1l(long double x) { return _j1(x); }
inline long double y0l(long double x) { return _y0(x); }
inline long double y1l(long double x) { return _y1(x); }
inline long double jnl(const int n, long double s) { return _jn(n, s); }
inline long double ynl(const int n, long double s) { return _yn(n, s); }
#endif
#endif // mingw
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam

View file

@ -74,6 +74,11 @@ Ostream& operator<<(Ostream&, const int64_t);
Ostream& operator<<(Ostream&, const long); Ostream& operator<<(Ostream&, const long);
#endif #endif
#if defined(mingw)
Istream& operator>>(Istream&, off_t&);
Ostream& operator<<(Ostream&, const off_t);
#endif
//- Template specialization for pTraits<int64_t> //- Template specialization for pTraits<int64_t>
template<> template<>
class pTraits<int64_t> class pTraits<int64_t>

View file

@ -114,4 +114,18 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const long i)
} }
#endif #endif
#if defined(mingw)
Foam::Istream& Foam::operator>>(Istream& is, off_t& i)
{
return operator>>(is, i);
}
Foam::Ostream& Foam::operator<<(Ostream& os, const off_t i)
{
os << i;
return os;
}
#endif
// ************************************************************************* // // ************************************************************************* //

View file

@ -67,7 +67,7 @@ MAXMIN(uint64_t, uint64_t, uint64_t)
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
uint readUint(Istream&); unsigned int readUint(Istream&);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View file

@ -9,14 +9,14 @@ include $(RULES)/c++$(WM_COMPILE_OPTION)
ptFLAGS = -DNoRepository -ftemplate-depth-200 ptFLAGS = -DNoRepository -ftemplate-depth-200
GFLAGS = -DWM_$(WM_PRECISION_OPTION) -DWM_LABEL_SIZE=$(WM_LABEL_SIZE) GFLAGS = -DWM_$(WM_PRECISION_OPTION) -DWM_LABEL_SIZE=$(WM_LABEL_SIZE)
c++FLAGS = $(GFLAGS) $(c++WARN) $(c++OPT) $(c++DBUG) $(ptFLAGS) $(LIB_HEADER_DIRS) -I$(OPENMPI_DIR)/include -I$(WM_THIRD_PARTY_DIR)/packages/system/include -Dmingw -DBIG_ENDIAN=0 -DLITTLE_ENDIAN=1 -DBYTE_ORDER=BIG_ENDIAN c++FLAGS = $(GFLAGS) $(c++WARN) $(c++OPT) $(c++DBUG) $(ptFLAGS) $(LIB_HEADER_DIRS) -I$(OPENMPI_DIR)/include -I$(WM_THIRD_PARTY_DIR)/packages/system/include -Dmingw -DBIG_ENDIAN=0 -DLITTLE_ENDIAN=1 -DBYTE_ORDER=BIG_ENDIAN -U__STRICT_ANSI__
Ctoo = $(WM_SCHEDULER) $(CC) $(c++FLAGS) -c $$SOURCE -o $@ Ctoo = $(WM_SCHEDULER) $(CC) $(c++FLAGS) -c $$SOURCE -o $@
cxxtoo = $(Ctoo) cxxtoo = $(Ctoo)
cctoo = $(Ctoo) cctoo = $(Ctoo)
cpptoo = $(Ctoo) cpptoo = $(Ctoo)
LINK_LIBS = $(c++DBUG) -L$(OPENMPI_DIR)/lib -lmpi -lpthread -lz -L$(WM_THIRD_PARTY_DIR)/packages/system/lib -ldl -lpsapi LINK_LIBS = $(c++DBUG) -L$(OPENMPI_DIR)/lib -lmpi -lpthread -lz -L$(WM_THIRD_PARTY_DIR)/packages/system/lib -ldl -lpsapi -lws2_32
LINKLIBSO = $(CC) $(c++FLAGS) -shared -Xlinker --add-needed -Xlinker --no-as-needed LINKLIBSO = $(CC) $(c++FLAGS) -shared -Xlinker --add-needed -Xlinker --no-as-needed
LINKEXE = $(CC) $(c++FLAGS) -Xlinker --add-needed -Xlinker --no-as-needed $(FOAM_LIBBIN)/libOSspecific.o LINKEXE = $(CC) $(c++FLAGS) -Xlinker --add-needed -Xlinker --no-as-needed $(FOAM_LIBBIN)/libOSspecific.o