diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c8ada95e..19ab868e4 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -320,6 +320,10 @@ set(NPP_FEATURE_TYPE "OPTIONAL") set(NPP_FEATURE_PURPOSE "performance") set(NPP_FEATURE_DESCRIPTION "NVIDIA Performance Primitives library") +set(JPEG_FEATURE_TYPE "OPTIONAL") +set(JPEG_FEATURE_PURPOSE "codec") +set(JPEG_FEATURE_DESCRIPTION "use JPEG library") + if(WIN32) set(X11_FEATURE_TYPE "DISABLED") set(ZLIB_FEATURE_TYPE "DISABLED") @@ -379,6 +383,8 @@ find_feature(PCSC ${PCSC_FEATURE_TYPE} ${PCSC_FEATURE_PURPOSE} ${PCSC_FEATURE_DE find_feature(FFmpeg ${FFMPEG_FEATURE_TYPE} ${FFMPEG_FEATURE_PURPOSE} ${FFMPEG_FEATURE_DESCRIPTION}) find_feature(Gstreamer ${GSTREAMER_FEATURE_TYPE} ${GSTREAMER_FEATURE_PURPOSE} ${GSTREAMER_FEATURE_DESCRIPTION}) +find_feature(JPEG ${JPEG_FEATURE_TYPE} ${JPEG_FEATURE_PURPOSE} ${JPEG_FEATURE_DESCRIPTION}) + if(TARGET_ARCH MATCHES "x86|x64") if (NOT APPLE) # Intel Performance Primitives diff --git a/channels/audin/client/pulse/audin_pulse.c b/channels/audin/client/pulse/audin_pulse.c index 2d4906ea2..787f208bd 100644 --- a/channels/audin/client/pulse/audin_pulse.c +++ b/channels/audin/client/pulse/audin_pulse.c @@ -290,6 +290,17 @@ static void audin_pulse_stream_request_callback(pa_stream* stream, size_t length BYTE* encoded_data; AudinPulseDevice* pulse = (AudinPulseDevice*) userdata; + /* There is a race condition here where we may receive this callback + * before the buffer has been set up in the main code. It's probably + * possible to fix with additional locking, but it's easier just to + * ignore input until the buffer is ready. + */ + if (pulse->buffer == NULL) + { + /* fprintf(stderr, "%s: ignoring input, pulse buffer not ready.\n", __func__); */ + return; + } + pa_stream_peek(stream, &data, &length); frames = length / pulse->bytes_per_frame; @@ -373,6 +384,7 @@ static void audin_pulse_open(IAudinDevice* device, AudinReceive receive, void* u DEBUG_DVC(""); + pulse->buffer = NULL; pulse->receive = receive; pulse->user_data = user_data; diff --git a/channels/urbdrc/client/CMakeLists.txt b/channels/urbdrc/client/CMakeLists.txt index 53391f100..736097122 100644 --- a/channels/urbdrc/client/CMakeLists.txt +++ b/channels/urbdrc/client/CMakeLists.txt @@ -31,6 +31,10 @@ set(${MODULE_PREFIX}_SRCS include_directories(..) +find_package(UDev REQUIRED) +find_package(UUID REQUIRED) +find_package(DbusGlib REQUIRED) + add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry") set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "") @@ -38,9 +42,9 @@ set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "") #set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} libusb-devman) set(${MODULE_PREFIX}_LIBS - dbus-glib-1 - udev - uuid) + ${DBUS_GLIB_LIBRARIES} + ${UDEV_LIBRARIES} + ${UUID_LIBRARIES}) set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS MONOLITHIC ${MONOLITHIC_BUILD} diff --git a/channels/urbdrc/client/libusb/CMakeLists.txt b/channels/urbdrc/client/libusb/CMakeLists.txt index 0f66539da..47688b9b0 100644 --- a/channels/urbdrc/client/libusb/CMakeLists.txt +++ b/channels/urbdrc/client/libusb/CMakeLists.txt @@ -27,6 +27,8 @@ set(${MODULE_PREFIX}_SRCS include_directories(..) +find_package(libusb-1.0 REQUIRED) + add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "") @@ -35,9 +37,10 @@ set(${MODULE_PREFIX}_LIBS ${CMAKE_THREAD_LIBS_INIT}) set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} - dbus-glib-1 - usb-1.0 - udev) + ${DBUS_GLIB_LIBRARIES} + ${UUID_LIBRARIES} + ${LIBUSB_1_LIBRARIES} + ) set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS MONOLITHIC ${MONOLITHIC_BUILD} diff --git a/client/common/compatibility.c b/client/common/compatibility.c index 8f14199b9..788b41354 100644 --- a/client/common/compatibility.c +++ b/client/common/compatibility.c @@ -473,7 +473,9 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe CommandLineSwitchCase(arg, "p") { settings->Password = _strdup(arg->Value); - fprintf(stderr, "-p %s -> /p:%s\n", arg->Value, arg->Value); + fprintf(stderr, "-p ****** -> /p:******\n"); + /* Hide the value from 'ps'. */ + FillMemory(arg->Value, strlen(arg->Value), '*'); } CommandLineSwitchCase(arg, "s") { diff --git a/cmake/FindDBus.cmake b/cmake/FindDBus.cmake new file mode 100644 index 000000000..b002a754b --- /dev/null +++ b/cmake/FindDBus.cmake @@ -0,0 +1,73 @@ +# - Try to find the low-level D-Bus library +# Once done this will define +# +# DBUS_FOUND - system has D-Bus +# DBUS_INCLUDE_DIR - the D-Bus include directory +# DBUS_ARCH_INCLUDE_DIR - the D-Bus architecture-specific include directory +# DBUS_LIBRARIES - the libraries needed to use D-Bus + +# Copyright (c) 2008, Kevin Kofler, +# modeled after FindLibArt.cmake: +# Copyright (c) 2006, Alexander Neundorf, +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +if (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) + + # in cache already + SET(DBUS_FOUND TRUE) + +else (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) + + IF (NOT WIN32) + FIND_PACKAGE(PkgConfig) + IF (PKG_CONFIG_FOUND) + # use pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + pkg_check_modules(_DBUS_PC QUIET dbus-1) + ENDIF (PKG_CONFIG_FOUND) + ENDIF (NOT WIN32) + + FIND_PATH(DBUS_INCLUDE_DIR dbus/dbus.h + ${_DBUS_PC_INCLUDE_DIRS} + /usr/include + /usr/include/dbus-1.0 + /usr/local/include + ) + + FIND_PATH(DBUS_ARCH_INCLUDE_DIR dbus/dbus-arch-deps.h + ${_DBUS_PC_INCLUDE_DIRS} + /usr/lib${LIB_SUFFIX}/include + /usr/lib${LIB_SUFFIX}/dbus-1.0/include + /usr/lib64/include + /usr/lib64/dbus-1.0/include + /usr/lib/include + /usr/lib/dbus-1.0/include + ) + + FIND_LIBRARY(DBUS_LIBRARIES NAMES dbus-1 dbus + PATHS + ${_DBUS_PC_LIBDIR} + ) + + + if (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) + set(DBUS_FOUND TRUE) + endif (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) + + + if (DBUS_FOUND) + if (NOT DBus_FIND_QUIETLY) + message(STATUS "Found D-Bus: ${DBUS_LIBRARIES}") + endif (NOT DBus_FIND_QUIETLY) + else (DBUS_FOUND) + if (DBus_FIND_REQUIRED) + message(FATAL_ERROR "Could NOT find D-Bus") + endif (DBus_FIND_REQUIRED) + endif (DBUS_FOUND) + + MARK_AS_ADVANCED(DBUS_INCLUDE_DIR DBUS_ARCH_INCLUDE_DIR DBUS_LIBRARIES) + +endif (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) + diff --git a/cmake/FindDbusGlib.cmake b/cmake/FindDbusGlib.cmake new file mode 100644 index 000000000..ae966bc65 --- /dev/null +++ b/cmake/FindDbusGlib.cmake @@ -0,0 +1,38 @@ +# DbusGlib library detection +# +# Copyright 2013 Thinstuff Technologies GmbH +# Copyright 2013 Armin Novak +# +# 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. + +find_package(PkgConfig) +pkg_check_modules(PC_DBUS_GLIB QUIET dbus-glib-1) +set(DBUS_GLIB_DEFINITIONS ${PC_DBUS_GLIB_CFLAGS_OTHER}) + +find_path(DBUS_GLIB_INCLUDE_DIR dbus/dbus-glib.h + HINTS ${PC_DBUS_GLIB_INCLUDEDIR} ${PC_DBUS_GLIB_INCLUDE_DIRS} + PATH_SUFFIXES dbus-glib-1 ) + +find_library(DBUS_GLIB_LIBRARY NAMES dbus-glib-1 dbus-glib + HINTS ${PC_DBUS_GLIB_LIBDIR} ${PC_DBUS_GLIB_LIBRARY_DIRS} ) + +set(DBUS_GLIB_LIBRARIES ${DBUS_GLIB_LIBRARY} ) +set(DBUS_GLIB_INCLUDE_DIRS ${DBUS_GLIB_INCLUDE_DIR} ) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set DBUS_GLIB_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(dbus-glib DEFAULT_MSG + DBUS_GLIB_LIBRARY DBUS_GLIB_INCLUDE_DIR) + +mark_as_advanced(DBUS_GLIB_INCLUDE_DIR DBUS_GLIB_LIBRARY ) diff --git a/cmake/FindUDev.cmake b/cmake/FindUDev.cmake new file mode 100644 index 000000000..f16761572 --- /dev/null +++ b/cmake/FindUDev.cmake @@ -0,0 +1,53 @@ +# razor-de: Configure libudev environment +# +# UDEV_FOUND - system has a libudev +# UDEV_INCLUDE_DIR - where to find header files +# UDEV_LIBRARIES - the libraries to link against udev +# UDEV_STABLE - it's true when is the version greater or equals to 143 - version when the libudev was stabilized in its API +# +# copyright (c) 2011 Petr Vanek +# Redistribution and use is allowed according to the terms of the BSD license. +# + +FIND_PATH( + UDEV_INCLUDE_DIR + libudev.h + /usr/include + /usr/local/include + ${UDEV_PATH_INCLUDES} +) + +FIND_LIBRARY( + UDEV_LIBRARIES + NAMES udev libudev + PATHS + /usr/lib${LIB_SUFFIX} + /usr/local/lib${LIB_SUFFIX} + ${UDEV_PATH_LIB} +) + +IF (UDEV_LIBRARIES AND UDEV_INCLUDE_DIR) + SET(UDEV_FOUND "YES") + execute_process(COMMAND pkg-config --atleast-version=143 libudev RESULT_VARIABLE UDEV_STABLE) + # retvale is 0 of the condition is "true" so we need to negate the value... + if (UDEV_STABLE) +set(UDEV_STABLE 0) + else (UDEV_STABLE) +set(UDEV_STABLE 1) + endif (UDEV_STABLE) + message(STATUS "libudev stable: ${UDEV_STABLE}") +ENDIF (UDEV_LIBRARIES AND UDEV_INCLUDE_DIR) + +IF (UDEV_FOUND) + MESSAGE(STATUS "Found UDev: ${UDEV_LIBRARIES}") + MESSAGE(STATUS " include: ${UDEV_INCLUDE_DIR}") +ELSE (UDEV_FOUND) + MESSAGE(STATUS "UDev not found.") + MESSAGE(STATUS "UDev: You can specify includes: -DUDEV_PATH_INCLUDES=/opt/udev/include") + MESSAGE(STATUS " currently found includes: ${UDEV_INCLUDE_DIR}") + MESSAGE(STATUS "UDev: You can specify libs: -DUDEV_PATH_LIB=/opt/udev/lib") + MESSAGE(STATUS " currently found libs: ${UDEV_LIBRARIES}") + IF (UDev_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find UDev library") + ENDIF (UDev_FIND_REQUIRED) +ENDIF (UDEV_FOUND) diff --git a/cmake/FindUUID.cmake b/cmake/FindUUID.cmake new file mode 100644 index 000000000..330e5caba --- /dev/null +++ b/cmake/FindUUID.cmake @@ -0,0 +1,113 @@ +# - Try to find UUID +# Once done this will define +# +# UUID_FOUND - system has UUID +# UUID_INCLUDE_DIRS - the UUID include directory +# UUID_LIBRARIES - Link these to use UUID +# UUID_DEFINITIONS - Compiler switches required for using UUID +# +# Copyright (c) 2006 Andreas Schneider +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + + +if (UUID_LIBRARIES AND UUID_INCLUDE_DIRS) +# in cache already +set(UUID_FOUND TRUE) +else (UUID_LIBRARIES AND UUID_INCLUDE_DIRS) +find_path(UUID_INCLUDE_DIR +NAMES +uuid/uuid.h +PATHS +${UUID_DIR}/include +$ENV{UUID_DIR}/include +$ENV{UUID_DIR} +${DELTA3D_EXT_DIR}/inc +$ENV{DELTA_ROOT}/ext/inc +$ENV{DELTA_ROOT} +~/Library/Frameworks +/Library/Frameworks +/usr/local/include +/usr/include +/usr/include/gdal +/sw/include # Fink +/opt/local/include # DarwinPorts +/opt/csw/include # Blastwave +/opt/include +[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/include +/usr/freeware/include + +) + +find_library(UUID_LIBRARY +NAMES +uuid +PATHS +${UUID_DIR}/lib +$ENV{UUID_DIR}/lib +$ENV{UUID_DIR} +${DELTA3D_EXT_DIR}/lib +$ENV{DELTA_ROOT}/ext/lib +$ENV{DELTA_ROOT} +$ENV{OSG_ROOT}/lib +~/Library/Frameworks +/Library/Frameworks +/usr/local/lib +/usr/lib +/sw/lib +/opt/local/lib +/opt/csw/lib +/opt/lib +/usr/freeware/lib64 +) + +find_library(UUID_LIBRARY_DEBUG +NAMES +uuidd +PATHS +${UUID_DIR}/lib +$ENV{UUID_DIR}/lib +$ENV{UUID_DIR} +${DELTA3D_EXT_DIR}/lib +$ENV{DELTA_ROOT}/ext/lib +$ENV{DELTA_ROOT} +$ENV{OSG_ROOT}/lib +~/Library/Frameworks +/Library/Frameworks +/usr/local/lib +/usr/lib +/sw/lib +/opt/local/lib +/opt/csw/lib +/opt/lib +/usr/freeware/lib64 +) + +set(UUID_INCLUDE_DIRS +${UUID_INCLUDE_DIR} +) +set(UUID_LIBRARIES +${UUID_LIBRARY} +) + +if (UUID_INCLUDE_DIRS AND UUID_LIBRARIES) +set(UUID_FOUND TRUE) +endif (UUID_INCLUDE_DIRS AND UUID_LIBRARIES) + +if (UUID_FOUND) +if (NOT UUID_FIND_QUIETLY) +message(STATUS "Found UUID: ${UUID_LIBRARIES}") +endif (NOT UUID_FIND_QUIETLY) +else (UUID_FOUND) +if (UUID_FIND_REQUIRED) +message(FATAL_ERROR "Could not find UUID") +endif (UUID_FIND_REQUIRED) +endif (UUID_FOUND) + +# show the UUID_INCLUDE_DIRS and UUID_LIBRARIES variables only in the advanced view +mark_as_advanced(UUID_INCLUDE_DIRS UUID_LIBRARIES) + +endif (UUID_LIBRARIES AND UUID_INCLUDE_DIRS) diff --git a/cmake/Findlibusb-1.0.cmake b/cmake/Findlibusb-1.0.cmake new file mode 100644 index 000000000..0163bd521 --- /dev/null +++ b/cmake/Findlibusb-1.0.cmake @@ -0,0 +1,98 @@ +# - Try to find libusb-1.0 +# Once done this will define +# +# LIBUSB_1_FOUND - system has libusb +# LIBUSB_1_INCLUDE_DIRS - the libusb include directory +# LIBUSB_1_LIBRARIES - Link these to use libusb +# LIBUSB_1_DEFINITIONS - Compiler switches required for using libusb +# +# Adapted from cmake-modules Google Code project +# +# Copyright (c) 2006 Andreas Schneider +# +# (Changes for libusb) Copyright (c) 2008 Kyle Machulis +# +# Redistribution and use is allowed according to the terms of the New BSD license. +# +# CMake-Modules Project New BSD License +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the CMake-Modules Project nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + + +if (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) + # in cache already + set(LIBUSB_FOUND TRUE) +else (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) + find_path(LIBUSB_1_INCLUDE_DIR + NAMES +libusb.h + PATHS + /usr/include + /usr/local/include + /opt/local/include + /sw/include +PATH_SUFFIXES +libusb-1.0 + ) + + find_library(LIBUSB_1_LIBRARY + NAMES + usb-1.0 usb + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + + set(LIBUSB_1_INCLUDE_DIRS + ${LIBUSB_1_INCLUDE_DIR} + ) + set(LIBUSB_1_LIBRARIES + ${LIBUSB_1_LIBRARY} +) + + if (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES) + set(LIBUSB_1_FOUND TRUE) + endif (LIBUSB_1_INCLUDE_DIRS AND LIBUSB_1_LIBRARIES) + + if (LIBUSB_1_FOUND) + if (NOT libusb_1_FIND_QUIETLY) + message(STATUS "Found libusb-1.0:") +message(STATUS " - Includes: ${LIBUSB_1_INCLUDE_DIRS}") +message(STATUS " - Libraries: ${LIBUSB_1_LIBRARIES}") + endif (NOT libusb_1_FIND_QUIETLY) + else (LIBUSB_1_FOUND) + if (libusb_1_FIND_REQUIRED) + message(FATAL_ERROR "Could not find libusb") + endif (libusb_1_FIND_REQUIRED) + endif (LIBUSB_1_FOUND) + + # show the LIBUSB_1_INCLUDE_DIRS and LIBUSB_1_LIBRARIES variables only in the advanced view + mark_as_advanced(LIBUSB_1_INCLUDE_DIRS LIBUSB_1_LIBRARIES) + +endif (LIBUSB_1_LIBRARIES AND LIBUSB_1_INCLUDE_DIRS) diff --git a/libfreerdp/cache/bitmap.c b/libfreerdp/cache/bitmap.c index a1136a08a..fcd653b5f 100644 --- a/libfreerdp/cache/bitmap.c +++ b/libfreerdp/cache/bitmap.c @@ -40,6 +40,8 @@ void update_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) bitmap = offscreen_cache_get(cache->offscreen, memblt->cacheIndex); else bitmap = bitmap_cache_get(cache->bitmap, (BYTE) memblt->cacheId, memblt->cacheIndex); + /* XP-SP2 servers sometimes ask for cached bitmaps they've never defined. */ + if (bitmap == NULL) return; memblt->bitmap = bitmap; IFCALL(cache->bitmap->MemBlt, context, memblt); @@ -56,6 +58,8 @@ void update_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) bitmap = offscreen_cache_get(cache->offscreen, mem3blt->cacheIndex); else bitmap = bitmap_cache_get(cache->bitmap, (BYTE) mem3blt->cacheId, mem3blt->cacheIndex); + /* XP-SP2 servers sometimes ask for cached bitmaps they've never defined. */ + if (bitmap == NULL) return; style = brush->style; diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index 26825a89d..f09029e3d 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -312,8 +312,7 @@ RFX_TILE* rfx_tile_pool_take(RFX_CONTEXT* context) { RFX_TILE* tile = NULL; - if (WaitForSingleObject(Queue_Event(context->priv->TilePool), 0) == WAIT_OBJECT_0) - tile = Queue_Dequeue(context->priv->TilePool); + tile = Queue_Dequeue(context->priv->TilePool); if (!tile) { diff --git a/winpr/include/winpr/collections.h b/winpr/include/winpr/collections.h index 4ef2e3b19..e6fc2bcf5 100644 --- a/winpr/include/winpr/collections.h +++ b/winpr/include/winpr/collections.h @@ -58,7 +58,7 @@ struct _wQueue int tail; int size; void** array; - HANDLE mutex; + CRITICAL_SECTION lock; HANDLE event; wObject object; @@ -67,8 +67,8 @@ typedef struct _wQueue wQueue; WINPR_API int Queue_Count(wQueue* queue); -WINPR_API BOOL Queue_Lock(wQueue* queue); -WINPR_API BOOL Queue_Unlock(wQueue* queue); +WINPR_API void Queue_Lock(wQueue* queue); +WINPR_API void Queue_Unlock(wQueue* queue); WINPR_API HANDLE Queue_Event(wQueue* queue); @@ -93,7 +93,7 @@ struct _wStack int size; int capacity; void** array; - HANDLE mutex; + CRITICAL_SECTION lock; BOOL synchronized; wObject object; }; @@ -125,7 +125,7 @@ struct _wArrayList int size; void** array; - HANDLE mutex; + CRITICAL_SECTION lock; wObject object; }; @@ -137,8 +137,8 @@ WINPR_API BOOL ArrayList_IsFixedSized(wArrayList* arrayList); WINPR_API BOOL ArrayList_IsReadOnly(wArrayList* arrayList); WINPR_API BOOL ArrayList_IsSynchronized(wArrayList* arrayList); -WINPR_API BOOL ArrayList_Lock(wArrayList* arrayList); -WINPR_API BOOL ArrayList_Unlock(wArrayList* arrayList); +WINPR_API void ArrayList_Lock(wArrayList* arrayList); +WINPR_API void ArrayList_Unlock(wArrayList* arrayList); WINPR_API void* ArrayList_GetItem(wArrayList* arrayList, int index); WINPR_API void ArrayList_SetItem(wArrayList* arrayList, int index, void* obj); @@ -165,7 +165,7 @@ WINPR_API void ArrayList_Free(wArrayList* arrayList); struct _wDictionary { BOOL synchronized; - HANDLE mutex; + CRITICAL_SECTION lock; }; typedef struct _wDictionary wDictionary; @@ -184,7 +184,7 @@ struct _wListDictionaryItem struct _wListDictionary { BOOL synchronized; - HANDLE mutex; + CRITICAL_SECTION lock; wListDictionaryItem* head; }; @@ -227,7 +227,7 @@ typedef int (*REFERENCE_FREE)(void* context, void* ptr); struct _wReferenceTable { UINT32 size; - HANDLE mutex; + CRITICAL_SECTION lock; void* context; BOOL synchronized; wReference* array; @@ -246,7 +246,7 @@ WINPR_API void ReferenceTable_Free(wReferenceTable* referenceTable); struct _wCountdownEvent { DWORD count; - HANDLE mutex; + CRITICAL_SECTION lock; HANDLE event; DWORD initialCount; }; @@ -271,7 +271,7 @@ struct _wBufferPool int size; int capacity; void** array; - HANDLE mutex; + CRITICAL_SECTION lock; int fixedSize; DWORD alignment; BOOL synchronized; @@ -292,7 +292,7 @@ struct _wObjectPool int size; int capacity; void** array; - HANDLE mutex; + CRITICAL_SECTION lock; wObject object; BOOL synchronized; }; @@ -330,7 +330,7 @@ struct _wMessageQueue int size; int capacity; wMessage* array; - HANDLE mutex; + CRITICAL_SECTION lock; HANDLE event; }; typedef struct _wMessageQueue wMessageQueue; @@ -427,7 +427,7 @@ typedef struct _wEventType wEventType; struct _wPubSub { - HANDLE mutex; + CRITICAL_SECTION lock; BOOL synchronized; int size; @@ -436,8 +436,8 @@ struct _wPubSub }; typedef struct _wPubSub wPubSub; -WINPR_API BOOL PubSub_Lock(wPubSub* pubSub); -WINPR_API BOOL PubSub_Unlock(wPubSub* pubSub); +WINPR_API void PubSub_Lock(wPubSub* pubSub); +WINPR_API void PubSub_Unlock(wPubSub* pubSub); WINPR_API wEventType* PubSub_GetEventTypes(wPubSub* pubSub, int* count); WINPR_API void PubSub_AddEventTypes(wPubSub* pubSub, wEventType* events, int count); diff --git a/winpr/include/winpr/stream.h b/winpr/include/winpr/stream.h index e9805714b..0ad45602e 100644 --- a/winpr/include/winpr/stream.h +++ b/winpr/include/winpr/stream.h @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -236,7 +237,7 @@ struct _wStreamPool int uCapacity; wStream** uArray; - HANDLE mutex; + CRITICAL_SECTION lock; BOOL synchronized; size_t defaultSize; }; diff --git a/winpr/libwinpr/synch/critical.c b/winpr/libwinpr/synch/critical.c index 560fc512a..3466a6672 100644 --- a/winpr/libwinpr/synch/critical.c +++ b/winpr/libwinpr/synch/critical.c @@ -31,6 +31,12 @@ #ifndef _WIN32 +/** + * TODO: EnterCriticalSection allows recursive calls from the same thread. + * Implement this using pthreads (see PTHREAD_MUTEX_RECURSIVE_NP) + * http://msdn.microsoft.com/en-us/library/windows/desktop/ms682608%28v=vs.85%29.aspx + */ + VOID InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection) { if (lpCriticalSection) @@ -44,60 +50,65 @@ VOID InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection) lpCriticalSection->OwningThread = NULL; lpCriticalSection->LockSemaphore = NULL; - lpCriticalSection->LockSemaphore = (winpr_sem_t*) malloc(sizeof(winpr_sem_t)); -#if defined __APPLE__ - semaphore_create(mach_task_self(), lpCriticalSection->LockSemaphore, SYNC_POLICY_FIFO, 1); -#else - sem_init(lpCriticalSection->LockSemaphore, 0, 1); -#endif + lpCriticalSection->LockSemaphore = malloc(sizeof(pthread_mutex_t)); + pthread_mutex_init(lpCriticalSection->LockSemaphore, NULL); } } BOOL InitializeCriticalSectionEx(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD Flags) { - return TRUE; + if (Flags != 0) { + fprintf(stderr, "warning: InitializeCriticalSectionEx Flags unimplemented\n"); + } + return InitializeCriticalSectionAndSpinCount(lpCriticalSection, dwSpinCount); } BOOL InitializeCriticalSectionAndSpinCount(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount) { + InitializeCriticalSection(lpCriticalSection); + SetCriticalSectionSpinCount(lpCriticalSection, dwSpinCount); return TRUE; } DWORD SetCriticalSectionSpinCount(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount) { - return 0; + DWORD dwPreviousSpinCount = lpCriticalSection->SpinCount; + lpCriticalSection->SpinCount = dwSpinCount; + return dwPreviousSpinCount; } VOID EnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection) { -#if defined __APPLE__ - semaphore_wait(*((winpr_sem_t*) lpCriticalSection->LockSemaphore)); -#else - sem_wait((winpr_sem_t*) lpCriticalSection->LockSemaphore); + /** + * Linux NPTL thread synchronization primitives are implemented using + * the futex system calls ... no need for performing a trylock loop. + */ +#if !defined(__linux__) + ULONG spin = lpCriticalSection->SpinCount; + while (spin--) + { + if (pthread_mutex_trylock((pthread_mutex_t*)lpCriticalSection->LockSemaphore) == 0) + return; + pthread_yield(); + } #endif + pthread_mutex_lock((pthread_mutex_t*)lpCriticalSection->LockSemaphore); } BOOL TryEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection) { - return TRUE; + return (pthread_mutex_trylock((pthread_mutex_t*)lpCriticalSection->LockSemaphore) == 0 ? TRUE : FALSE); } VOID LeaveCriticalSection(LPCRITICAL_SECTION lpCriticalSection) { -#if defined __APPLE__ - semaphore_signal(*((winpr_sem_t*) lpCriticalSection->LockSemaphore)); -#else - sem_post((winpr_sem_t*) lpCriticalSection->LockSemaphore); -#endif + pthread_mutex_unlock((pthread_mutex_t*)lpCriticalSection->LockSemaphore); } VOID DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection) { -#if defined __APPLE__ - semaphore_destroy(mach_task_self(), *((winpr_sem_t*) lpCriticalSection->LockSemaphore)); -#else - sem_destroy((winpr_sem_t*) lpCriticalSection->LockSemaphore); -#endif + pthread_mutex_destroy((pthread_mutex_t*)lpCriticalSection->LockSemaphore); + free(lpCriticalSection->LockSemaphore); } #endif diff --git a/winpr/libwinpr/utils/collections/ArrayList.c b/winpr/libwinpr/utils/collections/ArrayList.c index 157b365b6..40fec723d 100644 --- a/winpr/libwinpr/utils/collections/ArrayList.c +++ b/winpr/libwinpr/utils/collections/ArrayList.c @@ -83,18 +83,18 @@ BOOL ArrayList_IsSynchronized(wArrayList* arrayList) * Lock access to the ArrayList */ -BOOL ArrayList_Lock(wArrayList* arrayList) +void ArrayList_Lock(wArrayList* arrayList) { - return (WaitForSingleObject(arrayList->mutex, INFINITE) == WAIT_OBJECT_0) ? TRUE : FALSE; + EnterCriticalSection(&arrayList->lock); } /** * Unlock access to the ArrayList */ -BOOL ArrayList_Unlock(wArrayList* arrayList) +void ArrayList_Unlock(wArrayList* arrayList) { - return ReleaseMutex(arrayList->mutex); + LeaveCriticalSection(&arrayList->lock); } /** @@ -164,7 +164,7 @@ void ArrayList_Clear(wArrayList* arrayList) int index; if (arrayList->synchronized) - WaitForSingleObject(arrayList->mutex, INFINITE); + EnterCriticalSection(&arrayList->lock); for (index = 0; index < arrayList->size; index++) { @@ -177,7 +177,7 @@ void ArrayList_Clear(wArrayList* arrayList) arrayList->size = 0; if (arrayList->synchronized) - ReleaseMutex(arrayList->mutex); + LeaveCriticalSection(&arrayList->lock); } /** @@ -187,10 +187,10 @@ void ArrayList_Clear(wArrayList* arrayList) BOOL ArrayList_Contains(wArrayList* arrayList, void* obj) { if (arrayList->synchronized) - WaitForSingleObject(arrayList->mutex, INFINITE); + EnterCriticalSection(&arrayList->lock); if (arrayList->synchronized) - ReleaseMutex(arrayList->mutex); + LeaveCriticalSection(&arrayList->lock); return FALSE; } @@ -204,7 +204,7 @@ int ArrayList_Add(wArrayList* arrayList, void* obj) int index; if (arrayList->synchronized) - WaitForSingleObject(arrayList->mutex, INFINITE); + EnterCriticalSection(&arrayList->lock); if (arrayList->size + 1 > arrayList->capacity) { @@ -216,7 +216,7 @@ int ArrayList_Add(wArrayList* arrayList, void* obj) index = arrayList->size; if (arrayList->synchronized) - ReleaseMutex(arrayList->mutex); + LeaveCriticalSection(&arrayList->lock); return index; } @@ -228,7 +228,7 @@ int ArrayList_Add(wArrayList* arrayList, void* obj) void ArrayList_Insert(wArrayList* arrayList, int index, void* obj) { if (arrayList->synchronized) - WaitForSingleObject(arrayList->mutex, INFINITE); + EnterCriticalSection(&arrayList->lock); if ((index >= 0) && (index < arrayList->size)) { @@ -237,7 +237,7 @@ void ArrayList_Insert(wArrayList* arrayList, int index, void* obj) } if (arrayList->synchronized) - ReleaseMutex(arrayList->mutex); + LeaveCriticalSection(&arrayList->lock); } /** @@ -250,7 +250,7 @@ void ArrayList_Remove(wArrayList* arrayList, void* obj) BOOL found = FALSE; if (arrayList->synchronized) - WaitForSingleObject(arrayList->mutex, INFINITE); + EnterCriticalSection(&arrayList->lock); for (index = 0; index < arrayList->size; index++) { @@ -265,7 +265,7 @@ void ArrayList_Remove(wArrayList* arrayList, void* obj) ArrayList_Shift(arrayList, index, -1); if (arrayList->synchronized) - ReleaseMutex(arrayList->mutex); + LeaveCriticalSection(&arrayList->lock); } /** @@ -275,7 +275,7 @@ void ArrayList_Remove(wArrayList* arrayList, void* obj) void ArrayList_RemoveAt(wArrayList* arrayList, int index) { if (arrayList->synchronized) - WaitForSingleObject(arrayList->mutex, INFINITE); + EnterCriticalSection(&arrayList->lock); if ((index >= 0) && (index < arrayList->size)) { @@ -283,7 +283,7 @@ void ArrayList_RemoveAt(wArrayList* arrayList, int index) } if (arrayList->synchronized) - ReleaseMutex(arrayList->mutex); + LeaveCriticalSection(&arrayList->lock); } /** @@ -302,7 +302,7 @@ int ArrayList_IndexOf(wArrayList* arrayList, void* obj, int startIndex, int coun BOOL found = FALSE; if (arrayList->synchronized) - WaitForSingleObject(arrayList->mutex, INFINITE); + EnterCriticalSection(&arrayList->lock); if (startIndex < 0) startIndex = 0; @@ -323,7 +323,7 @@ int ArrayList_IndexOf(wArrayList* arrayList, void* obj, int startIndex, int coun index = -1; if (arrayList->synchronized) - ReleaseMutex(arrayList->mutex); + LeaveCriticalSection(&arrayList->lock); return index; } @@ -344,7 +344,7 @@ int ArrayList_LastIndexOf(wArrayList* arrayList, void* obj, int startIndex, int BOOL found = FALSE; if (arrayList->synchronized) - WaitForSingleObject(arrayList->mutex, INFINITE); + EnterCriticalSection(&arrayList->lock); if (startIndex < 0) startIndex = 0; @@ -365,7 +365,7 @@ int ArrayList_LastIndexOf(wArrayList* arrayList, void* obj, int startIndex, int index = -1; if (arrayList->synchronized) - ReleaseMutex(arrayList->mutex); + LeaveCriticalSection(&arrayList->lock); return index; } @@ -390,7 +390,7 @@ wArrayList* ArrayList_New(BOOL synchronized) arrayList->array = (void**) malloc(sizeof(void*) * arrayList->capacity); - arrayList->mutex = CreateMutex(NULL, FALSE, NULL); + InitializeCriticalSection(&arrayList->lock); ZeroMemory(&arrayList->object, sizeof(wObject)); } @@ -402,7 +402,7 @@ void ArrayList_Free(wArrayList* arrayList) { ArrayList_Clear(arrayList); - CloseHandle(arrayList->mutex); + DeleteCriticalSection(&arrayList->lock); free(arrayList->array); free(arrayList); } diff --git a/winpr/libwinpr/utils/collections/BufferPool.c b/winpr/libwinpr/utils/collections/BufferPool.c index d10ba1360..3a8c317e9 100644 --- a/winpr/libwinpr/utils/collections/BufferPool.c +++ b/winpr/libwinpr/utils/collections/BufferPool.c @@ -43,7 +43,7 @@ void* BufferPool_Take(wBufferPool* pool, int bufferSize) void* buffer = NULL; if (pool->synchronized) - WaitForSingleObject(pool->mutex, INFINITE); + EnterCriticalSection(&pool->lock); if (pool->fixedSize) { @@ -64,7 +64,7 @@ void* BufferPool_Take(wBufferPool* pool, int bufferSize) } if (pool->synchronized) - ReleaseMutex(pool->mutex); + LeaveCriticalSection(&pool->lock); return buffer; } @@ -76,7 +76,7 @@ void* BufferPool_Take(wBufferPool* pool, int bufferSize) void BufferPool_Return(wBufferPool* pool, void* buffer) { if (pool->synchronized) - WaitForSingleObject(pool->mutex, INFINITE); + EnterCriticalSection(&pool->lock); if ((pool->size + 1) >= pool->capacity) { @@ -87,7 +87,7 @@ void BufferPool_Return(wBufferPool* pool, void* buffer) pool->array[(pool->size)++] = buffer; if (pool->synchronized) - ReleaseMutex(pool->mutex); + LeaveCriticalSection(&pool->lock); } /** @@ -97,7 +97,7 @@ void BufferPool_Return(wBufferPool* pool, void* buffer) void BufferPool_Clear(wBufferPool* pool) { if (pool->synchronized) - WaitForSingleObject(pool->mutex, INFINITE); + EnterCriticalSection(&pool->lock); while (pool->size > 0) { @@ -110,7 +110,7 @@ void BufferPool_Clear(wBufferPool* pool) } if (pool->synchronized) - ReleaseMutex(pool->mutex); + LeaveCriticalSection(&pool->lock); } /** @@ -134,7 +134,7 @@ wBufferPool* BufferPool_New(BOOL synchronized, int fixedSize, DWORD alignment) pool->synchronized = synchronized; if (pool->synchronized) - pool->mutex = CreateMutex(NULL, FALSE, NULL); + InitializeCriticalSection(&pool->lock); if (!pool->fixedSize) { @@ -156,7 +156,7 @@ void BufferPool_Free(wBufferPool* pool) BufferPool_Clear(pool); if (pool->synchronized) - CloseHandle(pool->mutex); + DeleteCriticalSection(&pool->lock); free(pool->array); diff --git a/winpr/libwinpr/utils/collections/CountdownEvent.c b/winpr/libwinpr/utils/collections/CountdownEvent.c index 787c7e31b..0f11bb2ec 100644 --- a/winpr/libwinpr/utils/collections/CountdownEvent.c +++ b/winpr/libwinpr/utils/collections/CountdownEvent.c @@ -89,14 +89,14 @@ HANDLE CountdownEvent_WaitHandle(wCountdownEvent* countdown) void CountdownEvent_AddCount(wCountdownEvent* countdown, DWORD signalCount) { - WaitForSingleObject(countdown->mutex, INFINITE); + EnterCriticalSection(&countdown->lock); countdown->count += signalCount; if (countdown->count > 0) ResetEvent(countdown->event); - ReleaseMutex(countdown->mutex); + LeaveCriticalSection(&countdown->lock); } /** @@ -111,7 +111,7 @@ BOOL CountdownEvent_Signal(wCountdownEvent* countdown, DWORD signalCount) status = newStatus = oldStatus = FALSE; - WaitForSingleObject(countdown->mutex, INFINITE); + EnterCriticalSection(&countdown->lock); if (WaitForSingleObject(countdown->event, 0) == WAIT_OBJECT_0) oldStatus = TRUE; @@ -130,7 +130,7 @@ BOOL CountdownEvent_Signal(wCountdownEvent* countdown, DWORD signalCount) status = TRUE; } - ReleaseMutex(countdown->mutex); + LeaveCriticalSection(&countdown->lock); return status; } @@ -158,7 +158,7 @@ wCountdownEvent* CountdownEvent_New(DWORD initialCount) { countdown->count = initialCount; countdown->initialCount = initialCount; - countdown->mutex = CreateMutex(NULL, FALSE, NULL); + InitializeCriticalSection(&countdown->lock); countdown->event = CreateEvent(NULL, TRUE, FALSE, NULL); if (countdown->count == 0) @@ -170,7 +170,7 @@ wCountdownEvent* CountdownEvent_New(DWORD initialCount) void CountdownEvent_Free(wCountdownEvent* countdown) { - CloseHandle(countdown->mutex); + DeleteCriticalSection(&countdown->lock); CloseHandle(countdown->event); free(countdown); diff --git a/winpr/libwinpr/utils/collections/MessageQueue.c b/winpr/libwinpr/utils/collections/MessageQueue.c index d13916922..871316ab0 100644 --- a/winpr/libwinpr/utils/collections/MessageQueue.c +++ b/winpr/libwinpr/utils/collections/MessageQueue.c @@ -69,7 +69,7 @@ BOOL MessageQueue_Wait(wMessageQueue* queue) void MessageQueue_Dispatch(wMessageQueue* queue, wMessage* message) { - WaitForSingleObject(queue->mutex, INFINITE); + EnterCriticalSection(&queue->lock); if (queue->size == queue->capacity) { @@ -100,7 +100,7 @@ void MessageQueue_Dispatch(wMessageQueue* queue, wMessage* message) if (queue->size > 0) SetEvent(queue->event); - ReleaseMutex(queue->mutex); + LeaveCriticalSection(&queue->lock); } void MessageQueue_Post(wMessageQueue* queue, void* context, UINT32 type, void* wParam, void* lParam) @@ -127,7 +127,7 @@ int MessageQueue_Get(wMessageQueue* queue, wMessage* message) if (!MessageQueue_Wait(queue)) return status; - WaitForSingleObject(queue->mutex, INFINITE); + EnterCriticalSection(&queue->lock); if (queue->size > 0) { @@ -142,7 +142,7 @@ int MessageQueue_Get(wMessageQueue* queue, wMessage* message) status = (message->id != WMQ_QUIT) ? 1 : 0; } - ReleaseMutex(queue->mutex); + LeaveCriticalSection(&queue->lock); return status; } @@ -151,7 +151,7 @@ int MessageQueue_Peek(wMessageQueue* queue, wMessage* message, BOOL remove) { int status = 0; - WaitForSingleObject(queue->mutex, INFINITE); + EnterCriticalSection(&queue->lock); if (queue->size > 0) { @@ -169,7 +169,7 @@ int MessageQueue_Peek(wMessageQueue* queue, wMessage* message, BOOL remove) } } - ReleaseMutex(queue->mutex); + LeaveCriticalSection(&queue->lock); return status; } @@ -194,7 +194,7 @@ wMessageQueue* MessageQueue_New() queue->array = (wMessage*) malloc(sizeof(wMessage) * queue->capacity); ZeroMemory(queue->array, sizeof(wMessage) * queue->capacity); - queue->mutex = CreateMutex(NULL, FALSE, NULL); + InitializeCriticalSection(&queue->lock); queue->event = CreateEvent(NULL, TRUE, FALSE, NULL); } @@ -204,7 +204,7 @@ wMessageQueue* MessageQueue_New() void MessageQueue_Free(wMessageQueue* queue) { CloseHandle(queue->event); - CloseHandle(queue->mutex); + DeleteCriticalSection(&queue->lock); free(queue->array); free(queue); diff --git a/winpr/libwinpr/utils/collections/ObjectPool.c b/winpr/libwinpr/utils/collections/ObjectPool.c index 472eba1d2..488559085 100644 --- a/winpr/libwinpr/utils/collections/ObjectPool.c +++ b/winpr/libwinpr/utils/collections/ObjectPool.c @@ -43,7 +43,7 @@ void* ObjectPool_Take(wObjectPool* pool) void* obj = NULL; if (pool->synchronized) - WaitForSingleObject(pool->mutex, INFINITE); + EnterCriticalSection(&pool->lock); if (pool->size > 0) obj = pool->array[--(pool->size)]; @@ -55,7 +55,7 @@ void* ObjectPool_Take(wObjectPool* pool) } if (pool->synchronized) - ReleaseMutex(pool->mutex); + LeaveCriticalSection(&pool->lock); return obj; } @@ -67,7 +67,7 @@ void* ObjectPool_Take(wObjectPool* pool) void ObjectPool_Return(wObjectPool* pool, void* obj) { if (pool->synchronized) - WaitForSingleObject(pool->mutex, INFINITE); + EnterCriticalSection(&pool->lock); if ((pool->size + 1) >= pool->capacity) { @@ -78,7 +78,7 @@ void ObjectPool_Return(wObjectPool* pool, void* obj) pool->array[(pool->size)++] = obj; if (pool->synchronized) - ReleaseMutex(pool->mutex); + LeaveCriticalSection(&pool->lock); } /** @@ -88,7 +88,7 @@ void ObjectPool_Return(wObjectPool* pool, void* obj) void ObjectPool_Clear(wObjectPool* pool) { if (pool->synchronized) - WaitForSingleObject(pool->mutex, INFINITE); + EnterCriticalSection(&pool->lock); while (pool->size > 0) { @@ -99,7 +99,7 @@ void ObjectPool_Clear(wObjectPool* pool) } if (pool->synchronized) - ReleaseMutex(pool->mutex); + LeaveCriticalSection(&pool->lock); } /** @@ -119,7 +119,7 @@ wObjectPool* ObjectPool_New(BOOL synchronized) pool->synchronized = synchronized; if (pool->synchronized) - pool->mutex = CreateMutex(NULL, FALSE, NULL); + InitializeCriticalSection(&pool->lock); pool->size = 0; pool->capacity = 32; @@ -136,7 +136,7 @@ void ObjectPool_Free(wObjectPool* pool) ObjectPool_Clear(pool); if (pool->synchronized) - CloseHandle(pool->mutex); + DeleteCriticalSection(&pool->lock); free(pool->array); diff --git a/winpr/libwinpr/utils/collections/PubSub.c b/winpr/libwinpr/utils/collections/PubSub.c index 1236d6858..26c89968a 100644 --- a/winpr/libwinpr/utils/collections/PubSub.c +++ b/winpr/libwinpr/utils/collections/PubSub.c @@ -46,14 +46,14 @@ wEventType* PubSub_GetEventTypes(wPubSub* pubSub, int* count) * Methods */ -BOOL PubSub_Lock(wPubSub* pubSub) +void PubSub_Lock(wPubSub* pubSub) { - return (WaitForSingleObject(pubSub->mutex, INFINITE) == WAIT_OBJECT_0) ? TRUE : FALSE; + EnterCriticalSection(&pubSub->lock); } -BOOL PubSub_Unlock(wPubSub* pubSub) +void PubSub_Unlock(wPubSub* pubSub) { - return ReleaseMutex(pubSub->mutex); + LeaveCriticalSection(&pubSub->lock); } wEventType* PubSub_FindEventType(wPubSub* pubSub, const char* EventName) @@ -202,7 +202,7 @@ wPubSub* PubSub_New(BOOL synchronized) pubSub->synchronized = synchronized; if (pubSub->synchronized) - pubSub->mutex = CreateMutex(NULL, FALSE, NULL); + InitializeCriticalSection(&pubSub->lock); pubSub->count = 0; pubSub->size = 64; @@ -219,7 +219,7 @@ void PubSub_Free(wPubSub* pubSub) if (pubSub) { if (pubSub->synchronized) - CloseHandle(pubSub->mutex); + DeleteCriticalSection(&pubSub->lock); if (pubSub->events) free(pubSub->events); diff --git a/winpr/libwinpr/utils/collections/Queue.c b/winpr/libwinpr/utils/collections/Queue.c index fa33df76a..95210649d 100644 --- a/winpr/libwinpr/utils/collections/Queue.c +++ b/winpr/libwinpr/utils/collections/Queue.c @@ -47,18 +47,18 @@ int Queue_Count(wQueue* queue) * Lock access to the ArrayList */ -BOOL Queue_Lock(wQueue* queue) +void Queue_Lock(wQueue* queue) { - return (WaitForSingleObject(queue->mutex, INFINITE) == WAIT_OBJECT_0) ? TRUE : FALSE; + EnterCriticalSection(&queue->lock); } /** * Unlock access to the ArrayList */ -BOOL Queue_Unlock(wQueue* queue) +void Queue_Unlock(wQueue* queue) { - return ReleaseMutex(queue->mutex); + LeaveCriticalSection(&queue->lock); } /** @@ -83,7 +83,7 @@ void Queue_Clear(wQueue* queue) int index; if (queue->synchronized) - WaitForSingleObject(queue->mutex, INFINITE); + EnterCriticalSection(&queue->lock); for (index = queue->head; index != queue->tail; index = (index + 1) % queue->capacity) { @@ -97,7 +97,7 @@ void Queue_Clear(wQueue* queue) queue->head = queue->tail = 0; if (queue->synchronized) - ReleaseMutex(queue->mutex); + LeaveCriticalSection(&queue->lock); } /** @@ -110,7 +110,7 @@ BOOL Queue_Contains(wQueue* queue, void* obj) BOOL found = FALSE; if (queue->synchronized) - WaitForSingleObject(queue->mutex, INFINITE); + EnterCriticalSection(&queue->lock); for (index = 0; index < queue->tail; index++) { @@ -122,7 +122,7 @@ BOOL Queue_Contains(wQueue* queue, void* obj) } if (queue->synchronized) - ReleaseMutex(queue->mutex); + LeaveCriticalSection(&queue->lock); return found; } @@ -134,7 +134,7 @@ BOOL Queue_Contains(wQueue* queue, void* obj) void Queue_Enqueue(wQueue* queue, void* obj) { if (queue->synchronized) - WaitForSingleObject(queue->mutex, INFINITE); + EnterCriticalSection(&queue->lock); if (queue->size == queue->capacity) { @@ -162,7 +162,7 @@ void Queue_Enqueue(wQueue* queue, void* obj) SetEvent(queue->event); if (queue->synchronized) - ReleaseMutex(queue->mutex); + LeaveCriticalSection(&queue->lock); } /** @@ -174,7 +174,7 @@ void* Queue_Dequeue(wQueue* queue) void* obj = NULL; if (queue->synchronized) - WaitForSingleObject(queue->mutex, INFINITE); + EnterCriticalSection(&queue->lock); if (queue->size > 0) { @@ -188,7 +188,7 @@ void* Queue_Dequeue(wQueue* queue) ResetEvent(queue->event); if (queue->synchronized) - ReleaseMutex(queue->mutex); + LeaveCriticalSection(&queue->lock); return obj; } @@ -202,13 +202,13 @@ void* Queue_Peek(wQueue* queue) void* obj = NULL; if (queue->synchronized) - WaitForSingleObject(queue->mutex, INFINITE); + EnterCriticalSection(&queue->lock); if (queue->size > 0) obj = queue->array[queue->head]; if (queue->synchronized) - ReleaseMutex(queue->mutex); + LeaveCriticalSection(&queue->lock); return obj; } @@ -243,7 +243,7 @@ wQueue* Queue_New(BOOL synchronized, int capacity, int growthFactor) queue->array = (void**) malloc(sizeof(void*) * queue->capacity); ZeroMemory(queue->array, sizeof(void*) * queue->capacity); - queue->mutex = CreateMutex(NULL, FALSE, NULL); + InitializeCriticalSection(&queue->lock); queue->event = CreateEvent(NULL, TRUE, FALSE, NULL); ZeroMemory(&queue->object, sizeof(wObject)); @@ -257,7 +257,7 @@ void Queue_Free(wQueue* queue) Queue_Clear(queue); CloseHandle(queue->event); - CloseHandle(queue->mutex); + DeleteCriticalSection(&queue->lock); free(queue->array); free(queue); } diff --git a/winpr/libwinpr/utils/collections/Reference.c b/winpr/libwinpr/utils/collections/Reference.c index 7df1c84b2..6c32ffeac 100644 --- a/winpr/libwinpr/utils/collections/Reference.c +++ b/winpr/libwinpr/utils/collections/Reference.c @@ -88,7 +88,7 @@ UINT32 ReferenceTable_Add(wReferenceTable* referenceTable, void* ptr) wReference* reference = NULL; if (referenceTable->synchronized) - WaitForSingleObject(referenceTable->mutex, INFINITE); + EnterCriticalSection(&referenceTable->lock); reference = ReferenceTable_FindEntry(referenceTable, ptr); @@ -102,7 +102,7 @@ UINT32 ReferenceTable_Add(wReferenceTable* referenceTable, void* ptr) count = ++(reference->Count); if (referenceTable->synchronized) - ReleaseMutex(referenceTable->mutex); + LeaveCriticalSection(&referenceTable->lock); return count; } @@ -113,7 +113,7 @@ UINT32 ReferenceTable_Release(wReferenceTable* referenceTable, void* ptr) wReference* reference = NULL; if (referenceTable->synchronized) - WaitForSingleObject(referenceTable->mutex, INFINITE); + EnterCriticalSection(&referenceTable->lock); reference = ReferenceTable_FindEntry(referenceTable, ptr); @@ -133,7 +133,7 @@ UINT32 ReferenceTable_Release(wReferenceTable* referenceTable, void* ptr) } if (referenceTable->synchronized) - ReleaseMutex(referenceTable->mutex); + LeaveCriticalSection(&referenceTable->lock); return count; } @@ -154,7 +154,7 @@ wReferenceTable* ReferenceTable_New(BOOL synchronized, void* context, REFERENCE_ ZeroMemory(referenceTable->array, sizeof(wReference) * referenceTable->size); referenceTable->synchronized = synchronized; - referenceTable->mutex = CreateMutex(NULL, FALSE, NULL); + InitializeCriticalSection(&referenceTable->lock); } return referenceTable; @@ -164,7 +164,7 @@ void ReferenceTable_Free(wReferenceTable* referenceTable) { if (referenceTable) { - CloseHandle(referenceTable->mutex); + DeleteCriticalSection(&referenceTable->lock); free(referenceTable->array); free(referenceTable); } diff --git a/winpr/libwinpr/utils/collections/Stack.c b/winpr/libwinpr/utils/collections/Stack.c index 383fe0de1..a0d063eee 100644 --- a/winpr/libwinpr/utils/collections/Stack.c +++ b/winpr/libwinpr/utils/collections/Stack.c @@ -84,7 +84,7 @@ BOOL Stack_Contains(wStack* stack, void* obj) void Stack_Push(wStack* stack, void* obj) { if (stack->synchronized) - WaitForSingleObject(stack->mutex, INFINITE); + EnterCriticalSection(&stack->lock); if ((stack->size + 1) >= stack->capacity) { @@ -95,7 +95,7 @@ void Stack_Push(wStack* stack, void* obj) stack->array[(stack->size)++] = obj; if (stack->synchronized) - ReleaseMutex(stack->mutex); + LeaveCriticalSection(&stack->lock); } /** @@ -107,13 +107,13 @@ void* Stack_Pop(wStack* stack) void* obj = NULL; if (stack->synchronized) - WaitForSingleObject(stack->mutex, INFINITE); + EnterCriticalSection(&stack->lock); if (stack->size > 0) obj = stack->array[--(stack->size)]; if (stack->synchronized) - ReleaseMutex(stack->mutex); + LeaveCriticalSection(&stack->lock); return obj; } @@ -127,13 +127,13 @@ void* Stack_Peek(wStack* stack) void* obj = NULL; if (stack->synchronized) - WaitForSingleObject(stack->mutex, INFINITE); + EnterCriticalSection(&stack->lock); if (stack->size > 0) obj = stack->array[stack->size]; if (stack->synchronized) - ReleaseMutex(stack->mutex); + LeaveCriticalSection(&stack->lock); return obj; } @@ -153,7 +153,7 @@ wStack* Stack_New(BOOL synchronized) stack->synchronized = synchronized; if (stack->synchronized) - stack->mutex = CreateMutex(NULL, FALSE, NULL); + InitializeCriticalSection(&stack->lock); stack->size = 0; stack->capacity = 32; @@ -168,7 +168,7 @@ void Stack_Free(wStack* stack) if (stack) { if (stack->synchronized) - CloseHandle(stack->mutex); + DeleteCriticalSection(&stack->lock); free(stack->array); diff --git a/winpr/libwinpr/utils/collections/StreamPool.c b/winpr/libwinpr/utils/collections/StreamPool.c index 1605c5332..418681c61 100644 --- a/winpr/libwinpr/utils/collections/StreamPool.c +++ b/winpr/libwinpr/utils/collections/StreamPool.c @@ -118,7 +118,7 @@ wStream* StreamPool_Take(wStreamPool* pool, size_t size) BOOL found = FALSE; if (pool->synchronized) - WaitForSingleObject(pool->mutex, INFINITE); + EnterCriticalSection(&pool->lock); if (size == 0) size = pool->defaultSize; @@ -153,7 +153,7 @@ wStream* StreamPool_Take(wStreamPool* pool, size_t size) StreamPool_AddUsed(pool, s); if (pool->synchronized) - ReleaseMutex(pool->mutex); + LeaveCriticalSection(&pool->lock); return s; } @@ -165,7 +165,7 @@ wStream* StreamPool_Take(wStreamPool* pool, size_t size) void StreamPool_Return(wStreamPool* pool, wStream* s) { if (pool->synchronized) - WaitForSingleObject(pool->mutex, INFINITE); + EnterCriticalSection(&pool->lock); if ((pool->aSize + 1) >= pool->aCapacity) { @@ -177,7 +177,7 @@ void StreamPool_Return(wStreamPool* pool, wStream* s) StreamPool_RemoveUsed(pool, s); if (pool->synchronized) - ReleaseMutex(pool->mutex); + LeaveCriticalSection(&pool->lock); } /** @@ -186,7 +186,7 @@ void StreamPool_Return(wStreamPool* pool, wStream* s) void StreamPool_Lock(wStreamPool* pool) { - WaitForSingleObject(pool->mutex, INFINITE); + EnterCriticalSection(&pool->lock); } /** @@ -195,7 +195,7 @@ void StreamPool_Lock(wStreamPool* pool) void StreamPool_Unlock(wStreamPool* pool) { - ReleaseMutex(pool->mutex); + LeaveCriticalSection(&pool->lock); } /** @@ -241,7 +241,7 @@ wStream* StreamPool_Find(wStreamPool* pool, BYTE* ptr) wStream* s = NULL; BOOL found = FALSE; - WaitForSingleObject(pool->mutex, INFINITE); + EnterCriticalSection(&pool->lock); for (index = 0; index < pool->uSize; index++) { @@ -254,7 +254,7 @@ wStream* StreamPool_Find(wStreamPool* pool, BYTE* ptr) } } - ReleaseMutex(pool->mutex); + LeaveCriticalSection(&pool->lock); return (found) ? s : NULL; } @@ -294,7 +294,7 @@ void StreamPool_Release(wStreamPool* pool, BYTE* ptr) void StreamPool_Clear(wStreamPool* pool) { if (pool->synchronized) - WaitForSingleObject(pool->mutex, INFINITE); + EnterCriticalSection(&pool->lock); while (pool->aSize > 0) { @@ -303,7 +303,7 @@ void StreamPool_Clear(wStreamPool* pool) } if (pool->synchronized) - ReleaseMutex(pool->mutex); + LeaveCriticalSection(&pool->lock); } /** @@ -323,8 +323,7 @@ wStreamPool* StreamPool_New(BOOL synchronized, size_t defaultSize) pool->synchronized = synchronized; pool->defaultSize = defaultSize; - if (pool->synchronized) - pool->mutex = CreateMutex(NULL, FALSE, NULL); + InitializeCriticalSection(&pool->lock); pool->aSize = 0; pool->aCapacity = 32; @@ -344,8 +343,7 @@ void StreamPool_Free(wStreamPool* pool) { StreamPool_Clear(pool); - if (pool->synchronized) - CloseHandle(pool->mutex); + DeleteCriticalSection(&pool->lock); free(pool->aArray); free(pool->uArray);