From 15eeaa23274ba85b44751081b092804d71bbe983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Tue, 18 Sep 2012 19:40:54 -0400 Subject: [PATCH] libfreerdp-utils: remove semaphore utils in favor of WinPR semaphore API --- channels/rdpdr/smartcard/scard_operations.c | 1 - client/DirectFB/dfreerdp.c | 13 ++- client/X11/xfreerdp.c | 12 +-- client/test/freerdp.c | 13 +-- cunit/test_utils.c | 13 +-- cunit/test_utils.h | 1 - include/freerdp/utils/semaphore.h | 32 ------- libfreerdp/channels/libchannels.c | 15 +-- libfreerdp/utils/CMakeLists.txt | 1 - libfreerdp/utils/semaphore.c | 101 -------------------- 10 files changed, 30 insertions(+), 172 deletions(-) delete mode 100644 include/freerdp/utils/semaphore.h delete mode 100644 libfreerdp/utils/semaphore.c diff --git a/channels/rdpdr/smartcard/scard_operations.c b/channels/rdpdr/smartcard/scard_operations.c index fbf87f4b4..52d98c098 100644 --- a/channels/rdpdr/smartcard/scard_operations.c +++ b/channels/rdpdr/smartcard/scard_operations.c @@ -40,7 +40,6 @@ #include #include #include -#include #include #include "rdpdr_types.h" diff --git a/client/DirectFB/dfreerdp.c b/client/DirectFB/dfreerdp.c index c6799effc..ae80dafd6 100644 --- a/client/DirectFB/dfreerdp.c +++ b/client/DirectFB/dfreerdp.c @@ -20,19 +20,22 @@ #include #include #include + +#include #include #include -#include #include #include #include +#include + #include "df_event.h" #include "df_graphics.h" #include "dfreerdp.h" -static freerdp_sem g_sem; +static HANDLE g_sem; static int g_thread_count = 0; struct thread_data @@ -425,7 +428,7 @@ void* thread_func(void* param) g_thread_count--; if (g_thread_count < 1) - freerdp_sem_signal(g_sem); + ReleaseSemaphore(g_sem, 1, NULL); return NULL; } @@ -442,7 +445,7 @@ int main(int argc, char* argv[]) freerdp_channels_global_init(); - g_sem = freerdp_sem_new(1); + g_sem = CreateSemaphore(NULL, 0, 1, NULL); instance = freerdp_new(); instance->PreConnect = df_pre_connect; @@ -469,7 +472,7 @@ int main(int argc, char* argv[]) while (g_thread_count > 0) { - freerdp_sem_wait(g_sem); + WaitForSingleObject(g_sem, INFINITE); } freerdp_channels_global_uninit(); diff --git a/client/X11/xfreerdp.c b/client/X11/xfreerdp.c index 59afddb92..a4adfd93f 100644 --- a/client/X11/xfreerdp.c +++ b/client/X11/xfreerdp.c @@ -52,14 +52,14 @@ #include #include #include -#include -#include #include #include #include #include #include +#include + #include "xf_gdi.h" #include "xf_rail.h" #include "xf_tsmf.h" @@ -71,7 +71,7 @@ #include "xfreerdp.h" -static freerdp_sem g_sem; +static HANDLE g_sem; static int g_thread_count = 0; static uint8 g_disconnect_reason = 0; @@ -1256,7 +1256,7 @@ void* thread_func(void* param) g_thread_count--; if (g_thread_count < 1) - freerdp_sem_signal(g_sem); + ReleaseSemaphore(g_sem, 1, NULL); pthread_exit(NULL); } @@ -1294,7 +1294,7 @@ int main(int argc, char* argv[]) freerdp_channels_global_init(); - g_sem = freerdp_sem_new(1); + g_sem = CreateSemaphore(NULL, 0, 1, NULL); instance = freerdp_new(); instance->PreConnect = xf_pre_connect; @@ -1320,7 +1320,7 @@ int main(int argc, char* argv[]) while (g_thread_count > 0) { - freerdp_sem_wait(g_sem); + WaitForSingleObject(g_sem, INFINITE); } pthread_join(thread, NULL); diff --git a/client/test/freerdp.c b/client/test/freerdp.c index a301666ba..76d3ca55a 100644 --- a/client/test/freerdp.c +++ b/client/test/freerdp.c @@ -36,13 +36,14 @@ #include #include #include -#include -#include #include +#include #include #include #include +#include + struct tf_info { void* data; @@ -57,7 +58,7 @@ struct tf_context }; typedef struct tf_context tfContext; -freerdp_sem g_sem; +HANDLE g_sem; static int g_thread_count = 0; struct thread_data @@ -297,7 +298,7 @@ void* thread_func(void* param) g_thread_count--; if (g_thread_count < 1) - freerdp_sem_signal(&g_sem); + ReleaseSemaphore(g_sem, 1, NULL); return NULL; } @@ -311,7 +312,7 @@ int main(int argc, char* argv[]) freerdp_channels_global_init(); - g_sem = freerdp_sem_new(1); + g_sem = CreateSemaphore(NULL, 0, 1, NULL); instance = freerdp_new(); instance->PreConnect = tf_pre_connect; @@ -334,7 +335,7 @@ int main(int argc, char* argv[]) while (g_thread_count > 0) { - freerdp_sem_wait(g_sem); + WaitForSingleObject(g_sem, INFINITE); } freerdp_channels_global_uninit(); diff --git a/cunit/test_utils.c b/cunit/test_utils.c index f9d012115..673da5163 100644 --- a/cunit/test_utils.c +++ b/cunit/test_utils.c @@ -28,8 +28,8 @@ #include #include #include + #include -#include #include #include #include @@ -53,7 +53,6 @@ int add_utils_suite(void) { add_test_suite(utils); - add_test_function(semaphore); add_test_function(load_plugin); add_test_function(wait_obj); add_test_function(args); @@ -63,16 +62,6 @@ int add_utils_suite(void) return 0; } -void test_semaphore(void) -{ - freerdp_sem sem; - - sem = freerdp_sem_new(1); - freerdp_sem_wait(sem); - freerdp_sem_signal(sem); - freerdp_sem_free(sem); -} - void test_load_plugin(void) { void* entry; diff --git a/cunit/test_utils.h b/cunit/test_utils.h index 93e481fdc..6f7567603 100644 --- a/cunit/test_utils.h +++ b/cunit/test_utils.h @@ -23,7 +23,6 @@ int init_utils_suite(void); int clean_utils_suite(void); int add_utils_suite(void); -void test_semaphore(void); void test_load_plugin(void); void test_wait_obj(void); void test_args(void); diff --git a/include/freerdp/utils/semaphore.h b/include/freerdp/utils/semaphore.h deleted file mode 100644 index 15830eb04..000000000 --- a/include/freerdp/utils/semaphore.h +++ /dev/null @@ -1,32 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * Semaphore Utils - * - * Copyright 2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __SEMAPHORE_UTILS_H -#define __SEMAPHORE_UTILS_H - -#include - -typedef void* freerdp_sem; - -FREERDP_API freerdp_sem freerdp_sem_new(int iv); -FREERDP_API void freerdp_sem_free(freerdp_sem sem); -FREERDP_API void freerdp_sem_signal(freerdp_sem sem); -FREERDP_API void freerdp_sem_wait(freerdp_sem sem); - -#endif /* __SEMAPHORE_UTILS_H */ diff --git a/libfreerdp/channels/libchannels.c b/libfreerdp/channels/libchannels.c index 8f63c8ef9..0b641f263 100644 --- a/libfreerdp/channels/libchannels.c +++ b/libfreerdp/channels/libchannels.c @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -125,7 +124,7 @@ struct rdp_channels LIST* sync_data_list; /* used for sync event */ - freerdp_sem event_sem; + HANDLE event_sem; RDP_EVENT* event; }; @@ -566,11 +565,12 @@ static uint32 FREERDP_CC MyVirtualChannelEventPush(uint32 openHandle, RDP_EVENT* return CHANNEL_RC_NOT_OPEN; } - freerdp_sem_wait(channels->event_sem); /* lock channels->event */ + /* lock channels->event */ + WaitForSingleObject(channels->event_sem, INFINITE); if (!channels->is_connected) { - freerdp_sem_signal(channels->event_sem); + ReleaseSemaphore(channels->event_sem, 1, NULL); DEBUG_CHANNELS("error not connected"); return CHANNEL_RC_NOT_CONNECTED; } @@ -619,7 +619,7 @@ rdpChannels* freerdp_channels_new(void) channels->sync_data_mutex = CreateMutex(NULL, FALSE, NULL); channels->sync_data_list = list_new(); - channels->event_sem = freerdp_sem_new(1); + channels->event_sem = CreateSemaphore(NULL, 0, 1, NULL); channels->signal = wait_obj_new(); /* Add it to the global list */ @@ -642,7 +642,7 @@ void freerdp_channels_free(rdpChannels* channels) CloseHandle(channels->sync_data_mutex); list_free(channels->sync_data_list); - freerdp_sem_free(channels->event_sem); + CloseHandle(channels->event_sem); wait_obj_free(channels->signal); /* Remove from global list */ @@ -971,7 +971,8 @@ RDP_EVENT* freerdp_channels_pop_event(rdpChannels* channels) event = channels->event; channels->event = NULL; - freerdp_sem_signal(channels->event_sem); /* release channels->event */ + /* release channels->event */ + ReleaseSemaphore(channels->event_sem, 1, NULL); return event; } diff --git a/libfreerdp/utils/CMakeLists.txt b/libfreerdp/utils/CMakeLists.txt index bcffedaf6..ea4edfadb 100644 --- a/libfreerdp/utils/CMakeLists.txt +++ b/libfreerdp/utils/CMakeLists.txt @@ -36,7 +36,6 @@ set(FREERDP_UTILS_SRCS profiler.c rail.c rect.c - semaphore.c signal.c sleep.c stopwatch.c diff --git a/libfreerdp/utils/semaphore.c b/libfreerdp/utils/semaphore.c deleted file mode 100644 index 75bb1a57a..000000000 --- a/libfreerdp/utils/semaphore.c +++ /dev/null @@ -1,101 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Client - * Semaphore Utils - * - * Copyright 2011 Marc-Andre Moreau - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include - -#if defined __APPLE__ - -#include -#include -#include -#include -#include -#define freerdp_sem_t semaphore_t - -#elif defined _WIN32 - -#define freerdp_sem_t HANDLE - -#else - -#include -#include -#define freerdp_sem_t sem_t - -#endif - -freerdp_sem freerdp_sem_new(int iv) -{ - freerdp_sem_t* sem; - - sem = xnew(freerdp_sem_t); - -#if defined __APPLE__ - semaphore_create(mach_task_self(), sem, SYNC_POLICY_FIFO, iv); -#elif defined _WIN32 - *sem = CreateSemaphore(NULL, 0, iv, NULL); -#else - sem_init(sem, 0, iv); -#endif - - return sem; -} - -void freerdp_sem_free(freerdp_sem sem) -{ -#if defined __APPLE__ - semaphore_destroy(mach_task_self(), *((freerdp_sem_t*)sem)); -#elif defined _WIN32 - CloseHandle(*((freerdp_sem_t*)sem)); -#else - sem_destroy((freerdp_sem_t*)sem); -#endif - - xfree(sem); -} - -void freerdp_sem_signal(freerdp_sem sem) -{ -#if defined __APPLE__ - semaphore_signal(*((freerdp_sem_t*)sem)); -#elif defined _WIN32 - ReleaseSemaphore(*((freerdp_sem_t*)sem), 1, NULL); -#else - sem_post((freerdp_sem_t*)sem); -#endif -} - -void freerdp_sem_wait(freerdp_sem sem) -{ -#if defined __APPLE__ - semaphore_wait(*((freerdp_sem_t*)sem)); -#elif defined _WIN32 - WaitForSingleObject(*((freerdp_sem_t*)sem), INFINITE); -#else - sem_wait((freerdp_sem_t*)sem); -#endif -} -