2 * FreeRDP: A Remote Desktop Protocol client.
5 * Copyright 2011 Vic Lee
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
32 #include <freerdp/utils/sleep.h>
33 #include <freerdp/utils/memory.h>
34 #include <freerdp/utils/thread.h>
36 freerdp_thread* freerdp_thread_new(void)
38 freerdp_thread* thread;
40 thread = xnew(freerdp_thread);
41 thread->mutex = freerdp_mutex_new();
42 thread->signals[0] = wait_obj_new();
43 thread->signals[1] = wait_obj_new();
44 thread->num_signals = 2;
49 void freerdp_thread_start(freerdp_thread* thread, void* func, void* arg)
56 CloseHandle((HANDLE)_beginthreadex(NULL, 0, func, arg, 0, NULL));
58 CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, arg, 0, NULL));
64 pthread_create(&th, 0, func, arg);
70 void freerdp_thread_stop(freerdp_thread* thread)
74 wait_obj_set(thread->signals[0]);
76 while (thread->status > 0 && i < 1000)
79 freerdp_usleep(100000);
83 void freerdp_thread_free(freerdp_thread* thread)
87 for (i = 0; i < thread->num_signals; i++)
88 wait_obj_free(thread->signals[i]);
89 thread->num_signals = 0;
91 freerdp_mutex_free(thread->mutex);