libfreerdp-utils: removing mutex util in favor of WinPR mutex API
This commit is contained in:
parent
78723f019f
commit
13dbbb9513
@ -39,11 +39,12 @@
|
||||
#include <freerdp/utils/stream.h>
|
||||
#include <freerdp/utils/list.h>
|
||||
#include <freerdp/utils/thread.h>
|
||||
#include <freerdp/utils/mutex.h>
|
||||
#include <freerdp/utils/event.h>
|
||||
#include <freerdp/utils/sleep.h>
|
||||
#include <freerdp/plugins/tsmf.h>
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#include "drdynvc_types.h"
|
||||
#include "tsmf_constants.h"
|
||||
#include "tsmf_types.h"
|
||||
@ -82,8 +83,8 @@ struct _TSMF_PRESENTATION
|
||||
uint64 audio_start_time;
|
||||
uint64 audio_end_time;
|
||||
|
||||
/* The stream list could be accessed by differnt threads and need to be protected. */
|
||||
freerdp_mutex mutex;
|
||||
/* The stream list could be accessed by different threads and need to be protected. */
|
||||
HANDLE mutex;
|
||||
|
||||
LIST* stream_list;
|
||||
};
|
||||
@ -138,7 +139,7 @@ struct _TSMF_SAMPLE
|
||||
|
||||
static LIST* presentation_list = NULL;
|
||||
static uint64 last_played_audio_time = 0;
|
||||
static pthread_mutex_t tsmf_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static HANDLE tsmf_mutex = NULL;
|
||||
static int TERMINATING = 0;
|
||||
|
||||
static uint64 get_current_time(void)
|
||||
@ -171,10 +172,12 @@ static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync)
|
||||
/* Check if some other stream has earlier sample that needs to be played first */
|
||||
if (stream->last_end_time > AUDIO_TOLERANCE)
|
||||
{
|
||||
freerdp_mutex_lock(presentation->mutex);
|
||||
WaitForSingleObject(presentation->mutex, INFINITE);
|
||||
|
||||
for (item = presentation->stream_list->head; item; item = item->next)
|
||||
{
|
||||
s = (TSMF_STREAM*) item->data;
|
||||
|
||||
if (s != stream && !s->eos && s->last_end_time &&
|
||||
s->last_end_time < stream->last_end_time - AUDIO_TOLERANCE)
|
||||
{
|
||||
@ -182,7 +185,8 @@ static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync)
|
||||
break;
|
||||
}
|
||||
}
|
||||
freerdp_mutex_unlock(presentation->mutex);
|
||||
|
||||
ReleaseMutex(presentation->mutex);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -273,7 +277,7 @@ TSMF_PRESENTATION* tsmf_presentation_new(const uint8* guid, IWTSVirtualChannelCa
|
||||
memcpy(presentation->presentation_id, guid, GUID_SIZE);
|
||||
presentation->channel_callback = pChannelCallback;
|
||||
|
||||
presentation->mutex = freerdp_mutex_new();
|
||||
presentation->mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
presentation->stream_list = list_new();
|
||||
|
||||
list_enqueue(presentation_list, presentation);
|
||||
@ -891,9 +895,9 @@ void tsmf_presentation_free(TSMF_PRESENTATION* presentation)
|
||||
TSMF_STREAM* stream;
|
||||
|
||||
tsmf_presentation_stop(presentation);
|
||||
freerdp_mutex_lock(presentation->mutex);
|
||||
WaitForSingleObject(presentation->mutex, INFINITE);
|
||||
list_remove(presentation_list, presentation);
|
||||
freerdp_mutex_unlock(presentation->mutex);
|
||||
ReleaseMutex(presentation->mutex);
|
||||
|
||||
while (list_size(presentation->stream_list) > 0)
|
||||
{
|
||||
@ -902,7 +906,7 @@ void tsmf_presentation_free(TSMF_PRESENTATION* presentation)
|
||||
}
|
||||
list_free(presentation->stream_list);
|
||||
|
||||
freerdp_mutex_free(presentation->mutex);
|
||||
CloseHandle(presentation->mutex);
|
||||
|
||||
xfree(presentation);
|
||||
}
|
||||
@ -926,9 +930,9 @@ TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, uint32 stream_id)
|
||||
stream->sample_list = list_new();
|
||||
stream->sample_ack_list = list_new();
|
||||
|
||||
freerdp_mutex_lock(presentation->mutex);
|
||||
WaitForSingleObject(presentation->mutex, INFINITE);
|
||||
list_enqueue(presentation->stream_list, stream);
|
||||
freerdp_mutex_unlock(presentation->mutex);
|
||||
ReleaseMutex(presentation->mutex);
|
||||
|
||||
return stream;
|
||||
}
|
||||
@ -997,9 +1001,9 @@ void tsmf_stream_free(TSMF_STREAM* stream)
|
||||
tsmf_stream_stop(stream);
|
||||
tsmf_stream_flush(stream);
|
||||
|
||||
freerdp_mutex_lock(presentation->mutex);
|
||||
WaitForSingleObject(presentation->mutex, INFINITE);
|
||||
list_remove(presentation->stream_list, stream);
|
||||
freerdp_mutex_unlock(presentation->mutex);
|
||||
ReleaseMutex(presentation->mutex);
|
||||
|
||||
list_free(stream->sample_list);
|
||||
list_free(stream->sample_ack_list);
|
||||
@ -1022,15 +1026,15 @@ void tsmf_stream_push_sample(TSMF_STREAM* stream, IWTSVirtualChannelCallback* pC
|
||||
{
|
||||
TSMF_SAMPLE* sample;
|
||||
|
||||
pthread_mutex_lock(&tsmf_mutex);
|
||||
WaitForSingleObject(tsmf_mutex, INFINITE);
|
||||
|
||||
if (TERMINATING)
|
||||
{
|
||||
pthread_mutex_unlock(&tsmf_mutex);
|
||||
ReleaseMutex(tsmf_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&tsmf_mutex);
|
||||
ReleaseMutex(tsmf_mutex);
|
||||
|
||||
sample = xnew(TSMF_SAMPLE);
|
||||
|
||||
@ -1054,13 +1058,15 @@ void tsmf_stream_push_sample(TSMF_STREAM* stream, IWTSVirtualChannelCallback* pC
|
||||
|
||||
static void tsmf_signal_handler(int s)
|
||||
{
|
||||
pthread_mutex_lock(&tsmf_mutex);
|
||||
TERMINATING = 1;
|
||||
pthread_mutex_unlock(&tsmf_mutex);
|
||||
LIST_ITEM* p_item;
|
||||
TSMF_PRESENTATION* presentation;
|
||||
LIST_ITEM* s_item;
|
||||
TSMF_STREAM* _stream;
|
||||
|
||||
WaitForSingleObject(tsmf_mutex, INFINITE);
|
||||
TERMINATING = 1;
|
||||
ReleaseMutex(tsmf_mutex);
|
||||
|
||||
if (presentation_list)
|
||||
{
|
||||
for (p_item = presentation_list->head; p_item; p_item = p_item->next)
|
||||
@ -1101,6 +1107,8 @@ void tsmf_media_init(void)
|
||||
sigaction(SIGUSR1, &sigtrap, 0);
|
||||
#endif
|
||||
|
||||
tsmf_mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
|
||||
if (presentation_list == NULL)
|
||||
presentation_list = list_new();
|
||||
}
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include <freerdp/utils/list.h>
|
||||
#include <freerdp/utils/thread.h>
|
||||
#include <freerdp/utils/svc_plugin.h>
|
||||
#include <freerdp/utils/mutex.h>
|
||||
#include <freerdp/utils/debug.h>
|
||||
|
||||
#include "rdpdr_types.h"
|
||||
@ -223,12 +222,12 @@ scard_irp_complete(IRP* irp)
|
||||
stream_set_pos(irp->output, pos);
|
||||
|
||||
/* Begin TS Client defect workaround. */
|
||||
freerdp_mutex_lock(scard->CompletionIdsMutex);
|
||||
WaitForSingleObject(scard->CompletionIdsMutex, INFINITE);
|
||||
/* Remove from the list the item identified by the CompletionID.
|
||||
* The function returns whether or not it was a duplicate CompletionID.
|
||||
*/
|
||||
duplicate = scard_check_for_duplicate_id(scard, irp->CompletionId);
|
||||
freerdp_mutex_unlock(scard->CompletionIdsMutex);
|
||||
ReleaseMutex(scard->CompletionIdsMutex);
|
||||
|
||||
if (false == duplicate)
|
||||
{
|
||||
@ -261,10 +260,10 @@ scard_irp_request(DEVICE* device, IRP* irp)
|
||||
CompletionIdInfo->ID = irp->CompletionId;/* "duplicate" member is set
|
||||
* to false by "xnew()"
|
||||
*/
|
||||
freerdp_mutex_lock(scard->CompletionIdsMutex);
|
||||
WaitForSingleObject(scard->CompletionIdsMutex, INFINITE);
|
||||
scard_mark_duplicate_id(scard, irp->CompletionId);
|
||||
list_enqueue(scard->CompletionIds, CompletionIdInfo);
|
||||
freerdp_mutex_unlock(scard->CompletionIdsMutex);
|
||||
ReleaseMutex(scard->CompletionIdsMutex);
|
||||
|
||||
irp->Complete = scard_irp_complete; /* Overwrite the previous
|
||||
* assignment made in
|
||||
@ -298,16 +297,15 @@ scard_irp_request(DEVICE* device, IRP* irp)
|
||||
freerdp_thread_signal(scard->thread);
|
||||
}
|
||||
|
||||
int
|
||||
DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
|
||||
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
|
||||
{
|
||||
SCARD_DEVICE* scard;
|
||||
char* name;
|
||||
char* path;
|
||||
int i, length;
|
||||
SCARD_DEVICE* scard;
|
||||
|
||||
name = (char *)pEntryPoints->plugin_data->data[1];
|
||||
path = (char *)pEntryPoints->plugin_data->data[2];
|
||||
name = (char*) pEntryPoints->plugin_data->data[1];
|
||||
path = (char*) pEntryPoints->plugin_data->data[2];
|
||||
|
||||
if (name)
|
||||
{
|
||||
@ -332,7 +330,7 @@ DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)
|
||||
scard->thread = freerdp_thread_new();
|
||||
|
||||
scard->CompletionIds = list_new();
|
||||
scard->CompletionIdsMutex = freerdp_mutex_new();
|
||||
scard->CompletionIdsMutex = CreateMutex(NULL, FALSE, NULL);
|
||||
|
||||
pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE *)scard);
|
||||
|
||||
|
@ -25,10 +25,12 @@
|
||||
|
||||
#include "devman.h"
|
||||
#include "rdpdr_types.h"
|
||||
#include <freerdp/utils/mutex.h> /* For CompletionIdsMutex */
|
||||
|
||||
#include <freerdp/utils/list.h>
|
||||
#include <freerdp/utils/debug.h>
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
/*
|
||||
* When using Windows Server 2008 R2 as the Terminal Services (TS)
|
||||
* server, and with a smart card reader connected to the TS client machine
|
||||
@ -105,7 +107,7 @@ struct _SCARD_DEVICE
|
||||
freerdp_thread* thread;
|
||||
|
||||
LIST* CompletionIds;
|
||||
freerdp_mutex CompletionIdsMutex; /* Protect the LIST from
|
||||
HANDLE CompletionIdsMutex; /* Protect the LIST from
|
||||
* multiple thread writers.
|
||||
*/
|
||||
};
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/utils/mutex.h>
|
||||
#include <freerdp/utils/semaphore.h>
|
||||
#include <freerdp/utils/load_plugin.h>
|
||||
#include <freerdp/utils/wait_obj.h>
|
||||
@ -54,7 +53,6 @@ int add_utils_suite(void)
|
||||
{
|
||||
add_test_suite(utils);
|
||||
|
||||
add_test_function(mutex);
|
||||
add_test_function(semaphore);
|
||||
add_test_function(load_plugin);
|
||||
add_test_function(wait_obj);
|
||||
@ -65,16 +63,6 @@ int add_utils_suite(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void test_mutex(void)
|
||||
{
|
||||
freerdp_mutex mutex;
|
||||
|
||||
mutex = freerdp_mutex_new();
|
||||
freerdp_mutex_lock(mutex);
|
||||
freerdp_mutex_unlock(mutex);
|
||||
freerdp_mutex_free(mutex);
|
||||
}
|
||||
|
||||
void test_semaphore(void)
|
||||
{
|
||||
freerdp_sem sem;
|
||||
|
@ -23,7 +23,6 @@ int init_utils_suite(void);
|
||||
int clean_utils_suite(void);
|
||||
int add_utils_suite(void);
|
||||
|
||||
void test_mutex(void);
|
||||
void test_semaphore(void);
|
||||
void test_load_plugin(void);
|
||||
void test_wait_obj(void);
|
||||
|
@ -1,32 +0,0 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Mutex Utils
|
||||
*
|
||||
* Copyright 2011 Vic Lee
|
||||
*
|
||||
* 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 __MUTEX_UTILS_H
|
||||
#define __MUTEX_UTILS_H
|
||||
|
||||
#include <freerdp/api.h>
|
||||
|
||||
typedef void* freerdp_mutex;
|
||||
|
||||
FREERDP_API freerdp_mutex freerdp_mutex_new(void);
|
||||
FREERDP_API void freerdp_mutex_free(freerdp_mutex mutex);
|
||||
FREERDP_API void freerdp_mutex_lock(freerdp_mutex mutex);
|
||||
FREERDP_API void freerdp_mutex_unlock(freerdp_mutex mutex);
|
||||
|
||||
#endif /* __MUTEX_UTILS_H */
|
@ -22,17 +22,18 @@
|
||||
|
||||
#include <freerdp/api.h>
|
||||
#include <freerdp/types.h>
|
||||
#include <freerdp/utils/mutex.h>
|
||||
#include <freerdp/utils/wait_obj.h>
|
||||
#ifndef _WIN32
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
typedef struct _freerdp_thread freerdp_thread;
|
||||
|
||||
struct _freerdp_thread
|
||||
{
|
||||
freerdp_mutex* mutex;
|
||||
HANDLE mutex;
|
||||
|
||||
struct wait_obj* signals[5];
|
||||
int num_signals;
|
||||
@ -54,7 +55,7 @@ FREERDP_API void freerdp_thread_free(freerdp_thread* thread);
|
||||
wait_obj_clear(_t->signals[0]); } while (0)
|
||||
#define freerdp_thread_signal(_t) wait_obj_set(_t->signals[1])
|
||||
#define freerdp_thread_reset(_t) wait_obj_clear(_t->signals[1])
|
||||
#define freerdp_thread_lock(_t) freerdp_mutex_lock(_t->mutex)
|
||||
#define freerdp_thread_unlock(_t) freerdp_mutex_unlock(_t->mutex)
|
||||
#define freerdp_thread_lock(_t) WaitForSingleObject(_t->mutex, INFINITE)
|
||||
#define freerdp_thread_unlock(_t) ReleaseMutex(_t->mutex)
|
||||
|
||||
#endif /* __THREAD_UTILS_H */
|
||||
|
@ -34,11 +34,15 @@ set_target_properties(freerdp-channels PROPERTIES VERSION ${FREERDP_VERSION_FULL
|
||||
set(FREERDP_CHANNELS_LIBS)
|
||||
|
||||
if(WITH_MONOLITHIC_BUILD)
|
||||
set(FREERDP_CHANNELS_LIBS ${FREERDP_CHANNELS_LIBS} winpr)
|
||||
set(FREERDP_LIBS ${FREERDP_LIBS} ${FREERDP_CHANNELS_LIBS} PARENT_SCOPE)
|
||||
else()
|
||||
set(FREERDP_CHANNELS_LIBS ${FREERDP_CHANNELS_LIBS}
|
||||
freerdp-utils)
|
||||
|
||||
set(FREERDP_CHANNELS_LIBS ${FREERDP_CHANNELS_LIBS}
|
||||
winpr-synch)
|
||||
|
||||
target_link_libraries(freerdp-channels ${FREERDP_CHANNELS_LIBS})
|
||||
install(TARGETS freerdp-channels DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
@ -47,11 +47,12 @@
|
||||
#include <freerdp/utils/memory.h>
|
||||
#include <freerdp/utils/list.h>
|
||||
#include <freerdp/utils/semaphore.h>
|
||||
#include <freerdp/utils/mutex.h>
|
||||
#include <freerdp/utils/wait_obj.h>
|
||||
#include <freerdp/utils/load_plugin.h>
|
||||
#include <freerdp/utils/event.h>
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#include "libchannels.h"
|
||||
|
||||
#define CHANNEL_MAX_COUNT 30
|
||||
@ -120,7 +121,7 @@ struct rdp_channels
|
||||
struct wait_obj* signal;
|
||||
|
||||
/* used for sync write */
|
||||
freerdp_mutex sync_data_mutex;
|
||||
HANDLE sync_data_mutex;
|
||||
LIST* sync_data_list;
|
||||
|
||||
/* used for sync event */
|
||||
@ -148,8 +149,8 @@ static rdpChannelsList* g_channels_list;
|
||||
static int g_open_handle_sequence;
|
||||
|
||||
/* For locking the global resources */
|
||||
static freerdp_mutex g_mutex_init;
|
||||
static freerdp_mutex g_mutex_list;
|
||||
static HANDLE g_mutex_init;
|
||||
static HANDLE g_mutex_list;
|
||||
|
||||
/* returns the channels for the open handle passed in */
|
||||
static rdpChannels* freerdp_channels_find_by_open_handle(int open_handle, int* pindex)
|
||||
@ -158,7 +159,7 @@ static rdpChannels* freerdp_channels_find_by_open_handle(int open_handle, int* p
|
||||
rdpChannels* channels;
|
||||
rdpChannelsList* channels_list;
|
||||
|
||||
freerdp_mutex_lock(g_mutex_list);
|
||||
WaitForSingleObject(g_mutex_list, INFINITE);
|
||||
|
||||
for (channels_list = g_channels_list; channels_list; channels_list = channels_list->next)
|
||||
{
|
||||
@ -168,14 +169,14 @@ static rdpChannels* freerdp_channels_find_by_open_handle(int open_handle, int* p
|
||||
{
|
||||
if (channels->channels_data[lindex].open_handle == open_handle)
|
||||
{
|
||||
freerdp_mutex_unlock(g_mutex_list);
|
||||
ReleaseMutex(g_mutex_list);
|
||||
*pindex = lindex;
|
||||
return channels;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
freerdp_mutex_unlock(g_mutex_list);
|
||||
ReleaseMutex(g_mutex_list);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -186,19 +187,19 @@ static rdpChannels* freerdp_channels_find_by_instance(freerdp* instance)
|
||||
rdpChannels* channels;
|
||||
rdpChannelsList* channels_list;
|
||||
|
||||
freerdp_mutex_lock(g_mutex_list);
|
||||
WaitForSingleObject(g_mutex_list, INFINITE);
|
||||
|
||||
for (channels_list = g_channels_list; channels_list; channels_list = channels_list->next)
|
||||
{
|
||||
channels = channels_list->channels;
|
||||
if (channels->instance == instance)
|
||||
{
|
||||
freerdp_mutex_unlock(g_mutex_list);
|
||||
ReleaseMutex(g_mutex_list);
|
||||
return channels;
|
||||
}
|
||||
}
|
||||
|
||||
freerdp_mutex_unlock(g_mutex_list);
|
||||
ReleaseMutex(g_mutex_list);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -353,9 +354,9 @@ static uint32 FREERDP_CC MyVirtualChannelInit(void** ppInitHandle, PCHANNEL_DEF
|
||||
lchannel_def = pChannel + index;
|
||||
lchannel_data = channels->channels_data + channels->num_channels_data;
|
||||
|
||||
freerdp_mutex_lock(g_mutex_list);
|
||||
WaitForSingleObject(g_mutex_list, INFINITE);
|
||||
lchannel_data->open_handle = g_open_handle_sequence++;
|
||||
freerdp_mutex_unlock(g_mutex_list);
|
||||
ReleaseMutex(g_mutex_list);
|
||||
|
||||
lchannel_data->flags = 1; /* init */
|
||||
strncpy(lchannel_data->name, lchannel_def->name, CHANNEL_NAME_LEN);
|
||||
@ -508,11 +509,11 @@ static uint32 FREERDP_CC MyVirtualChannelWrite(uint32 openHandle, void* pData, u
|
||||
return CHANNEL_RC_NOT_OPEN;
|
||||
}
|
||||
|
||||
freerdp_mutex_lock(channels->sync_data_mutex); /* lock channels->sync* vars */
|
||||
WaitForSingleObject(channels->sync_data_mutex, INFINITE); /* lock channels->sync* vars */
|
||||
|
||||
if (!channels->is_connected)
|
||||
{
|
||||
freerdp_mutex_unlock(channels->sync_data_mutex);
|
||||
ReleaseMutex(channels->sync_data_mutex);
|
||||
DEBUG_CHANNELS("error not connected");
|
||||
return CHANNEL_RC_NOT_CONNECTED;
|
||||
}
|
||||
@ -523,7 +524,7 @@ static uint32 FREERDP_CC MyVirtualChannelWrite(uint32 openHandle, void* pData, u
|
||||
item->user_data = pUserData;
|
||||
item->index = index;
|
||||
list_enqueue(channels->sync_data_list, item);
|
||||
freerdp_mutex_unlock(channels->sync_data_mutex);
|
||||
ReleaseMutex(channels->sync_data_mutex);
|
||||
|
||||
/* set the event */
|
||||
wait_obj_set(channels->signal);
|
||||
@ -591,8 +592,8 @@ int freerdp_channels_global_init(void)
|
||||
g_init_channels = NULL;
|
||||
g_channels_list = NULL;
|
||||
g_open_handle_sequence = 1;
|
||||
g_mutex_init = freerdp_mutex_new();
|
||||
g_mutex_list = freerdp_mutex_new();
|
||||
g_mutex_init = CreateMutex(NULL, FALSE, NULL);
|
||||
g_mutex_list = CreateMutex(NULL, FALSE, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -602,8 +603,8 @@ int freerdp_channels_global_uninit(void)
|
||||
while (g_channels_list)
|
||||
freerdp_channels_free(g_channels_list->channels);
|
||||
|
||||
freerdp_mutex_free(g_mutex_init);
|
||||
freerdp_mutex_free(g_mutex_list);
|
||||
CloseHandle(g_mutex_init);
|
||||
CloseHandle(g_mutex_list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -615,7 +616,7 @@ rdpChannels* freerdp_channels_new(void)
|
||||
|
||||
channels = xnew(rdpChannels);
|
||||
|
||||
channels->sync_data_mutex = freerdp_mutex_new();
|
||||
channels->sync_data_mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
channels->sync_data_list = list_new();
|
||||
|
||||
channels->event_sem = freerdp_sem_new(1);
|
||||
@ -625,10 +626,10 @@ rdpChannels* freerdp_channels_new(void)
|
||||
channels_list = xnew(rdpChannelsList);
|
||||
channels_list->channels = channels;
|
||||
|
||||
freerdp_mutex_lock(g_mutex_list);
|
||||
WaitForSingleObject(g_mutex_list, INFINITE);
|
||||
channels_list->next = g_channels_list;
|
||||
g_channels_list = channels_list;
|
||||
freerdp_mutex_unlock(g_mutex_list);
|
||||
ReleaseMutex(g_mutex_list);
|
||||
|
||||
return channels;
|
||||
}
|
||||
@ -638,7 +639,7 @@ void freerdp_channels_free(rdpChannels* channels)
|
||||
rdpChannelsList* list;
|
||||
rdpChannelsList* prev;
|
||||
|
||||
freerdp_mutex_free(channels->sync_data_mutex);
|
||||
CloseHandle(channels->sync_data_mutex);
|
||||
list_free(channels->sync_data_list);
|
||||
|
||||
freerdp_sem_free(channels->event_sem);
|
||||
@ -646,7 +647,7 @@ void freerdp_channels_free(rdpChannels* channels)
|
||||
|
||||
/* Remove from global list */
|
||||
|
||||
freerdp_mutex_lock(g_mutex_list);
|
||||
WaitForSingleObject(g_mutex_list, INFINITE);
|
||||
|
||||
for (prev = NULL, list = g_channels_list; list; prev = list, list = list->next)
|
||||
{
|
||||
@ -663,7 +664,7 @@ void freerdp_channels_free(rdpChannels* channels)
|
||||
xfree(list);
|
||||
}
|
||||
|
||||
freerdp_mutex_unlock(g_mutex_list);
|
||||
ReleaseMutex(g_mutex_list);
|
||||
|
||||
xfree(channels);
|
||||
}
|
||||
@ -709,13 +710,13 @@ int freerdp_channels_load_plugin(rdpChannels* channels, rdpSettings* settings, c
|
||||
channels->can_call_init = 1;
|
||||
channels->settings = settings;
|
||||
|
||||
freerdp_mutex_lock(g_mutex_init);
|
||||
WaitForSingleObject(g_mutex_init, INFINITE);
|
||||
|
||||
g_init_channels = channels;
|
||||
ok = lib->entry((PCHANNEL_ENTRY_POINTS) &ep);
|
||||
g_init_channels = NULL;
|
||||
|
||||
freerdp_mutex_unlock(g_mutex_init);
|
||||
ReleaseMutex(g_mutex_init);
|
||||
|
||||
/* disable MyVirtualChannelInit */
|
||||
channels->settings = 0;
|
||||
@ -757,12 +758,12 @@ int freerdp_channels_pre_connect(rdpChannels* channels, freerdp* instance)
|
||||
strcpy(lchannel_def.name, "rdpdr");
|
||||
channels->can_call_init = 1;
|
||||
channels->settings = instance->settings;
|
||||
freerdp_mutex_lock(g_mutex_init);
|
||||
WaitForSingleObject(g_mutex_init, INFINITE);
|
||||
g_init_channels = channels;
|
||||
MyVirtualChannelInit(&dummy, &lchannel_def, 1,
|
||||
VIRTUAL_CHANNEL_VERSION_WIN2000, 0);
|
||||
g_init_channels = NULL;
|
||||
freerdp_mutex_unlock(g_mutex_init);
|
||||
ReleaseMutex(g_mutex_init);
|
||||
channels->can_call_init = 0;
|
||||
channels->settings = 0;
|
||||
DEBUG_CHANNELS("registered fake rdpdr for rdpsnd.");
|
||||
@ -912,9 +913,9 @@ static void freerdp_channels_process_sync(rdpChannels* channels, freerdp* instan
|
||||
|
||||
while (list_size(channels->sync_data_list) > 0)
|
||||
{
|
||||
freerdp_mutex_lock(channels->sync_data_mutex);
|
||||
WaitForSingleObject(channels->sync_data_mutex, INFINITE);
|
||||
item = (struct sync_data*)list_dequeue(channels->sync_data_list);
|
||||
freerdp_mutex_unlock(channels->sync_data_mutex);
|
||||
ReleaseMutex(channels->sync_data_mutex);
|
||||
|
||||
if (!item)
|
||||
break ;
|
||||
|
@ -24,9 +24,12 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <freerdp/constants.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#include "wtsvc.h"
|
||||
|
||||
#define CREATE_REQUEST_PDU 0x01
|
||||
@ -56,6 +59,7 @@ static rdpPeerChannel* wts_get_dvc_channel_by_id(WTSVirtualChannelManager* vcm,
|
||||
for (item = vcm->dvc_channel_list->head; item; item = item->next)
|
||||
{
|
||||
channel = (rdpPeerChannel*) item->data;
|
||||
|
||||
if (channel->channel_id == ChannelId)
|
||||
break;
|
||||
}
|
||||
@ -72,9 +76,9 @@ static void wts_queue_receive_data(rdpPeerChannel* channel, const uint8* buffer,
|
||||
item->buffer = xmalloc(length);
|
||||
memcpy(item->buffer, buffer, length);
|
||||
|
||||
freerdp_mutex_lock(channel->mutex);
|
||||
WaitForSingleObject(channel->mutex, INFINITE);
|
||||
list_enqueue(channel->receive_queue, item);
|
||||
freerdp_mutex_unlock(channel->mutex);
|
||||
ReleaseMutex(channel->mutex);
|
||||
|
||||
wait_obj_set(channel->receive_event);
|
||||
}
|
||||
@ -87,9 +91,9 @@ static void wts_queue_send_item(rdpPeerChannel* channel, wts_data_item* item)
|
||||
|
||||
item->channel_id = channel->channel_id;
|
||||
|
||||
freerdp_mutex_lock(vcm->mutex);
|
||||
WaitForSingleObject(vcm->mutex, INFINITE);
|
||||
list_enqueue(vcm->send_queue, item);
|
||||
freerdp_mutex_unlock(vcm->mutex);
|
||||
ReleaseMutex(vcm->mutex);
|
||||
|
||||
wait_obj_set(vcm->send_event);
|
||||
}
|
||||
@ -122,6 +126,7 @@ static void wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, uint
|
||||
|
||||
if (length < 3)
|
||||
return;
|
||||
|
||||
stream_seek_uint8(channel->receive_data); /* Pad (1 byte) */
|
||||
stream_read_uint16(channel->receive_data, Version);
|
||||
|
||||
@ -364,12 +369,13 @@ WTSVirtualChannelManager* WTSCreateVirtualChannelManager(freerdp_peer* client)
|
||||
WTSVirtualChannelManager* vcm;
|
||||
|
||||
vcm = xnew(WTSVirtualChannelManager);
|
||||
|
||||
if (vcm != NULL)
|
||||
{
|
||||
vcm->client = client;
|
||||
vcm->send_event = wait_obj_new();
|
||||
vcm->send_queue = list_new();
|
||||
vcm->mutex = freerdp_mutex_new();
|
||||
vcm->mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
vcm->dvc_channel_id_seq = 1;
|
||||
vcm->dvc_channel_list = list_new();
|
||||
|
||||
@ -403,7 +409,7 @@ void WTSDestroyVirtualChannelManager(WTSVirtualChannelManager* vcm)
|
||||
wts_data_item_free(item);
|
||||
}
|
||||
list_free(vcm->send_queue);
|
||||
freerdp_mutex_free(vcm->mutex);
|
||||
CloseHandle(vcm->mutex);
|
||||
xfree(vcm);
|
||||
}
|
||||
}
|
||||
@ -441,18 +447,22 @@ boolean WTSVirtualChannelManagerCheckFileDescriptor(WTSVirtualChannelManager* vc
|
||||
|
||||
wait_obj_clear(vcm->send_event);
|
||||
|
||||
freerdp_mutex_lock(vcm->mutex);
|
||||
WaitForSingleObject(vcm->mutex, INFINITE);
|
||||
|
||||
while ((item = (wts_data_item*) list_dequeue(vcm->send_queue)) != NULL)
|
||||
{
|
||||
if (vcm->client->SendChannelData(vcm->client, item->channel_id, item->buffer, item->length) == false)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
wts_data_item_free(item);
|
||||
|
||||
if (result == false)
|
||||
break;
|
||||
}
|
||||
freerdp_mutex_unlock(vcm->mutex);
|
||||
|
||||
ReleaseMutex(vcm->mutex);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -483,12 +493,12 @@ void* WTSVirtualChannelOpenEx(
|
||||
channel->receive_data = stream_new(client->settings->vc_chunk_size);
|
||||
channel->receive_event = wait_obj_new();
|
||||
channel->receive_queue = list_new();
|
||||
channel->mutex = freerdp_mutex_new();
|
||||
channel->mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
|
||||
freerdp_mutex_lock(vcm->mutex);
|
||||
WaitForSingleObject(vcm->mutex, INFINITE);
|
||||
channel->channel_id = vcm->dvc_channel_id_seq++;
|
||||
list_enqueue(vcm->dvc_channel_list, channel);
|
||||
freerdp_mutex_unlock(vcm->mutex);
|
||||
ReleaseMutex(vcm->mutex);
|
||||
|
||||
s = stream_new(64);
|
||||
wts_write_drdynvc_create_request(s, channel->channel_id, pVirtualName);
|
||||
@ -500,6 +510,7 @@ void* WTSVirtualChannelOpenEx(
|
||||
else
|
||||
{
|
||||
len = strlen(pVirtualName);
|
||||
|
||||
if (len > 8)
|
||||
return NULL;
|
||||
|
||||
@ -511,10 +522,12 @@ void* WTSVirtualChannelOpenEx(
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= client->settings->num_channels)
|
||||
return NULL;
|
||||
|
||||
channel = (rdpPeerChannel*) client->settings->channels[i].handle;
|
||||
|
||||
if (channel == NULL)
|
||||
{
|
||||
channel = xnew(rdpPeerChannel);
|
||||
@ -526,7 +539,7 @@ void* WTSVirtualChannelOpenEx(
|
||||
channel->receive_data = stream_new(client->settings->vc_chunk_size);
|
||||
channel->receive_event = wait_obj_new();
|
||||
channel->receive_queue = list_new();
|
||||
channel->mutex = freerdp_mutex_new();
|
||||
channel->mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
|
||||
client->settings->channels[i].handle = channel;
|
||||
}
|
||||
@ -609,22 +622,27 @@ boolean WTSVirtualChannelRead(
|
||||
rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle;
|
||||
|
||||
item = (wts_data_item*) list_peek(channel->receive_queue);
|
||||
|
||||
if (item == NULL)
|
||||
{
|
||||
wait_obj_clear(channel->receive_event);
|
||||
*pBytesRead = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
*pBytesRead = item->length;
|
||||
|
||||
if (item->length > BufferSize)
|
||||
return false;
|
||||
|
||||
/* remove the first element (same as what we just peek) */
|
||||
freerdp_mutex_lock(channel->mutex);
|
||||
WaitForSingleObject(channel->mutex, INFINITE);
|
||||
list_dequeue(channel->receive_queue);
|
||||
|
||||
if (list_size(channel->receive_queue) == 0)
|
||||
wait_obj_clear(channel->receive_event);
|
||||
freerdp_mutex_unlock(channel->mutex);
|
||||
|
||||
ReleaseMutex(channel->mutex);
|
||||
|
||||
memcpy(Buffer, item->buffer, item->length);
|
||||
wts_data_item_free(item) ;
|
||||
@ -725,9 +743,9 @@ boolean WTSVirtualChannelClose(
|
||||
}
|
||||
else
|
||||
{
|
||||
freerdp_mutex_lock(vcm->mutex);
|
||||
WaitForSingleObject(vcm->mutex, INFINITE);
|
||||
list_remove(vcm->dvc_channel_list, channel);
|
||||
freerdp_mutex_unlock(vcm->mutex);
|
||||
ReleaseMutex(vcm->mutex);
|
||||
|
||||
if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
|
||||
{
|
||||
@ -750,7 +768,7 @@ boolean WTSVirtualChannelClose(
|
||||
list_free(channel->receive_queue);
|
||||
}
|
||||
if (channel->mutex)
|
||||
freerdp_mutex_free(channel->mutex);
|
||||
CloseHandle(channel->mutex);
|
||||
xfree(channel);
|
||||
}
|
||||
return true;
|
||||
|
@ -23,11 +23,12 @@
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/utils/stream.h>
|
||||
#include <freerdp/utils/list.h>
|
||||
#include <freerdp/utils/mutex.h>
|
||||
#include <freerdp/utils/debug.h>
|
||||
#include <freerdp/utils/wait_obj.h>
|
||||
#include <freerdp/channels/wtsvc.h>
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#ifdef WITH_DEBUG_DVC
|
||||
#define DEBUG_DVC(fmt, ...) DEBUG_CLASS(DVC, fmt, ## __VA_ARGS__)
|
||||
#else
|
||||
@ -67,7 +68,7 @@ struct rdp_peer_channel
|
||||
STREAM* receive_data;
|
||||
struct wait_obj* receive_event;
|
||||
LIST* receive_queue;
|
||||
freerdp_mutex mutex;
|
||||
HANDLE mutex;
|
||||
|
||||
uint8 dvc_open_state;
|
||||
uint32 dvc_total_length;
|
||||
@ -78,7 +79,7 @@ struct WTSVirtualChannelManager
|
||||
freerdp_peer* client;
|
||||
struct wait_obj* send_event;
|
||||
LIST* send_queue;
|
||||
freerdp_mutex mutex;
|
||||
HANDLE mutex;
|
||||
|
||||
rdpPeerChannel* drdynvc_channel;
|
||||
uint8 drdynvc_state;
|
||||
|
@ -31,7 +31,6 @@ set(FREERDP_UTILS_SRCS
|
||||
file.c
|
||||
load_plugin.c
|
||||
memory.c
|
||||
mutex.c
|
||||
passphrase.c
|
||||
pcap.c
|
||||
profiler.c
|
||||
@ -72,8 +71,10 @@ if(${CMAKE_SYSTEM_NAME} MATCHES SunOS)
|
||||
endif()
|
||||
|
||||
if(WITH_MONOLITHIC_BUILD)
|
||||
set(FREERDP_UTILS_LIBS ${FREERDP_UTILS_LIBS} winpr)
|
||||
set(FREERDP_LIBS ${FREERDP_LIBS} ${FREERDP_UTILS_LIBS} PARENT_SCOPE)
|
||||
else()
|
||||
set(FREERDP_UTILS_LIBS ${FREERDP_UTILS_LIBS} winpr-synch)
|
||||
target_link_libraries(freerdp-utils ${FREERDP_UTILS_LIBS})
|
||||
install(TARGETS freerdp-utils DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Mutex Utils
|
||||
*
|
||||
* Copyright 2011 Vic Lee
|
||||
*
|
||||
* 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/mutex.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define freerdp_mutex_t HANDLE
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#define freerdp_mutex_t pthread_mutex_t
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Mutex are used to prevent concurrent accesses to specific portions of code.
|
||||
* This funciton and the other freerdp_mutex_*() function are defining a portable API
|
||||
* to get mutex for both Windows and Linux, where the lower level implementation is very different.
|
||||
*
|
||||
* This function creates a new freerdp_mutex object.
|
||||
* Use freerdp_mutex_lock() to get exclusive ownership of the mutex, and lock a given (protected) portion of code.
|
||||
* Use freerdp_mutex_unlock() to release your ownership on a mutex.
|
||||
* Use freerdp_mutex_free() to release the resources associated with the mutex when it is no longer needed.
|
||||
*
|
||||
* @return a freerdp_mutex pointer. This should be considered opaque, as the implementation is platform dependent.
|
||||
* NULL is returned if an allocation or initialization error occurred.
|
||||
*
|
||||
* @see pthread documentation for Linux implementation of mutexes
|
||||
* @see MSDN http://msdn.microsoft.com/en-us/library/windows/desktop/ms682411%28v=vs.85%29.aspx for Windows implementation
|
||||
*/
|
||||
freerdp_mutex freerdp_mutex_new(void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
freerdp_mutex_t mutex;
|
||||
mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
return (freerdp_mutex) mutex;
|
||||
#else
|
||||
freerdp_mutex_t* mutex;
|
||||
mutex = xnew(freerdp_mutex_t);
|
||||
if (mutex)
|
||||
pthread_mutex_init(mutex, 0);
|
||||
return mutex;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is used to deallocate all resources associated with a freerdp_mutex object.
|
||||
*
|
||||
* @param mutex [in] - Pointer to the mutex that needs to be deallocated.
|
||||
* On return, this object is not valid anymore.
|
||||
*/
|
||||
void freerdp_mutex_free(freerdp_mutex mutex)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
CloseHandle((freerdp_mutex_t) mutex);
|
||||
#else
|
||||
pthread_mutex_destroy((freerdp_mutex_t*) mutex);
|
||||
xfree(mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this function to get exclusive ownership of the mutex.
|
||||
* This should be called before entering a portion of code that needs to be protected against concurrent accesses.
|
||||
* Use the freerdp_mutex_unlock() call to release ownership when you leave this protected code.
|
||||
*
|
||||
* @param mutex [in] - An initialized freerdp_mutex object, as returned from a call to freerdp_mutex_new().
|
||||
* This function will suspend the running thread when called, until the mutex is available.
|
||||
* Only one thread at a time will be allowed to continue execution.
|
||||
*/
|
||||
void freerdp_mutex_lock(freerdp_mutex mutex)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
WaitForSingleObject((freerdp_mutex_t) mutex, INFINITE);
|
||||
#else
|
||||
pthread_mutex_lock(mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this function to release your ownership on a mutex.
|
||||
* This should be called when leaving a portion of code that needs to be protected against concurrent accesses.
|
||||
* DO NOT use this call on a mutex that you do not own. See freerdp_mutex_lock() for getting ownership on a mutex.
|
||||
*
|
||||
* @param mutex [in] - Pointer to a mutex that was locked by a call to freerdp_mutex_lock().
|
||||
*/
|
||||
void freerdp_mutex_unlock(freerdp_mutex mutex)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
ReleaseMutex((freerdp_mutex_t) mutex);
|
||||
#else
|
||||
pthread_mutex_unlock(mutex);
|
||||
#endif
|
||||
}
|
@ -28,7 +28,6 @@
|
||||
|
||||
#include <freerdp/constants.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
#include <freerdp/utils/mutex.h>
|
||||
#include <freerdp/utils/debug.h>
|
||||
#include <freerdp/utils/stream.h>
|
||||
#include <freerdp/utils/list.h>
|
||||
@ -47,7 +46,7 @@ struct rdp_svc_plugin_list
|
||||
static rdpSvcPluginList* g_svc_plugin_list = NULL;
|
||||
|
||||
/* For locking the global resources */
|
||||
static freerdp_mutex g_mutex = NULL;
|
||||
static HANDLE g_mutex = NULL;
|
||||
|
||||
/* Queue for receiving packets */
|
||||
struct _svc_data_in_item
|
||||
@ -84,20 +83,24 @@ struct rdp_svc_plugin_private
|
||||
|
||||
static rdpSvcPlugin* svc_plugin_find_by_init_handle(void* init_handle)
|
||||
{
|
||||
rdpSvcPluginList * list;
|
||||
rdpSvcPlugin * plugin;
|
||||
rdpSvcPluginList* list;
|
||||
rdpSvcPlugin* plugin;
|
||||
|
||||
WaitForSingleObject(g_mutex, INFINITE);
|
||||
|
||||
freerdp_mutex_lock(g_mutex);
|
||||
for (list = g_svc_plugin_list; list; list = list->next)
|
||||
{
|
||||
plugin = list->plugin;
|
||||
|
||||
if (plugin->priv->init_handle == init_handle)
|
||||
{
|
||||
freerdp_mutex_unlock(g_mutex);
|
||||
ReleaseMutex(g_mutex);
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
freerdp_mutex_unlock(g_mutex);
|
||||
|
||||
ReleaseMutex(g_mutex);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -106,17 +109,17 @@ static rdpSvcPlugin* svc_plugin_find_by_open_handle(uint32 open_handle)
|
||||
rdpSvcPluginList * list;
|
||||
rdpSvcPlugin * plugin;
|
||||
|
||||
freerdp_mutex_lock(g_mutex);
|
||||
WaitForSingleObject(g_mutex, INFINITE);
|
||||
for (list = g_svc_plugin_list; list; list = list->next)
|
||||
{
|
||||
plugin = list->plugin;
|
||||
if (plugin->priv->open_handle == open_handle)
|
||||
{
|
||||
freerdp_mutex_unlock(g_mutex);
|
||||
ReleaseMutex(g_mutex);
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
freerdp_mutex_unlock(g_mutex);
|
||||
ReleaseMutex(g_mutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -126,7 +129,7 @@ static void svc_plugin_remove(rdpSvcPlugin* plugin)
|
||||
rdpSvcPluginList* prev;
|
||||
|
||||
/* Remove from global list */
|
||||
freerdp_mutex_lock(g_mutex);
|
||||
WaitForSingleObject(g_mutex, INFINITE);
|
||||
for (prev = NULL, list = g_svc_plugin_list; list; prev = list, list = list->next)
|
||||
{
|
||||
if (list->plugin == plugin)
|
||||
@ -140,7 +143,7 @@ static void svc_plugin_remove(rdpSvcPlugin* plugin)
|
||||
g_svc_plugin_list = list->next;
|
||||
xfree(list);
|
||||
}
|
||||
freerdp_mutex_unlock(g_mutex);
|
||||
ReleaseMutex(g_mutex);
|
||||
}
|
||||
|
||||
static void svc_plugin_process_received(rdpSvcPlugin* plugin, void* pData, uint32 dataLength,
|
||||
@ -372,7 +375,7 @@ void svc_plugin_init(rdpSvcPlugin* plugin, CHANNEL_ENTRY_POINTS* pEntryPoints)
|
||||
* VirtualChannelInit at a time. So this should be safe.
|
||||
*/
|
||||
if (g_mutex == NULL)
|
||||
g_mutex = freerdp_mutex_new();
|
||||
g_mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
|
||||
memcpy(&plugin->channel_entry_points, pEntryPoints, pEntryPoints->cbSize);
|
||||
|
||||
@ -382,10 +385,10 @@ void svc_plugin_init(rdpSvcPlugin* plugin, CHANNEL_ENTRY_POINTS* pEntryPoints)
|
||||
list = xnew(rdpSvcPluginList);
|
||||
list->plugin = plugin;
|
||||
|
||||
freerdp_mutex_lock(g_mutex);
|
||||
WaitForSingleObject(g_mutex, INFINITE);
|
||||
list->next = g_svc_plugin_list;
|
||||
g_svc_plugin_list = list;
|
||||
freerdp_mutex_unlock(g_mutex);
|
||||
ReleaseMutex(g_mutex);
|
||||
|
||||
plugin->channel_entry_points.pVirtualChannelInit(&plugin->priv->init_handle,
|
||||
&plugin->channel_def, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, svc_plugin_init_event);
|
||||
|
@ -43,7 +43,7 @@ freerdp_thread* freerdp_thread_new(void)
|
||||
freerdp_thread* thread;
|
||||
|
||||
thread = xnew(freerdp_thread);
|
||||
thread->mutex = freerdp_mutex_new();
|
||||
thread->mutex = CreateMutex(NULL, FALSE, NULL);
|
||||
thread->signals[0] = wait_obj_new();
|
||||
thread->signals[1] = wait_obj_new();
|
||||
thread->num_signals = 2;
|
||||
@ -87,9 +87,10 @@ void freerdp_thread_free(freerdp_thread* thread)
|
||||
|
||||
for (i = 0; i < thread->num_signals; i++)
|
||||
wait_obj_free(thread->signals[i]);
|
||||
|
||||
thread->num_signals = 0;
|
||||
|
||||
freerdp_mutex_free(thread->mutex);
|
||||
CloseHandle(thread->mutex);
|
||||
thread->mutex = NULL;
|
||||
|
||||
xfree(thread);
|
||||
|
@ -39,6 +39,7 @@ WINPR_API BOOL winpr_Handle_Remove(HANDLE handle);
|
||||
|
||||
WINPR_API ULONG winpr_Handle_GetType(HANDLE handle);
|
||||
WINPR_API PVOID winpr_Handle_GetObject(HANDLE handle);
|
||||
WINPR_API BOOL winpr_Handle_GetInfo(HANDLE handle, ULONG* pType, PVOID* pObject);
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
|
@ -71,11 +71,6 @@ WINPR_API HANDLE OpenSemaphoreW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCW
|
||||
|
||||
WINPR_API BOOL ReleaseSemaphore(HANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviousCount);
|
||||
|
||||
#define WAIT_OBJECT_0 0x00000000L
|
||||
#define WAIT_ABANDONED 0x00000080L
|
||||
#define WAIT_TIMEOUT 0x00000102L
|
||||
#define WAIT_FAILED ((DWORD) 0xFFFFFFFF)
|
||||
|
||||
/* Event */
|
||||
|
||||
WINPR_API HANDLE CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCSTR lpName);
|
||||
@ -180,7 +175,15 @@ WINPR_API BOOL WaitOnAddress(VOID volatile *Address, PVOID CompareAddress, SIZE_
|
||||
|
||||
/* Wait */
|
||||
|
||||
#define INFINITE 0xFFFFFFFF
|
||||
|
||||
#define WAIT_OBJECT_0 0x00000000L
|
||||
#define WAIT_ABANDONED 0x00000080L
|
||||
#define WAIT_TIMEOUT 0x00000102L
|
||||
#define WAIT_FAILED ((DWORD) 0xFFFFFFFF)
|
||||
|
||||
WINPR_API DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds);
|
||||
WINPR_API DWORD WaitForSingleObjectEx(HANDLE hHandle, DWORD dwMilliseconds, BOOL bAlertable);
|
||||
WINPR_API DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAll, DWORD dwMilliseconds);
|
||||
WINPR_API DWORD WaitForMultipleObjectsEx(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAll, DWORD dwMilliseconds, BOOL bAlertable);
|
||||
|
||||
|
@ -25,46 +25,40 @@
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#if defined __APPLE__
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <mach/mach.h>
|
||||
#include <mach/semaphore.h>
|
||||
#include <mach/task.h>
|
||||
#define winpr_sem_t semaphore_t
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#define winpr_sem_t sem_t
|
||||
#endif
|
||||
#include "../synch/synch.h"
|
||||
|
||||
BOOL CloseHandle(HANDLE hObject)
|
||||
{
|
||||
#if defined __APPLE__
|
||||
semaphore_destroy(mach_task_self(), *((winpr_sem_t*) hObject));
|
||||
#else
|
||||
sem_destroy((winpr_sem_t*) hObject);
|
||||
#endif
|
||||
ULONG Type;
|
||||
PVOID Object;
|
||||
|
||||
free(hObject);
|
||||
if (!winpr_Handle_GetInfo(hObject, &Type, &Object))
|
||||
return FALSE;
|
||||
|
||||
return 1;
|
||||
if (Type == HANDLE_TYPE_MUTEX)
|
||||
{
|
||||
pthread_mutex_destroy((pthread_mutex_t*) Object);
|
||||
free(Object);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle,
|
||||
LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions)
|
||||
{
|
||||
return 1;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL GetHandleInformation(HANDLE hObject, LPDWORD lpdwFlags)
|
||||
{
|
||||
return 1;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL SetHandleInformation(HANDLE hObject, DWORD dwMask, DWORD dwFlags)
|
||||
{
|
||||
return 1;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -36,7 +36,7 @@ typedef struct _HANDLE_TABLE
|
||||
{
|
||||
LONG Count;
|
||||
LONG MaxCount;
|
||||
PHANDLE_TABLE_ENTRY* Entries;
|
||||
PHANDLE_TABLE_ENTRY Entries;
|
||||
} HANDLE_TABLE, *PHANDLE_TABLE;
|
||||
|
||||
static HANDLE_TABLE HandleTable = { 0, 0, NULL };
|
||||
@ -54,7 +54,7 @@ void winpr_HandleTable_New()
|
||||
|
||||
size = sizeof(HANDLE_TABLE_ENTRY) * HandleTable.MaxCount;
|
||||
|
||||
HandleTable.Entries = (PHANDLE_TABLE_ENTRY*) malloc(size);
|
||||
HandleTable.Entries = (PHANDLE_TABLE_ENTRY) malloc(size);
|
||||
ZeroMemory(HandleTable.Entries, size);
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ void winpr_HandleTable_Grow()
|
||||
|
||||
size = sizeof(HANDLE_TABLE_ENTRY) * HandleTable.MaxCount;
|
||||
|
||||
HandleTable.Entries = (PHANDLE_TABLE_ENTRY*) realloc(HandleTable.Entries, size);
|
||||
HandleTable.Entries = (PHANDLE_TABLE_ENTRY) realloc(HandleTable.Entries, size);
|
||||
ZeroMemory((void*) &HandleTable.Entries[HandleTable.MaxCount / 2], size / 2);
|
||||
}
|
||||
|
||||
@ -86,12 +86,12 @@ HANDLE winpr_Handle_Insert(ULONG Type, PVOID Object)
|
||||
|
||||
for (index = 0; index < (int) HandleTable.MaxCount; index++)
|
||||
{
|
||||
if (HandleTable.Entries[index]->Object == NULL)
|
||||
if (HandleTable.Entries[index].Object == NULL)
|
||||
{
|
||||
HandleTable.Count++;
|
||||
|
||||
HandleTable.Entries[index]->Type = Type;
|
||||
HandleTable.Entries[index]->Object = Object;
|
||||
HandleTable.Entries[index].Type = Type;
|
||||
HandleTable.Entries[index].Object = Object;
|
||||
|
||||
return Object;
|
||||
}
|
||||
@ -114,10 +114,10 @@ BOOL winpr_Handle_Remove(HANDLE handle)
|
||||
|
||||
for (index = 0; index < (int) HandleTable.MaxCount; index++)
|
||||
{
|
||||
if (HandleTable.Entries[index]->Object == handle)
|
||||
if (HandleTable.Entries[index].Object == handle)
|
||||
{
|
||||
HandleTable.Entries[index]->Type = HANDLE_TYPE_NONE;
|
||||
HandleTable.Entries[index]->Object = NULL;
|
||||
HandleTable.Entries[index].Type = HANDLE_TYPE_NONE;
|
||||
HandleTable.Entries[index].Object = NULL;
|
||||
HandleTable.Count--;
|
||||
|
||||
return TRUE;
|
||||
@ -135,8 +135,8 @@ ULONG winpr_Handle_GetType(HANDLE handle)
|
||||
|
||||
for (index = 0; index < (int) HandleTable.MaxCount; index++)
|
||||
{
|
||||
if (HandleTable.Entries[index]->Object == handle)
|
||||
return HandleTable.Entries[index]->Type;
|
||||
if (HandleTable.Entries[index].Object == handle)
|
||||
return HandleTable.Entries[index].Type;
|
||||
}
|
||||
|
||||
return HANDLE_TYPE_NONE;
|
||||
@ -149,5 +149,24 @@ PVOID winpr_Handle_GetObject(HANDLE handle)
|
||||
return handle;
|
||||
}
|
||||
|
||||
BOOL winpr_Handle_GetInfo(HANDLE handle, ULONG* pType, PVOID* pObject)
|
||||
{
|
||||
int index;
|
||||
|
||||
HandleTable_GetInstance();
|
||||
|
||||
for (index = 0; index < (int) HandleTable.MaxCount; index++)
|
||||
{
|
||||
if (HandleTable.Entries[index].Object == handle)
|
||||
{
|
||||
*pType = HandleTable.Entries[index].Type;
|
||||
*pObject = HandleTable.Entries[index].Object;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#include "synch.h"
|
||||
|
||||
/**
|
||||
* CreateMutexA
|
||||
* CreateMutexW
|
||||
@ -33,24 +35,36 @@
|
||||
* ReleaseMutex
|
||||
*/
|
||||
|
||||
HANDLE CreateMutexA(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner, LPCSTR lpName)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#ifndef _WIN32
|
||||
|
||||
HANDLE CreateMutexW(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner, LPCWSTR lpName)
|
||||
{
|
||||
return NULL;
|
||||
HANDLE handle;
|
||||
pthread_mutex_t* pMutex;
|
||||
|
||||
pMutex = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
|
||||
|
||||
if (pMutex)
|
||||
pthread_mutex_init(pMutex, 0);
|
||||
|
||||
handle = winpr_Handle_Insert(HANDLE_TYPE_MUTEX, pMutex);
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
HANDLE CreateMutexA(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner, LPCSTR lpName)
|
||||
{
|
||||
return CreateMutexW(lpMutexAttributes, bInitialOwner, NULL);
|
||||
}
|
||||
|
||||
HANDLE CreateMutexExA(LPSECURITY_ATTRIBUTES lpMutexAttributes, LPCTSTR lpName, DWORD dwFlags, DWORD dwDesiredAccess)
|
||||
{
|
||||
return NULL;
|
||||
return CreateMutexW(lpMutexAttributes, FALSE, NULL);
|
||||
}
|
||||
|
||||
HANDLE CreateMutexExW(LPSECURITY_ATTRIBUTES lpMutexAttributes, LPCWSTR lpName, DWORD dwFlags, DWORD dwDesiredAccess)
|
||||
{
|
||||
return NULL;
|
||||
return CreateMutexW(lpMutexAttributes, FALSE, NULL);
|
||||
}
|
||||
|
||||
HANDLE OpenMutexA(DWORD dwDesiredAccess, BOOL bInheritHandle,LPCSTR lpName)
|
||||
@ -65,5 +79,19 @@ HANDLE OpenMutexW(DWORD dwDesiredAccess, BOOL bInheritHandle,LPCWSTR lpName)
|
||||
|
||||
BOOL ReleaseMutex(HANDLE hMutex)
|
||||
{
|
||||
ULONG Type;
|
||||
PVOID Object;
|
||||
|
||||
if (!winpr_Handle_GetInfo(hMutex, &Type, &Object))
|
||||
return FALSE;
|
||||
|
||||
if (Type == HANDLE_TYPE_MUTEX)
|
||||
{
|
||||
pthread_mutex_unlock((pthread_mutex_t*) Object);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#if defined __APPLE__
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
@ -35,4 +37,6 @@
|
||||
#define winpr_sem_t sem_t
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* WINPR_SYNCH_PRIVATE_H */
|
||||
|
@ -32,14 +32,26 @@
|
||||
* SignalObjectAndWait
|
||||
*/
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
||||
{
|
||||
#if defined __APPLE__
|
||||
semaphore_wait(*((winpr_sem_t*) hHandle));
|
||||
#else
|
||||
sem_wait((winpr_sem_t*) hHandle);
|
||||
#endif
|
||||
ULONG Type;
|
||||
PVOID Object;
|
||||
|
||||
if (!winpr_Handle_GetInfo(hHandle, &Type, &Object))
|
||||
return WAIT_FAILED;
|
||||
|
||||
if (Type == HANDLE_TYPE_MUTEX)
|
||||
{
|
||||
pthread_mutex_lock((pthread_mutex_t*) Object);
|
||||
}
|
||||
|
||||
return WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
DWORD WaitForSingleObjectEx(HANDLE hHandle, DWORD dwMilliseconds, BOOL bAlertable)
|
||||
{
|
||||
return WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
@ -57,3 +69,5 @@ DWORD SignalObjectAndWait(HANDLE hObjectToSignal, HANDLE hObjectToWaitOn, DWORD
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user