msvcrt: Implemented setjmp for x86_64.
[wine] / dlls / dpnet / threadpool.c
1 /*
2  * DirectPlay8 ThreadPool
3  *
4  * Copyright 2004 Raphael Junqueira
5  * Copyright 2008 Alexander N. Sørnes <alex@thehandofagony.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  *
21  */
22
23 #include "config.h"
24
25 #include <stdarg.h>
26
27 #define COBJMACROS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "objbase.h"
33 #include "wine/debug.h"
34
35 #include "dplay8.h"
36 #include "dpnet_private.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(dpnet);
39
40 /* IUnknown interface follows */
41
42 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_QueryInterface(PDIRECTPLAY8THREADPOOL iface, REFIID riid, LPVOID *ppobj)
43 {
44     IDirectPlay8ThreadPoolImpl *This = (IDirectPlay8ThreadPoolImpl*)iface;
45
46     if(IsEqualGUID(riid, &IID_IUnknown) ||
47        IsEqualGUID(riid, &IID_IDirectPlay8ThreadPool))
48     {
49         IUnknown_AddRef(iface);
50         *ppobj = This;
51         return DPN_OK;
52     }
53
54     WARN("(%p)->(%s,%p): not found\n", This, debugstr_guid(riid), ppobj);
55     return E_NOINTERFACE;
56 }
57
58 static ULONG WINAPI IDirectPlay8ThreadPoolImpl_AddRef(PDIRECTPLAY8THREADPOOL iface)
59 {
60     IDirectPlay8ThreadPoolImpl* This = (IDirectPlay8ThreadPoolImpl*)iface;
61     ULONG RefCount = InterlockedIncrement(&This->ref);
62
63     return RefCount;
64 }
65
66 static ULONG WINAPI IDirectPlay8ThreadPoolImpl_Release(PDIRECTPLAY8THREADPOOL iface)
67 {
68     IDirectPlay8ThreadPoolImpl* This = (IDirectPlay8ThreadPoolImpl*)iface;
69     ULONG RefCount = InterlockedDecrement(&This->ref);
70
71     if(!RefCount)
72         HeapFree(GetProcessHeap(), 0, This);
73
74     return RefCount;
75 }
76
77 /* IDirectPlay8ThreadPool interface follows */
78 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_Initialize(PDIRECTPLAY8THREADPOOL iface, PVOID CONST pvUserContext, CONST PFNDPNMESSAGEHANDLER pfn, CONST DWORD dwFlags)
79 {
80     FIXME("(%p)->(%p,%p,%x): stub\n", iface, pvUserContext, pfn, dwFlags);
81     return DPN_OK;
82 }
83
84 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_Close(PDIRECTPLAY8THREADPOOL iface, CONST DWORD dwFlags)
85 {
86     return DPN_OK;
87 }
88
89 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_GetThreadCount(PDIRECTPLAY8THREADPOOL iface, CONST DWORD dwProcessorNum, DWORD* CONST pdwNumThreads, CONST DWORD dwFlags)
90 {
91     FIXME("(%p)->(%x,%p,%x): stub\n", iface, dwProcessorNum, pdwNumThreads, dwFlags);
92     *pdwNumThreads = 0;
93     return DPN_OK;
94 }
95
96 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_SetThreadCount(PDIRECTPLAY8THREADPOOL iface, CONST DWORD dwProcessorNum, CONST DWORD dwNumThreads, CONST DWORD dwFlags)
97 {
98     FIXME("(%p)->(%x,%x,%x): stub\n", iface, dwProcessorNum, dwNumThreads, dwFlags);
99     return DPN_OK;
100 }
101
102 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_DoWork(PDIRECTPLAY8THREADPOOL iface, CONST DWORD dwAllowedTimeSlice, CONST DWORD dwFlags)
103 {
104     static BOOL Run = FALSE;
105
106     if(!Run)
107         FIXME("(%p)->(%x,%x): stub\n", iface, dwAllowedTimeSlice, dwFlags);
108
109     Run = TRUE;
110
111     return DPN_OK;
112 }
113
114 static const IDirectPlay8ThreadPoolVtbl DirectPlay8ThreadPool_Vtbl =
115 {
116     IDirectPlay8ThreadPoolImpl_QueryInterface,
117     IDirectPlay8ThreadPoolImpl_AddRef,
118     IDirectPlay8ThreadPoolImpl_Release,
119     IDirectPlay8ThreadPoolImpl_Initialize,
120     IDirectPlay8ThreadPoolImpl_Close,
121     IDirectPlay8ThreadPoolImpl_GetThreadCount,
122     IDirectPlay8ThreadPoolImpl_SetThreadCount,
123     IDirectPlay8ThreadPoolImpl_DoWork
124 };
125
126 HRESULT DPNET_CreateDirectPlay8ThreadPool(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj)
127 {
128     IDirectPlay8ThreadPoolImpl* Client;
129
130     Client = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectPlay8ThreadPoolImpl));
131
132     if(Client == NULL)
133     {
134         *ppobj = NULL;
135         WARN("Not enough memory\n");
136         return E_OUTOFMEMORY;
137     }
138
139     Client->lpVtbl = &DirectPlay8ThreadPool_Vtbl;
140     Client->ref = 0;
141
142     return IDirectPlay8ThreadPoolImpl_QueryInterface((PDIRECTPLAY8THREADPOOL)Client, riid, ppobj);
143 }