initial load of upstream version 1.06.32
[xmlrpc-c] / lib / util / pthreadx_win32.c
1 /* Copyright (C) 2001 by First Peer, Inc. All rights reserved.
2 **
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
5 ** are met:
6 ** 1. Redistributions of source code must retain the above copyright
7 **    notice, this list of conditions and the following disclaimer.
8 ** 2. Redistributions in binary form must reproduce the above copyright
9 **    notice, this list of conditions and the following disclaimer in the
10 **    documentation and/or other materials provided with the distribution.
11 ** 3. The name of the author may not be used to endorse or promote products
12 **    derived from this software without specific prior written permission. 
13 **  
14 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 ** SUCH DAMAGE. */
25
26 #include "xmlrpc_config.h"
27
28 #if WIN32
29
30 #include "pthreadx.h"
31
32 #include <process.h>
33
34 #undef PACKAGE
35 #undef VERSION
36
37 int pthread_create(pthread_t *new_thread_ID,
38                    const pthread_attr_t * attr,
39                    pthread_func start_func, void *arg)
40 {
41     HANDLE hThread;
42     DWORD dwThreadID;
43
44     hThread = (HANDLE) _beginthreadex (
45         NULL, 0, start_func, (LPVOID)arg, CREATE_SUSPENDED, &dwThreadID);
46
47     SetThreadPriority (hThread, THREAD_PRIORITY_NORMAL); 
48     ResumeThread (hThread);
49
50     *new_thread_ID = hThread;
51
52     return hThread ? 0 : -1;
53 }
54
55 /* Just kill it. */
56 int pthread_cancel(pthread_t target_thread)
57 {
58     CloseHandle (target_thread);
59     return 0;
60 }
61
62 /* Waits for the thread to exit before continuing. */
63 int pthread_join(pthread_t target_thread, void **status)
64 {
65     DWORD dwResult = WaitForSingleObject(target_thread, INFINITE);
66     (*status) = (void *)dwResult;
67     return 0;
68 }
69
70 /* Stubbed. Do nothing. */
71 int pthread_detach(pthread_t target_thread)
72 {
73     return 0;
74 }
75
76 int pthread_mutex_init(pthread_mutex_t *mp,
77                        const pthread_mutexattr_t * attr)
78 {
79     InitializeCriticalSection(mp);
80     return 0;
81 }
82
83 int pthread_mutex_lock(pthread_mutex_t *mp)
84 {
85     EnterCriticalSection(mp);
86     return 0;
87 }
88
89 int pthread_mutex_unlock(pthread_mutex_t *mp)
90 {
91     LeaveCriticalSection(mp);
92     return 0;
93 }
94
95 int pthread_mutex_destroy(pthread_mutex_t *mp)
96 {
97     DeleteCriticalSection(mp);
98     return 0;
99 }
100
101 #endif