summaryrefslogtreecommitdiff
path: root/miranda-wine/protocols/Yahoo/pthread.c
diff options
context:
space:
mode:
Diffstat (limited to 'miranda-wine/protocols/Yahoo/pthread.c')
-rw-r--r--miranda-wine/protocols/Yahoo/pthread.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/miranda-wine/protocols/Yahoo/pthread.c b/miranda-wine/protocols/Yahoo/pthread.c
new file mode 100644
index 0000000..f979b0e
--- /dev/null
+++ b/miranda-wine/protocols/Yahoo/pthread.c
@@ -0,0 +1,75 @@
+/*
+ * $Id: pthread.c 2874 2006-05-16 21:38:00Z ghazan $
+ *
+ * myYahoo Miranda Plugin
+ *
+ * Authors: Gennady Feldman (aka Gena01)
+ * Laurent Marechal (aka Peorth)
+ *
+ * Code borrowed for myYahoo plugin. Fixed to compile on Mingw by G.Feldman
+ * Original Copyright (c) 2003 Robert Rainwater
+ *
+ * This code is under GPL and is based on AIM, MSN and Miranda source code.
+ * I want to thank Robert Rainwater and George Hazan for their code and support
+ * and for answering some of my questions during development of this plugin.
+ */
+#include "yahoo.h"
+#include <process.h>
+#include <m_system.h>
+
+/* Gena01 - added some defined to fix compilation with mingw gcc */
+/* __try/__finally taken from abiword patch found on the web */
+#ifdef __GNUC__
+
+#if 0
+ #include <crtdbg.h>
+#else
+#define __try
+#define __except(x) if (0) /* don't execute handler */
+#define __finally
+
+#define _try __try
+#define _except __except
+#define _finally __finally
+#endif
+
+#endif
+
+#include <excpt.h>
+
+struct pthread_arg
+{
+ HANDLE hEvent;
+ void (*threadcode) (void *);
+ void *arg;
+};
+
+void pthread_r(struct pthread_arg *fa)
+{
+ 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);
+ }
+}
+
+unsigned long pthread_create(void (*threadcode) (void *), void *arg)
+{
+ unsigned long rc;
+ struct pthread_arg fa;
+ fa.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ fa.threadcode = threadcode;
+ fa.arg = arg;
+ rc = _beginthread((void *) (void *) pthread_r, 0, &fa);
+ if ((unsigned long) -1L != rc) {
+ WaitForSingleObject(fa.hEvent, INFINITE);
+ }
+ CloseHandle(fa.hEvent);
+ return rc;
+}
+