libfreerdp-utils: remove semaphore utils in favor of WinPR semaphore API
This commit is contained in:
parent
ca6a37eed4
commit
15eeaa2327
@ -40,7 +40,6 @@
|
||||
#include <freerdp/utils/memory.h>
|
||||
#include <freerdp/utils/stream.h>
|
||||
#include <freerdp/utils/svc_plugin.h>
|
||||
#include <freerdp/utils/semaphore.h>
|
||||
#include <freerdp/utils/thread.h>
|
||||
|
||||
#include "rdpdr_types.h"
|
||||
|
@ -20,19 +20,22 @@
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/utils/args.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
#include <freerdp/utils/semaphore.h>
|
||||
#include <freerdp/utils/event.h>
|
||||
#include <freerdp/constants.h>
|
||||
#include <freerdp/plugins/cliprdr.h>
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#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();
|
||||
|
@ -52,14 +52,14 @@
|
||||
#include <freerdp/codec/bitmap.h>
|
||||
#include <freerdp/utils/args.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
#include <freerdp/utils/semaphore.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
#include <freerdp/utils/event.h>
|
||||
#include <freerdp/utils/signal.h>
|
||||
#include <freerdp/utils/passphrase.h>
|
||||
#include <freerdp/plugins/cliprdr.h>
|
||||
#include <freerdp/rail.h>
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#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);
|
||||
|
@ -36,13 +36,14 @@
|
||||
#include <string.h>
|
||||
#include <freerdp/gdi/gdi.h>
|
||||
#include <freerdp/utils/args.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
#include <freerdp/utils/semaphore.h>
|
||||
#include <freerdp/utils/event.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
#include <freerdp/constants.h>
|
||||
#include <freerdp/channels/channels.h>
|
||||
#include <freerdp/plugins/cliprdr.h>
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
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();
|
||||
|
@ -28,8 +28,8 @@
|
||||
#include <sys/wait.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/utils/semaphore.h>
|
||||
#include <freerdp/utils/load_plugin.h>
|
||||
#include <freerdp/utils/wait_obj.h>
|
||||
#include <freerdp/utils/args.h>
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -1,32 +0,0 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Semaphore Utils
|
||||
*
|
||||
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* 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 <freerdp/api.h>
|
||||
|
||||
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 */
|
@ -46,7 +46,6 @@
|
||||
#include <freerdp/svc.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
#include <freerdp/utils/list.h>
|
||||
#include <freerdp/utils/semaphore.h>
|
||||
#include <freerdp/utils/wait_obj.h>
|
||||
#include <freerdp/utils/load_plugin.h>
|
||||
#include <freerdp/utils/event.h>
|
||||
@ -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;
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ set(FREERDP_UTILS_SRCS
|
||||
profiler.c
|
||||
rail.c
|
||||
rect.c
|
||||
semaphore.c
|
||||
signal.c
|
||||
sleep.c
|
||||
stopwatch.c
|
||||
|
@ -1,101 +0,0 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Semaphore Utils
|
||||
*
|
||||
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* 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 <winpr/windows.h>
|
||||
|
||||
#include <freerdp/utils/memory.h>
|
||||
#include <freerdp/utils/semaphore.h>
|
||||
|
||||
#if defined __APPLE__
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <mach/mach.h>
|
||||
#include <mach/semaphore.h>
|
||||
#include <mach/task.h>
|
||||
#define freerdp_sem_t semaphore_t
|
||||
|
||||
#elif defined _WIN32
|
||||
|
||||
#define freerdp_sem_t HANDLE
|
||||
|
||||
#else
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user