libwinpr-synch: initial commit
This commit is contained in:
parent
ae6f331570
commit
b846f72de3
45
include/winpr/handle.h
Normal file
45
include/winpr/handle.h
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Handle Management
|
||||
*
|
||||
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WINPR_HANDLE_H
|
||||
#define WINPR_HANDLE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <winpr/winpr.h>
|
||||
#include <winpr/wtypes.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#define HANDLE_FLAG_INHERIT 0x00000001
|
||||
#define HANDLE_FLAG_PROTECT_FROM_CLOSE 0x00000002
|
||||
|
||||
WINPR_API BOOL CloseHandle(HANDLE hObject);
|
||||
|
||||
WINPR_API BOOL DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle,
|
||||
LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions);
|
||||
|
||||
WINPR_API BOOL GetHandleInformation(HANDLE hObject, LPDWORD lpdwFlags);
|
||||
WINPR_API BOOL SetHandleInformation(HANDLE hObject, DWORD dwMask, DWORD dwFlags);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* WINPR_HANDLE_H */
|
||||
|
44
include/winpr/heap.h
Normal file
44
include/winpr/heap.h
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Heap Memory Allocation
|
||||
*
|
||||
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WINPR_HEAP_H
|
||||
#define WINPR_HEAP_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <winpr/winpr.h>
|
||||
#include <winpr/wtypes.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#define HEAP_GENERATE_EXCEPTIONS 0x00000004
|
||||
#define HEAP_NO_SERIALIZE 0x00000001
|
||||
#define HEAP_ZERO_MEMORY 0x00000008
|
||||
#define HEAP_REALLOC_IN_PLACE_ONLY 0x00000010
|
||||
|
||||
WINPR_API HANDLE GetProcessHeap(void);
|
||||
WINPR_API LPVOID HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes);
|
||||
WINPR_API LPVOID HeapReAlloc(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes);
|
||||
WINPR_API BOOL HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* WINPR_HEAP_H */
|
||||
|
@ -38,16 +38,9 @@
|
||||
#define RtlFillMemory(Destination, Length, Fill) memset((Destination), (Fill), (Length))
|
||||
#define RtlZeroMemory(Destination, Length) memset((Destination), 0, (Length))
|
||||
|
||||
#define HEAP_GENERATE_EXCEPTIONS 0x00000004
|
||||
#define HEAP_NO_SERIALIZE 0x00000001
|
||||
#define HEAP_ZERO_MEMORY 0x00000008
|
||||
#define HEAP_REALLOC_IN_PLACE_ONLY 0x00000010
|
||||
|
||||
WINPR_API HANDLE GetProcessHeap(void);
|
||||
WINPR_API LPVOID HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes);
|
||||
WINPR_API LPVOID HeapReAlloc(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes);
|
||||
WINPR_API BOOL HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem);
|
||||
|
||||
#endif
|
||||
|
||||
#include <winpr/heap.h>
|
||||
|
||||
#endif /* WINPR_CRT_MEMORY_H */
|
||||
|
||||
|
@ -148,13 +148,6 @@ typedef ACCESS_MASK REGSAM;
|
||||
#define RRF_NOEXPAND 0x10000000
|
||||
#define RRF_ZEROONFAILURE 0x20000000
|
||||
|
||||
typedef struct _SECURITY_ATTRIBUTES
|
||||
{
|
||||
DWORD nLength;
|
||||
LPVOID lpSecurityDescriptor;
|
||||
BOOL bInheritHandle;
|
||||
} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
|
||||
|
||||
struct val_context
|
||||
{
|
||||
int valuelen;
|
||||
|
64
include/winpr/synch.h
Normal file
64
include/winpr/synch.h
Normal file
@ -0,0 +1,64 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Synchronization Functions
|
||||
*
|
||||
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WINPR_SYNCH_H
|
||||
#define WINPR_SYNCH_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <winpr/winpr.h>
|
||||
#include <winpr/wtypes.h>
|
||||
|
||||
#include <winpr/handle.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
WINPR_API HANDLE CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCSTR lpName);
|
||||
WINPR_API HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCWSTR lpName);
|
||||
|
||||
#ifdef UNICODE
|
||||
#define CreateSemaphore CreateSemaphoreW
|
||||
#else
|
||||
#define CreateSemaphore CreateSemaphoreA
|
||||
#endif
|
||||
|
||||
WINPR_API HANDLE OpenSemaphoreA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName);
|
||||
WINPR_API HANDLE OpenSemaphoreW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName);
|
||||
|
||||
#ifdef UNICODE
|
||||
#define OpenSemaphore OpenSemaphoreW
|
||||
#else
|
||||
#define OpenSemaphore OpenSemaphoreA
|
||||
#endif
|
||||
|
||||
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)
|
||||
|
||||
WINPR_API DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds);
|
||||
WINPR_API DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAll, DWORD dwMilliseconds);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* WINPR_SYNCH_H */
|
||||
|
@ -54,7 +54,7 @@ typedef float FLOAT;
|
||||
typedef unsigned char UCHAR, *PUCHAR;
|
||||
typedef short SHORT;
|
||||
|
||||
typedef void* HANDLE;
|
||||
typedef void* HANDLE, *LPHANDLE;
|
||||
typedef DWORD HCALL;
|
||||
typedef int INT, *LPINT;
|
||||
typedef signed char INT8;
|
||||
@ -176,6 +176,13 @@ typedef struct _SECURITY_DESCRIPTOR
|
||||
PACL Dacl;
|
||||
} SECURITY_DESCRIPTOR, *PSECURITY_DESCRIPTOR;
|
||||
|
||||
typedef struct _SECURITY_ATTRIBUTES
|
||||
{
|
||||
DWORD nLength;
|
||||
LPVOID lpSecurityDescriptor;
|
||||
BOOL bInheritHandle;
|
||||
} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
|
||||
|
||||
#endif
|
||||
|
||||
typedef BYTE byte;
|
||||
|
@ -19,6 +19,9 @@
|
||||
|
||||
add_subdirectory(crt)
|
||||
add_subdirectory(utils)
|
||||
add_subdirectory(heap)
|
||||
add_subdirectory(handle)
|
||||
add_subdirectory(synch)
|
||||
add_subdirectory(bcrypt)
|
||||
add_subdirectory(rpc)
|
||||
add_subdirectory(sspi)
|
||||
|
@ -24,36 +24,6 @@
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
HANDLE GetProcessHeap(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LPVOID HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes)
|
||||
{
|
||||
LPVOID lpMem = NULL;
|
||||
|
||||
if (dwFlags & HEAP_ZERO_MEMORY)
|
||||
lpMem = calloc(1, dwBytes);
|
||||
else
|
||||
lpMem = malloc(dwBytes);
|
||||
|
||||
return lpMem;
|
||||
}
|
||||
|
||||
LPVOID HeapReAlloc(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes)
|
||||
{
|
||||
LPVOID lpNewMem;
|
||||
|
||||
lpNewMem = realloc(lpMem, dwBytes);
|
||||
|
||||
return lpNewMem;
|
||||
}
|
||||
|
||||
BOOL HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem)
|
||||
{
|
||||
free(lpMem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
28
winpr/handle/CMakeLists.txt
Normal file
28
winpr/handle/CMakeLists.txt
Normal file
@ -0,0 +1,28 @@
|
||||
# WinPR: Windows Portable Runtime
|
||||
# libwinpr-handle cmake build script
|
||||
#
|
||||
# Copyright 2011 O.S. Systems Software Ltda.
|
||||
# Copyright 2011 Otavio Salvador <otavio@ossystems.com.br>
|
||||
# Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set(WINPR_HANDLE_SRCS
|
||||
handle.c)
|
||||
|
||||
add_library(winpr-handle ${WINPR_HANDLE_SRCS})
|
||||
|
||||
set_target_properties(winpr-handle PROPERTIES VERSION ${FREERDP_VERSION_FULL} SOVERSION ${FREERDP_VERSION} PREFIX "lib")
|
||||
|
||||
install(TARGETS winpr-handle DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
66
winpr/handle/handle.c
Normal file
66
winpr/handle/handle.c
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Handle Management
|
||||
*
|
||||
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <winpr/handle.h>
|
||||
|
||||
#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_td
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#define winpr_sem_t sem_t
|
||||
#endif
|
||||
|
||||
BOOL CloseHandle(HANDLE hObject)
|
||||
{
|
||||
#if defined __APPLE__
|
||||
semaphore_destroy(mach_task_self(), *((winpr_sem_t*) hObject));
|
||||
#else
|
||||
sem_destroy((winpr_sem_t*) hObject);
|
||||
#endif
|
||||
|
||||
free(hObject);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle,
|
||||
LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL GetHandleInformation(HANDLE hObject, LPDWORD lpdwFlags)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL SetHandleInformation(HANDLE hObject, DWORD dwMask, DWORD dwFlags)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
28
winpr/heap/CMakeLists.txt
Normal file
28
winpr/heap/CMakeLists.txt
Normal file
@ -0,0 +1,28 @@
|
||||
# WinPR: Windows Portable Runtime
|
||||
# libwinpr-heap cmake build script
|
||||
#
|
||||
# Copyright 2011 O.S. Systems Software Ltda.
|
||||
# Copyright 2011 Otavio Salvador <otavio@ossystems.com.br>
|
||||
# Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set(WINPR_HEAP_SRCS
|
||||
heap.c)
|
||||
|
||||
add_library(winpr-heap ${WINPR_HEAP_SRCS})
|
||||
|
||||
set_target_properties(winpr-heap PROPERTIES VERSION ${FREERDP_VERSION_FULL} SOVERSION ${FREERDP_VERSION} PREFIX "lib")
|
||||
|
||||
install(TARGETS winpr-heap DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
59
winpr/heap/heap.c
Normal file
59
winpr/heap/heap.c
Normal file
@ -0,0 +1,59 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Memory Allocation
|
||||
*
|
||||
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <winpr/crt.h>
|
||||
|
||||
/* Memory Allocation: http://msdn.microsoft.com/en-us/library/hk1k7x6x.aspx */
|
||||
/* Memory Management Functions: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366781/ */
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
HANDLE GetProcessHeap(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LPVOID HeapAlloc(HANDLE hHeap, DWORD dwFlags, SIZE_T dwBytes)
|
||||
{
|
||||
LPVOID lpMem = NULL;
|
||||
|
||||
if (dwFlags & HEAP_ZERO_MEMORY)
|
||||
lpMem = calloc(1, dwBytes);
|
||||
else
|
||||
lpMem = malloc(dwBytes);
|
||||
|
||||
return lpMem;
|
||||
}
|
||||
|
||||
LPVOID HeapReAlloc(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem, SIZE_T dwBytes)
|
||||
{
|
||||
LPVOID lpNewMem;
|
||||
|
||||
lpNewMem = realloc(lpMem, dwBytes);
|
||||
|
||||
return lpNewMem;
|
||||
}
|
||||
|
||||
BOOL HeapFree(HANDLE hHeap, DWORD dwFlags, LPVOID lpMem)
|
||||
{
|
||||
free(lpMem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
@ -122,8 +122,8 @@ void sspi_ContextBufferAllocTableGrow()
|
||||
|
||||
size = sizeof(CONTEXT_BUFFER_ALLOC_ENTRY) * ContextBufferAllocTable.cMaxEntries;
|
||||
|
||||
ContextBufferAllocTable.entries = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ContextBufferAllocTable.entries, size);
|
||||
memset((void*) &ContextBufferAllocTable.entries[ContextBufferAllocTable.cMaxEntries / 2], 0, size / 2);
|
||||
ContextBufferAllocTable.entries = realloc(ContextBufferAllocTable.entries, size);
|
||||
ZeroMemory((void*) &ContextBufferAllocTable.entries[ContextBufferAllocTable.cMaxEntries / 2], size / 2);
|
||||
}
|
||||
|
||||
void sspi_ContextBufferAllocTableFree()
|
||||
|
34
winpr/synch/CMakeLists.txt
Normal file
34
winpr/synch/CMakeLists.txt
Normal file
@ -0,0 +1,34 @@
|
||||
# WinPR: Windows Portable Runtime
|
||||
# libwinpr-synch cmake build script
|
||||
#
|
||||
# Copyright 2011 O.S. Systems Software Ltda.
|
||||
# Copyright 2011 Otavio Salvador <otavio@ossystems.com.br>
|
||||
# Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set(WINPR_SYNCH_SRCS
|
||||
critical.c
|
||||
event.c
|
||||
mutex.c
|
||||
semaphore.c
|
||||
sleep.c)
|
||||
|
||||
add_library(winpr-synch ${WINPR_SYNCH_SRCS})
|
||||
|
||||
set_target_properties(winpr-synch PROPERTIES VERSION ${FREERDP_VERSION_FULL} SOVERSION ${FREERDP_VERSION} PREFIX "lib")
|
||||
|
||||
target_link_libraries(winpr-synch winpr-handle)
|
||||
|
||||
install(TARGETS winpr-synch DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
23
winpr/synch/critical.c
Normal file
23
winpr/synch/critical.c
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Synchronization Functions
|
||||
*
|
||||
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
|
||||
|
23
winpr/synch/event.c
Normal file
23
winpr/synch/event.c
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Synchronization Functions
|
||||
*
|
||||
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
|
||||
|
23
winpr/synch/mutex.c
Normal file
23
winpr/synch/mutex.c
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Synchronization Functions
|
||||
*
|
||||
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
|
||||
|
104
winpr/synch/semaphore.c
Normal file
104
winpr/synch/semaphore.c
Normal file
@ -0,0 +1,104 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Synchronization Functions
|
||||
*
|
||||
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#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_td
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#define winpr_sem_t sem_t
|
||||
#endif
|
||||
|
||||
HANDLE CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCSTR lpName)
|
||||
{
|
||||
winpr_sem_t* hSemaphore;
|
||||
|
||||
hSemaphore = malloc(sizeof(winpr_sem_t));
|
||||
|
||||
#if defined __APPLE__
|
||||
semaphore_create(mach_task_self(), hSemaphore, SYNC_POLICY_FIFO, lMaximumCount);
|
||||
#else
|
||||
sem_init(hSemaphore, 0, lMaximumCount);
|
||||
#endif
|
||||
|
||||
return (HANDLE) hSemaphore;
|
||||
}
|
||||
|
||||
HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCWSTR lpName)
|
||||
{
|
||||
winpr_sem_t* hSemaphore;
|
||||
|
||||
hSemaphore = malloc(sizeof(winpr_sem_t));
|
||||
|
||||
#if defined __APPLE__
|
||||
semaphore_create(mach_task_self(), hSemaphore, SYNC_POLICY_FIFO, lMaximumCount);
|
||||
#else
|
||||
sem_init(hSemaphore, 0, lMaximumCount);
|
||||
#endif
|
||||
|
||||
return (HANDLE) hSemaphore;
|
||||
}
|
||||
|
||||
HANDLE OpenSemaphoreA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HANDLE OpenSemaphoreW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BOOL ReleaseSemaphore(HANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviousCount)
|
||||
{
|
||||
#if defined __APPLE__
|
||||
semaphore_signal(*((winpr_sem_t*) hSemaphore));
|
||||
#else
|
||||
sem_post((winpr_sem_t*) hSemaphore);
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
|
||||
{
|
||||
#if defined __APPLE__
|
||||
semaphore_wait(*((winpr_sem_t*) hHandle));
|
||||
#else
|
||||
sem_wait((winpr_sem_t*) hHandle);
|
||||
#endif
|
||||
|
||||
return WAIT_OBJECT_0;
|
||||
}
|
||||
|
||||
DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAll, DWORD dwMilliseconds)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
23
winpr/synch/sleep.c
Normal file
23
winpr/synch/sleep.c
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* Synchronization Functions
|
||||
*
|
||||
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <winpr/synch.h>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user