diff --git a/src/core/model/system-mutex.h b/src/core/model/system-mutex.h --- a/src/core/model/system-mutex.h +++ b/src/core/model/system-mutex.h @@ -58,6 +58,18 @@ class SystemMutex { public: + +#ifndef HAVE_PTHREAD_H + // This minimal implementation is needed for to support compilation + // of the thread-safe Schedule implementation, on systems without + // thread support. + + /** Constructor */ + SystemMutex () { }; + /** Destructor */ + ~SystemMutex () { }; + +#else SystemMutex (); ~SystemMutex (); @@ -74,6 +86,8 @@ private: /** The (system-dependent) implementation. */ SystemMutexPrivate * m_priv; + +#endif /* HAVE_PTHREAD_H */ }; /** @@ -118,6 +132,21 @@ class CriticalSection { public: + +#ifndef HAVE_PTHREAD_H + // This minimal implementation is needed for to support compilation + // of the thread-safe Schedule implementation, on systems without + // thread support. + + /** + * Constructor + * @param [in] mutex The mutex. + */ + CriticalSection (SystemMutex &mutex) { }; + /** Destructor */ + ~CriticalSection () { }; + +#else /* HAVE_PTHREAD_H */ /** * Construct with the required SystemMutex. * @@ -128,7 +157,10 @@ ~CriticalSection (); private: SystemMutex &m_mutex; /**< The mutex. */ -}; + +#endif /* HAVE_PTHREAD_H */ + +}; // class CriticalSection } // namespace ns3 diff --git a/src/core/model/system-thread.h b/src/core/model/system-thread.h --- a/src/core/model/system-thread.h +++ b/src/core/model/system-thread.h @@ -57,10 +57,35 @@ { public: -#ifdef HAVE_PTHREAD_H +#ifndef HAVE_PTHREAD_H + // This minimal implementation is needed for to support compilation + // of the thread-safe Schedule implementation, on systems without + // thread support. + + /** + * Fallback type alias for thread objects + * on systems without thread support. + */ + typedef void * ThreadId; + + /** + * @brief Returns the default thread Id on systems without thread support. + * + * @returns Default thread Id. + */ + static ThreadId Self(void) { return 0; }; + + /** + * @brief Compares ThreadIds on systems without thread support. + * + * @param [in] id The ThreadId to compare to. + * @returns @c true if @c id matches the current ThreadId. + */ + static bool Equals(ThreadId id) { return true; }; + +#else /* HAVE_PTHREAD_H */ /** Type alias for the system-dependent thread object. */ typedef pthread_t ThreadId; -#endif /** * @brief Create a SystemThread object. @@ -157,7 +182,7 @@ static bool Equals(ThreadId id); private: -#ifdef HAVE_PTHREAD_H + /** * Invoke the callback in the new thread. * @@ -168,8 +193,9 @@ Callback m_callback; /**< The main function for this thread when launched. */ pthread_t m_thread; /**< The thread id of the child thread. */ -#endif -}; + +#endif /* HAVE_PTHREAD_H */ +}; // class SystemThread } // namespace ns3 diff --git a/src/core/wscript b/src/core/wscript --- a/src/core/wscript +++ b/src/core/wscript @@ -236,6 +236,13 @@ 'model/watchdog.h', 'model/synchronizer.h', 'model/make-event.h', + + # Include always for compilation + # of the thread-safe Schedule implementation, + # even on systems without thread support. + 'model/system-mutex.h', + 'model/system-thread.h', + 'model/system-wall-clock-ms.h', 'model/empty.h', 'model/callback.h', @@ -350,8 +357,11 @@ core_test.source.extend(['test/threaded-test-suite.cc']) headers.source.extend([ 'model/unix-fd-reader.h', - 'model/system-mutex.h', - 'model/system-thread.h', + # Include always for compilation + # of the thread-safe Schedule implementation, + # on systems without thread support. + # 'model/system-mutex.h', + # 'model/system-thread.h', 'model/system-condition.h', ])