From 7fd9fe181150f166a098eaf4e006f878c28cb770 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Mon, 15 Feb 2010 05:51:01 +0300 Subject: sort --- forkthread.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 forkthread.c (limited to 'forkthread.c') diff --git a/forkthread.c b/forkthread.c new file mode 100644 index 0000000..2613f62 --- /dev/null +++ b/forkthread.c @@ -0,0 +1,112 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2006 Miranda ICQ/IM project, +all portions of this code file are copyrighted to the people +listed in contributors.txt. + +This program 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 2 +of the License, or (at your option) any later version. + +This program 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 this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "common.h" + +struct FORK_ARG { + HANDLE hEvent; + void (__cdecl *threadcode)(void*); + unsigned (__stdcall *threadcodeex)(void*); + void *arg; +}; + +void __cdecl forkthread_r(void * arg) +{ + struct FORK_ARG * fa = (struct FORK_ARG *) arg; + void (*callercode)(void*)=fa->threadcode; + void * cookie=fa->arg; + CallService(MS_SYSTEM_THREAD_PUSH,0,0); + if (fa->hEvent) SetEvent(fa->hEvent); + __try { + callercode(cookie); + } __finally { + CallService(MS_SYSTEM_THREAD_POP,0,0); + } + return; +} + + +unsigned long forkthread ( + void (__cdecl *threadcode)(void*), + unsigned long stacksize, + void *arg +) +{ + unsigned long rc; + struct FORK_ARG fa; + fa.hEvent=CreateEvent(NULL,FALSE,FALSE,NULL); + fa.threadcode=threadcode; + fa.arg=arg; + rc=_beginthread(forkthread_r,stacksize,&fa); + if (fa.hEvent) { + if ((unsigned long)-1L != rc) { + WaitForSingleObject(fa.hEvent,INFINITE); + } //if + CloseHandle(fa.hEvent); + } // if + return rc; +} + + +/* +unsigned __stdcall forkthreadex_r(void * arg) +{ + struct FORK_ARG *fa=(struct FORK_ARG *)arg; + unsigned (__stdcall * threadcode) (void *)=fa->threadcodeex; + void *cookie=fa->arg; + unsigned long rc; + + CallService(MS_SYSTEM_THREAD_PUSH,0,0); + if (fa->hEvent) SetEvent(fa->hEvent); + __try { + rc=threadcode(cookie); + } __finally { + CallService(MS_SYSTEM_THREAD_POP,0,0); + } + return rc; +} + +unsigned long forkthreadex( + void *sec, + unsigned stacksize, + unsigned (__stdcall *threadcode)(void*), + void *arg, + unsigned cf, + unsigned *thraddr +) +{ + unsigned long rc; + struct FORK_ARG fa; + fa.threadcodeex=threadcode; + fa.arg=arg; + fa.hEvent=CreateEvent(NULL,FALSE,FALSE,NULL); + rc=_beginthreadex(sec,stacksize,forkthreadex_r,(void *)&fa,0,thraddr); + if (fa.hEvent) { + if (rc) { + WaitForSingleObject(fa.hEvent,INFINITE); + } // if + CloseHandle(fa.hEvent); + } + return rc; +} +*/ \ No newline at end of file -- cgit v1.2.3