Prechádzať zdrojové kódy

Added thread register/unregister functions.

woollybah 9 rokov pred
rodič
commit
b943ceee3a
2 zmenil súbory, kde vykonal 59 pridanie a 1 odobranie
  1. 51 1
      blitz.mod/blitz_thread.c
  2. 8 0
      blitz.mod/blitz_thread.h

+ 51 - 1
blitz.mod/blitz_thread.c

@@ -75,7 +75,7 @@ void bbThreadSetData( int index,BBObject *data ){
 }
 
 BBObject *bbThreadGetData( int index ){
-	BBObject *data=bbThreadGetCurrent()->data[index];
+	BBObject * data = bbThreadGetCurrent()->data[index];
 	return data ? data : &bbNullObject;
 }
 
@@ -175,6 +175,32 @@ int bbThreadSuspend( BBThread *thread ){
 int bbThreadResume( BBThread *thread ){
 	return ResumeThread( thread->handle );
 }
+
+BBThread *bbThreadRegister( DWORD id ) {
+	BBThread *thread=GC_MALLOC_UNCOLLECTABLE( sizeof( BBThread ) );
+	memset( thread->data,0,sizeof(thread->data) );
+	
+	thread->handle = 0;
+	thread->proc=0;
+	thread->data[0]=0;
+	thread->detached=0;
+	thread->id = id;
+	
+	TlsSetValue( curThreadTls,thread );
+
+	BB_LOCK
+	addThread( thread );
+	BB_UNLOCK
+	
+	return thread;
+}
+
+void bbThreadUnregister( BBThread * thread ) {
+	BB_LOCK
+	removeThread( thread );
+	BB_UNLOCK
+}
+
 //***** POSIX threads *****
 #else
 
@@ -256,6 +282,30 @@ BBThread *bbThreadCreate( BBThreadProc proc,BBObject *data ){
 	return 0;
 }
 
+BBThread *bbThreadRegister( void * thd ) {
+	BBThread *thread=GC_MALLOC_UNCOLLECTABLE( sizeof( BBThread ) );
+	memset( thread->data,0,sizeof(thread->data) );
+	
+	thread->handle = thd;
+	thread->proc=0;
+	thread->data[0]=0;
+	thread->detached=0;
+	
+	pthread_setspecific( curThreadTls,thread );
+
+	BB_LOCK
+	addThread( thread );
+	BB_UNLOCK
+	
+	return thread;
+}
+
+void bbThreadUnregister( BBThread * thread ) {
+	BB_LOCK
+	removeThread( thread );
+	BB_UNLOCK
+}
+
 void bbThreadDetach( BBThread *thread ){
 	thread->detached=1;
 	pthread_detach( thread->handle );

+ 8 - 0
blitz.mod/blitz_thread.h

@@ -109,6 +109,14 @@ BBObject*		bbThreadGetData( int index );
 int			bbAtomicCAS( volatile int *target,int oldVal,int newVal );
 int			bbAtomicAdd( volatile int *target,int incr );
 
+#ifdef _WIN32
+BBThread *bbThreadRegister( DWORD id );
+#else
+BBThread *bbThreadRegister( void * thd );
+#endif
+void bbThreadUnregister( BBThread * thread );
+
+
 //Internal locks...
 extern int _bbNeedsLock;
 extern bb_mutex_t _bbLock;