summaryrefslogtreecommitdiff
path: root/plugins/Svc_dbepp/threads.cpp
diff options
context:
space:
mode:
authorVadim Dashevskiy <watcherhd@gmail.com>2012-05-15 10:38:20 +0000
committerVadim Dashevskiy <watcherhd@gmail.com>2012-05-15 10:38:20 +0000
commit48540940b6c28bb4378abfeb500ec45a625b37b6 (patch)
tree2ef294c0763e802f91d868bdef4229b6868527de /plugins/Svc_dbepp/threads.cpp
parent5c350913f011e119127baeb32a6aedeb4f0d33bc (diff)
initial commit
git-svn-id: http://svn.miranda-ng.org/main/trunk@2 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Svc_dbepp/threads.cpp')
-rw-r--r--plugins/Svc_dbepp/threads.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/plugins/Svc_dbepp/threads.cpp b/plugins/Svc_dbepp/threads.cpp
new file mode 100644
index 0000000000..7ac144adc4
--- /dev/null
+++ b/plugins/Svc_dbepp/threads.cpp
@@ -0,0 +1,48 @@
+#include "headers.h"
+
+// thread stuff
+
+struct FORK_ARG {
+ HANDLE hEvent;
+ void (__cdecl *threadcode)(void*);
+ unsigned (__stdcall *threadcodeex)(void*);
+ void *arg;
+};
+
+void __cdecl forkthread_r(void *param)
+{
+ struct FORK_ARG *fa=(struct FORK_ARG*)param;
+ void (*callercode)(void*)=fa->threadcode;
+ void *arg=fa->arg;
+
+ CallService(MS_SYSTEM_THREAD_PUSH,0,0);
+
+ SetEvent(fa->hEvent);
+
+ __try {
+ callercode(arg);
+ } __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 ((unsigned long)-1L != rc) {
+ WaitForSingleObject(fa.hEvent,INFINITE);
+ }
+ CloseHandle(fa.hEvent);
+
+ return rc;
+}