ntdll: Use cpu_info to check for AVX availability.
[wine.git] / dlls / dpnet / threadpool.c
blob22d871b40b414c4f8d3e2c40046a7ed48b093ba3
1 /*
2 * DirectPlay8 ThreadPool
4 * Copyright 2004 Raphael Junqueira
5 * Copyright 2008 Alexander N. Sørnes <alex@thehandofagony.com>
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.
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.
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
24 #include <stdarg.h>
26 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "objbase.h"
32 #include "wine/debug.h"
34 #include "dpnet_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(dpnet);
38 static PFNDPNMESSAGEHANDLER threadpool_msghandler = NULL;
39 static DWORD threadpool_flags = 0;
40 static void *threadpool_usercontext = NULL;
42 static inline IDirectPlay8ThreadPoolImpl *impl_from_IDirectPlay8ThreadPool(IDirectPlay8ThreadPool *iface)
44 return CONTAINING_RECORD(iface, IDirectPlay8ThreadPoolImpl, IDirectPlay8ThreadPool_iface);
47 /* IUnknown interface follows */
48 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_QueryInterface(IDirectPlay8ThreadPool *iface,
49 REFIID riid, void **ppobj)
51 IDirectPlay8ThreadPoolImpl *This = impl_from_IDirectPlay8ThreadPool(iface);
53 if(IsEqualGUID(riid, &IID_IUnknown) ||
54 IsEqualGUID(riid, &IID_IDirectPlay8ThreadPool))
56 IUnknown_AddRef(iface);
57 *ppobj = This;
58 return DPN_OK;
61 WARN("(%p)->(%s,%p): not found\n", This, debugstr_guid(riid), ppobj);
62 return E_NOINTERFACE;
65 static ULONG WINAPI IDirectPlay8ThreadPoolImpl_AddRef(IDirectPlay8ThreadPool *iface)
67 IDirectPlay8ThreadPoolImpl* This = impl_from_IDirectPlay8ThreadPool(iface);
68 ULONG RefCount = InterlockedIncrement(&This->ref);
70 return RefCount;
73 static ULONG WINAPI IDirectPlay8ThreadPoolImpl_Release(IDirectPlay8ThreadPool *iface)
75 IDirectPlay8ThreadPoolImpl* This = impl_from_IDirectPlay8ThreadPool(iface);
76 ULONG RefCount = InterlockedDecrement(&This->ref);
78 if(!RefCount)
79 HeapFree(GetProcessHeap(), 0, This);
81 return RefCount;
84 /* IDirectPlay8ThreadPool interface follows */
85 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_Initialize(IDirectPlay8ThreadPool *iface,
86 void * const pvUserContext, const PFNDPNMESSAGEHANDLER pfn, const DWORD dwFlags)
88 IDirectPlay8ThreadPoolImpl *This = impl_from_IDirectPlay8ThreadPool(iface);
90 TRACE("(%p)->(%p,%p,%x)\n", This, pvUserContext, pfn, dwFlags);
92 if(!pfn)
93 return DPNERR_INVALIDPARAM;
95 if(threadpool_msghandler)
96 return DPNERR_ALREADYINITIALIZED;
98 threadpool_msghandler = pfn;
99 threadpool_flags = dwFlags;
100 threadpool_usercontext = pvUserContext;
102 return DPN_OK;
105 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_Close(IDirectPlay8ThreadPool *iface,
106 const DWORD dwFlags)
108 IDirectPlay8ThreadPoolImpl *This = impl_from_IDirectPlay8ThreadPool(iface);
110 FIXME("(%p)->(%x)\n", This, dwFlags);
112 if(!threadpool_msghandler)
113 return DPNERR_UNINITIALIZED;
115 threadpool_msghandler = NULL;
117 return DPN_OK;
120 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_GetThreadCount(IDirectPlay8ThreadPool *iface,
121 const DWORD dwProcessorNum, DWORD * const pdwNumThreads, const DWORD dwFlags)
123 FIXME("(%p)->(%x,%p,%x): stub\n", iface, dwProcessorNum, pdwNumThreads, dwFlags);
124 *pdwNumThreads = 0;
125 return DPN_OK;
128 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_SetThreadCount(IDirectPlay8ThreadPool *iface,
129 const DWORD dwProcessorNum, const DWORD dwNumThreads, const DWORD dwFlags)
131 FIXME("(%p)->(%x,%x,%x): stub\n", iface, dwProcessorNum, dwNumThreads, dwFlags);
132 return DPN_OK;
135 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_DoWork(IDirectPlay8ThreadPool *iface,
136 const DWORD dwAllowedTimeSlice, const DWORD dwFlags)
138 static BOOL Run = FALSE;
140 if(!Run)
141 FIXME("(%p)->(%x,%x): stub\n", iface, dwAllowedTimeSlice, dwFlags);
143 Run = TRUE;
145 return DPN_OK;
148 static const IDirectPlay8ThreadPoolVtbl DirectPlay8ThreadPool_Vtbl =
150 IDirectPlay8ThreadPoolImpl_QueryInterface,
151 IDirectPlay8ThreadPoolImpl_AddRef,
152 IDirectPlay8ThreadPoolImpl_Release,
153 IDirectPlay8ThreadPoolImpl_Initialize,
154 IDirectPlay8ThreadPoolImpl_Close,
155 IDirectPlay8ThreadPoolImpl_GetThreadCount,
156 IDirectPlay8ThreadPoolImpl_SetThreadCount,
157 IDirectPlay8ThreadPoolImpl_DoWork
160 HRESULT DPNET_CreateDirectPlay8ThreadPool(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj)
162 IDirectPlay8ThreadPoolImpl* Client;
164 Client = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectPlay8ThreadPoolImpl));
166 if(Client == NULL)
168 *ppobj = NULL;
169 WARN("Not enough memory\n");
170 return E_OUTOFMEMORY;
173 Client->IDirectPlay8ThreadPool_iface.lpVtbl = &DirectPlay8ThreadPool_Vtbl;
174 Client->ref = 0;
176 return IDirectPlay8ThreadPoolImpl_QueryInterface(&Client->IDirectPlay8ThreadPool_iface, riid,
177 ppobj);