mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / opencl / unix_wrappers.c
blob9c83250b4e124e627194aae69b3374a203cec149
1 /*
2 * Copyright 2021 Zebediah Figura
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #if 0
20 #pragma makedep unix
21 #endif
23 #include "config.h"
24 #include <stdlib.h>
25 #include "unix_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(opencl);
29 struct program_callback
31 void (WINAPI *pfn_notify)(cl_program program, void *user_data);
32 void *user_data;
35 static void CL_CALLBACK program_callback_wrapper(cl_program program, void *user_data)
37 struct program_callback *callback = user_data;
38 TRACE("(%p, %p)\n", program, user_data);
39 callback->pfn_notify(program, callback->user_data);
40 free(callback);
43 cl_int WINAPI wrap_clBuildProgram( cl_program program, cl_uint num_devices,
44 const cl_device_id *device_list, const char *options,
45 void (WINAPI *pfn_notify)(cl_program program, void *user_data),
46 void *user_data )
48 if (pfn_notify)
50 struct program_callback *callback;
51 cl_int ret;
53 if (!(callback = malloc(sizeof(*callback))))
54 return CL_OUT_OF_HOST_MEMORY;
55 callback->pfn_notify = pfn_notify;
56 callback->user_data = user_data;
57 if ((ret = clBuildProgram( program, num_devices, device_list, options,
58 program_callback_wrapper, callback )) != CL_SUCCESS)
59 free( callback );
60 return ret;
63 return clBuildProgram( program, num_devices, device_list, options, NULL, NULL );
66 struct context_callback
68 void (WINAPI *pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data);
69 void *user_data;
72 static void CL_CALLBACK context_callback_wrapper(const char *errinfo,
73 const void *private_info, size_t cb, void *user_data)
75 struct context_callback *callback = user_data;
76 TRACE("(%s, %p, %zu, %p)\n", debugstr_a(errinfo), private_info, cb, user_data);
77 callback->pfn_notify(errinfo, private_info, cb, callback->user_data);
80 cl_context WINAPI wrap_clCreateContext( const cl_context_properties *properties,
81 cl_uint num_devices, const cl_device_id *devices,
82 void (WINAPI *pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data),
83 void *user_data, cl_int *errcode_ret )
85 if (pfn_notify)
87 struct context_callback *callback;
88 cl_context ret;
90 /* FIXME: the callback structure is currently leaked */
91 if (!(callback = malloc(sizeof(*callback))))
93 *errcode_ret = CL_OUT_OF_HOST_MEMORY;
94 return NULL;
96 callback->pfn_notify = pfn_notify;
97 callback->user_data = user_data;
98 if (!(ret = clCreateContext( properties, num_devices, devices, context_callback_wrapper, callback, errcode_ret )))
99 free( callback );
100 return ret;
103 return clCreateContext( properties, num_devices, devices, NULL, NULL, errcode_ret );
106 cl_context WINAPI wrap_clCreateContextFromType( const cl_context_properties *properties, cl_device_type device_type,
107 void (WINAPI *pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data),
108 void *user_data, cl_int *errcode_ret )
110 if (pfn_notify)
112 struct context_callback *callback;
113 cl_context ret;
115 /* FIXME: the callback structure is currently leaked */
116 if (!(callback = malloc(sizeof(*callback))))
118 *errcode_ret = CL_OUT_OF_HOST_MEMORY;
119 return NULL;
121 callback->pfn_notify = pfn_notify;
122 callback->user_data = user_data;
123 if (!(ret = clCreateContextFromType( properties, device_type, context_callback_wrapper, callback, errcode_ret )))
124 free( callback );
125 return ret;
128 return clCreateContextFromType( properties, device_type, NULL, NULL, errcode_ret );
131 cl_int WINAPI wrap_clEnqueueNativeKernel( cl_command_queue command_queue,
132 void (WINAPI *user_func)(void *),
133 void *args, size_t cb_args, cl_uint num_mem_objects, const cl_mem *mem_list, const void **args_mem_loc,
134 cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event )
136 /* we have no clear way to wrap user_func */
137 FIXME( "not implemented\n" );
138 return CL_INVALID_OPERATION;
141 cl_int WINAPI wrap_clSetEventCallback( cl_event event, cl_int type,
142 void (WINAPI *pfn_notify)(cl_event, cl_int, void *),
143 void *user_data)
145 FIXME( "not yet implemented\n" );
146 return CL_INVALID_OPERATION;
149 cl_int WINAPI wrap_clSetMemObjectDestructorCallback(cl_mem memobj,
150 void (WINAPI *pfn_notify)(cl_mem, void *),
151 void *user_data)
153 FIXME( "not yet implemented\n" );
154 return CL_INVALID_OPERATION;
157 cl_int WINAPI wrap_clCompileProgram( cl_program program, cl_uint num_devices,
158 const cl_device_id *device_list, const char *options, cl_uint num_input_headers,
159 const cl_program *input_headers, const char **header_include_names,
160 void (WINAPI *pfn_notify)(cl_program program, void *user_data),
161 void *user_data )
163 FIXME( "not yet implemented\n" );
164 return CL_INVALID_OPERATION;
167 cl_program WINAPI wrap_clLinkProgram( cl_context context, cl_uint num_devices, const cl_device_id *device_list,
168 const char *options, cl_uint num_input_programs, const cl_program *input_programs,
169 void (WINAPI *pfn_notify)(cl_program program, void *user_data),
170 void *user_data, cl_int *errcode_ret )
172 FIXME( "not yet implemented\n" );
173 *errcode_ret = CL_INVALID_OPERATION;
174 return NULL;
177 NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
179 if (reason != DLL_PROCESS_ATTACH) return STATUS_SUCCESS;
180 *(const struct opencl_funcs **)ptr_out = &funcs;
181 return STATUS_SUCCESS;