$NetBSD: patch-src_zm_thread_cpp,v 1.2 2013/03/24 16:47:47 joerg Exp $

pthread_mutex_timedlock() is not available on NetBSD 5.0, and not required
in ZoneMinder.

Work around varying notion of an undefined mpid on pthread/not.

--- src/zm_thread.cpp.orig	2018-12-08 14:22:36.000000000 +0000
+++ src/zm_thread.cpp
@@ -69,6 +69,7 @@ void Mutex::lock() {
     throw ThreadException( stringtf( "Unable to lock pthread mutex: %s", strerror(errno) ) );
 }
 
+#if 0
 void Mutex::lock( int secs ) {
   struct timespec timeout = getTimeout( secs );
   if ( pthread_mutex_timedlock( &mMutex, &timeout ) < 0 )
@@ -80,6 +81,7 @@ void Mutex::lock( double secs ) {
   if ( pthread_mutex_timedlock( &mMutex, &timeout ) < 0 )
     throw ThreadException( stringtf( "Unable to timedlock pthread mutex: %s", strerror(errno) ) );
 }
+#endif
 
 void Mutex::unlock() {
   if ( pthread_mutex_unlock( &mMutex ) < 0 )
@@ -218,9 +220,15 @@ template <class T> void ThreadData<T>::u
   Debug(9, "Updated value, %p", this);
 }
 
+#ifndef USE_PTHREAD
+#define MPID_UNDEFINED -1
+#else /* USE_PTHREAD */
+#define MPID_UNDEFINED NULL
+#endif /* USE_PTHREAD */
+
 Thread::Thread() :
   mThreadCondition( mThreadMutex ),
-  mPid( -1 ),
+  mPid( MPID_UNDEFINED ),
   mStarted( false ),
   mRunning( false )
 {
@@ -283,7 +291,7 @@ void Thread::join() {
   if ( isThread() )
     throw ThreadException( "Can't self join thread" );
   mThreadMutex.lock();
-  if ( mPid >= 0 ) {
+  if ( mPid != MPID_UNDEFINED ) {
     if ( mStarted ) {
       void *threadStatus = 0;
       if ( pthread_join( mThread, &threadStatus ) < 0 )
@@ -305,4 +313,5 @@ void Thread::kill( int signal ) {
 }
 
 // Some explicit template instantiations
-#include "zm_threaddata.cpp"
+template class ThreadData<bool>;
+template class ThreadData<int>;
