[PD-cvs] externals/grill/flext/source flext.h,1.16,1.17 flprefix.h,1.23,1.24 flsupport.h,1.54,1.55 flthr.cpp,1.20,1.21

xovo at users.sourceforge.net xovo at users.sourceforge.net
Thu Nov 13 04:33:11 CET 2003


Update of /cvsroot/pure-data/externals/grill/flext/source
In directory sc8-pr-cvs1:/tmp/cvs-serv14274/source

Modified Files:
	flext.h flprefix.h flsupport.h flthr.cpp 
Log Message:
 ""

Index: flext.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flext.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** flext.h	5 Aug 2003 02:32:31 -0000	1.16
--- flext.h	13 Nov 2003 03:33:09 -0000	1.17
***************
*** 45,49 ****
--- 45,51 ----
  		#include <multiprocessing.h>
  	#elif FLEXT_THREADS == FLEXT_THR_WIN32
+         #define _WIN32_WINNT 0x500 // must be WIN2000 at least!
  		#include <windows.h>
+         #include <process.h>
  	#else
  		#error "Thread model not supported"

Index: flprefix.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flprefix.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** flprefix.h	17 Sep 2003 02:32:55 -0000	1.23
--- flprefix.h	13 Nov 2003 03:33:09 -0000	1.24
***************
*** 336,341 ****
  	#undef FLEXT_THREADS
  	#if FLEXT_OS == FLEXT_OS_MAC && FLEXT_SYS == FLEXT_SYS_MAX
! 		// Max crashes with posix threads (but don't know why...)
  		#define FLEXT_THREADS FLEXT_THR_MP		
  	#else
  		#define FLEXT_THREADS FLEXT_THR_POSIX
--- 336,344 ----
  	#undef FLEXT_THREADS
  	#if FLEXT_OS == FLEXT_OS_MAC && FLEXT_SYS == FLEXT_SYS_MAX
! 		// Max crashes with posix threads (because it's in the CFM model)
  		#define FLEXT_THREADS FLEXT_THR_MP		
+ 	#elif FLEXT_SYS == FLEXT_SYS_MAX && FLEXT_OS == FLEXT_OS_WIN
+ 		// for wmax use native Windows threads
+ 		#define FLEXT_THREADS FLEXT_THR_WIN32
  	#else
  		#define FLEXT_THREADS FLEXT_THR_POSIX

Index: flsupport.h
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flsupport.h,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** flsupport.h	12 Nov 2003 03:35:19 -0000	1.54
--- flsupport.h	13 Nov 2003 03:33:09 -0000	1.55
***************
*** 637,640 ****
--- 637,642 ----
  #elif FLEXT_THREADS == FLEXT_THR_POSIX
  	typedef pthread_t thrid_t;
+ #elif FLEXT_THREADS == FLEXT_THR_WIN32
+     typedef DWORD thrid_t;
  #else
  #error
***************
*** 648,651 ****
--- 650,655 ----
  #elif FLEXT_THREADS == FLEXT_THR_MP
  		return MPCurrentTaskID();
+ #elif FLEXT_THREADS == FLEXT_THR_WIN32
+ 		return GetCurrentThreadId();
  #else
  #error
***************
*** 661,664 ****
--- 665,670 ----
  #if FLEXT_THREADS == FLEXT_THR_POSIX
  		return pthread_equal(ref,t) != 0; 
+ #elif FLEXT_THREADS == FLEXT_THR_WIN32
+         return ref == t; 
  #else
  		return ref == t;
***************
*** 728,731 ****
--- 734,738 ----
  	static bool StopHelper();
  	static void ThrHelper(void *);
+     static void LaunchHelper(thr_entry *e);
  
  	//! the system's thread id
***************
*** 743,746 ****
--- 750,755 ----
  #elif FLEXT_THREADS == FLEXT_THR_MP
  		MPYield();
+ #elif FLEXT_THREADS == FLEXT_THR_WIN32
+         SwitchToThread();
  #else
  #error
***************
*** 801,804 ****
--- 810,835 ----
  //		int cnt;
  	};
+ #elif FLEXT_THREADS == FLEXT_THR_WIN32
+ 	{
+ 	public:
+ 		//! Construct thread mutex
+         ThrMutex() { ::InitializeCriticalSection(&mutex); }
+ 		//! Destroy thread mutex
+         ~ThrMutex() { ::DeleteCriticalSection(&mutex); }
+ 
+ 		//! Lock thread mutex
+         bool Lock() { ::EnterCriticalSection(&mutex); return true; }
+ 		/*! Wait to lock thread mutex.
+ 			\todo Implement!
+ 		*/
+ //		bool WaitForLock(double tm) { return pthread_mutex_lock(&mutex) == 0; }
+ 		//! Try to lock, but don't wait
+         bool TryLock() { return ::TryEnterCriticalSection(&mutex) != 0; }
+ 		//! Unlock thread mutex
+         bool Unlock() { ::LeaveCriticalSection(&mutex); return true; }
+ 
+ 	protected:
+ 		CRITICAL_SECTION mutex;
+ 	};
  #elif FLEXT_THREADS == FLEXT_THR_MP
  	{
***************
*** 843,847 ****
  		/*! Wait for condition (for a certain time).
  			\param ftime Wait time in seconds
! 			\ret 0 = signalled, 1 = timed out 
  			\remark If ftime = 0 this may suck away your cpu if used in a signalled loop.
  			\remark The time resolution of the implementation is required to be at least ms.
--- 874,878 ----
  		/*! Wait for condition (for a certain time).
  			\param ftime Wait time in seconds
! 			\ret true = signalled, false = timed out 
  			\remark If ftime = 0 this may suck away your cpu if used in a signalled loop.
  			\remark The time resolution of the implementation is required to be at least ms.
***************
*** 850,857 ****
  
  		//! Signal condition
! 		bool Signal();
  
  	protected:
  		pthread_cond_t cond;
  	};
  #elif FLEXT_THREADS == FLEXT_THR_MP
--- 881,913 ----
  
  		//! Signal condition
!         bool Signal() { return pthread_cond_signal(&cond) == 0; }
  
  	protected:
  		pthread_cond_t cond;
+ 	};
+ #elif FLEXT_THREADS == FLEXT_THR_WIN32
+ 	{
+ 	public:
+ 		//! Construct thread conditional
+ 		ThrCond() { cond = CreateEvent(NULL,FALSE,FALSE,NULL); }
+ 		//! Destroy thread conditional
+ 		~ThrCond() { CloseHandle(cond); }
+ 
+ 		//! Wait for condition 
+ 		bool Wait() { return WaitForSingleObject(cond,INFINITE) == WAIT_OBJECT_0; }
+ 
+ 		/*! Wait for condition (for a certain time).
+ 			\param ftime Wait time in seconds
+ 			\ret true = signalled, false = timed out 
+ 			\remark If ftime = 0 this may suck away your cpu if used in a signalled loop.
+ 			\remark The time resolution of the implementation is required to be at least ms.
+ 		*/
+         bool TimedWait(double ftime) { return WaitForSingleObject(cond,(LONG)(ftime*1000)) == WAIT_OBJECT_0; }
+ 
+ 		//! Signal condition
+         bool Signal() { return SetEvent(cond) != 0; }
+ 
+ 	protected:
+ 		HANDLE cond;
  	};
  #elif FLEXT_THREADS == FLEXT_THR_MP

Index: flthr.cpp
===================================================================
RCS file: /cvsroot/pure-data/externals/grill/flext/source/flthr.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** flthr.cpp	28 Jul 2003 02:32:41 -0000	1.20
--- flthr.cpp	13 Nov 2003 03:33:09 -0000	1.21
***************
*** 49,52 ****
--- 49,58 ----
  
  
+ void flext::LaunchHelper(thr_entry *e)
+ {
+     e->thrid = GetThreadId();
+     e->meth(e->params);
+ }
+ 
  //! Start helper thread
  bool flext::StartHelper()
***************
*** 76,79 ****
--- 82,87 ----
  		ok = ret == noErr;
  	}
+ #elif FLEXT_THREADS == FLEXT_THR_WIN32
+     ok = _beginthread(ThrHelper,0,NULL) >= 0;
  #else
  #error
***************
*** 101,108 ****
  #endif
  
- 
  //! Static helper thread function
  void flext::ThrHelper(void *)
  {
  #if FLEXT_THREADS == FLEXT_THR_POSIX
  	// set prototype thread attributes
--- 109,117 ----
  #endif
  
  //! Static helper thread function
  void flext::ThrHelper(void *)
  {
+     thrhelpid = GetThreadId();
+ 
  #if FLEXT_THREADS == FLEXT_THR_POSIX
  	// set prototype thread attributes
***************
*** 140,146 ****
  //				post("Helper start thread");
  #if FLEXT_THREADS == FLEXT_THR_POSIX
! 				ok = pthread_create (&ti->thrid,&attr,(void *(*)(void *))ti->meth,ti->params) == 0;
  #elif FLEXT_THREADS == FLEXT_THR_MP
! 				ok = MPCreateTask((TaskProc)ti->meth,ti->params,0,0,0,0,0,&ti->thrid) == noErr;
  #else
  #error
--- 149,159 ----
  //				post("Helper start thread");
  #if FLEXT_THREADS == FLEXT_THR_POSIX
!                 thrid_t dummy;
! 				ok = pthread_create (&dummy,&attr,(void *(*)(void *))LaunchHelper,ti) == 0;
  #elif FLEXT_THREADS == FLEXT_THR_MP
!                 thrid_t dummy;
! 				ok = MPCreateTask((TaskProc)LaunchHelper,ti,0,0,0,0,0,&dummy) == noErr;
! #elif FLEXT_THREADS == FLEXT_THR_WIN32
! 				ok = _beginthread((void (*)(void *))LaunchHelper,0,ti) >= 0;
  #else
  #error
***************
*** 343,346 ****
--- 356,363 ----
  				MPTerminateTask(t->thrid,0);
  				// here, we should use a task queue to check whether the task has really terminated!!
+ 		#elif FLEXT_THREADS == FLEXT_THR_WIN32
+                 // can't use the c library function _endthread.. memory leaks will occur
+                 HANDLE hnd = OpenThread(THREAD_ALL_ACCESS,TRUE,t->thrid);
+                 TerminateThread(hnd,0);
  		#else
  		#error
***************
*** 400,403 ****
--- 417,455 ----
  	}
  	return true;
+ 
+ #elif FLEXT_THREADS == FLEXT_THR_WIN32
+     HANDLE href = OpenThread(THREAD_ALL_ACCESS,TRUE,ref);
+     HANDLE hid = OpenThread(THREAD_ALL_ACCESS,TRUE,id);
+     int pr = GetThreadPriority(href);
+ 
+     if(pr == THREAD_PRIORITY_ERROR_RETURN) {
+ #ifdef FLEXT_DEBUG
+ 		post("flext - failed to get thread priority");
+ #endif
+ 		return false;
+ 	}
+ 
+     pr += dp;
+ 	if(pr < THREAD_PRIORITY_IDLE) {
+ #ifdef FLEXT_DEBUG		
+ 		post("flext - minimum thread priority reached");
+ #endif
+ 		pr = THREAD_PRIORITY_IDLE;
+ 	}
+ 	else if(pr > THREAD_PRIORITY_TIME_CRITICAL) {
+ #ifdef FLEXT_DEBUG		
+ 		post("flext - maximum thread priority reached");
+ #endif
+ 		pr = THREAD_PRIORITY_TIME_CRITICAL;
+ 	}
+ 	
+ 	if(SetThreadPriority(hid,pr) == 0) {
+ #ifdef FLEXT_DEBUG		
+ 		post("flext - failed to change thread priority");
+ #endif
+ 		return false;
+ 	}
+     return true;
+ 
  #elif FLEXT_THREADS == FLEXT_THR_MP
  	thr_entry *t;
***************
*** 442,445 ****
--- 494,510 ----
  	}
  	return parm.sched_priority;
+ 
+ #elif FLEXT_THREADS == FLEXT_THR_WIN32
+     HANDLE hid = OpenThread(THREAD_ALL_ACCESS,TRUE,id);
+     int pr = GetThreadPriority(hid);
+ 
+     if(pr == THREAD_PRIORITY_ERROR_RETURN) {
+ #ifdef FLEXT_DEBUG
+ 		post("flext - failed to get thread priority");
+ #endif
+ 		return -1;
+ 	}
+     return pr;
+ 
  #elif FLEXT_THREADS == FLEXT_THR_MP
  	thr_entry *t;
***************
*** 473,476 ****
--- 538,552 ----
  	}
  	return true;
+ 
+ #elif FLEXT_THREADS == FLEXT_THR_WIN32
+     HANDLE hid = OpenThread(THREAD_ALL_ACCESS,TRUE,id);
+ 	if(SetThreadPriority(hid,p) == 0) {
+ #ifdef FLEXT_DEBUG		
+ 		post("flext - failed to change thread priority");
+ #endif
+ 		return false;
+ 	}
+     return true;
+ 
  #elif FLEXT_THREADS == FLEXT_THR_MP
  	thr_entry *t;
***************
*** 539,550 ****
  	bool ret = pthread_cond_timedwait(&cond,&mutex,&tm) == 0; 
  	Unlock();
- 	return ret;
- }
- 
- bool flext::ThrCond::Signal() 
- { 
- //	Lock();
- 	bool ret = pthread_cond_signal(&cond) == 0; 
- //	Unlock();
  	return ret;
  }
--- 615,618 ----






More information about the Pd-cvs mailing list