- Fix duplicate code on os_winphone.h
 - Change the use of PJ_WIN32_WINPHONE to follow the code convention
 - Fix incorrect link of the Thread library
 - Handle exception raised from select() API. However the break window will still be shown when debugging on Visual Studio. To disable it, from Debug>Exceptions>Win32 Exceptions> unmark the "An invalid handle was specified” exception.



git-svn-id: https://svn.pjsip.org/repos/pjproject/branches/projects/winphone@4777 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
Riza Sulistyo 2014-03-05 06:48:59 +00:00
parent d64a946406
commit 267357213f
8 changed files with 100 additions and 360 deletions

View File

@ -21,8 +21,8 @@
#define __PJ_COMPAT_OS_WIN32_WINPHONE_H__
/**
* @file os_win32.h
* @brief Describes Win32 operating system family specifics.
* @file os_winphone.h
* @brief Describes Windows Phone operating system family specifics.
*/
#define PJ_OS_NAME "winphone"
@ -145,303 +145,5 @@
#define PJ_THREAD_ALLOCATE_STACK 0
#endif /* __PJ_COMPAT_OS_WIN32_WINCE_H__ */
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PJ_COMPAT_OS_WINPHONE_H__
#define __PJ_COMPAT_OS_WIN32_WINPHONE_H__
/**
* @file os_win32.h
* @brief Describes Win32 operating system family specifics.
*/
#define PJ_OS_NAME "winphone"
#define WIN32_LEAN_AND_MEAN
#define RPC_NO_WINDOWS_H
#define PJ_WIN32_WINNT 0x0602 /*_WIN32_WINNT_WIN8*/
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#define _WIN32_WINNT PJ_WIN32_WINNT
#endif
#define PJ_HAS_ARPA_INET_H 0
#define PJ_HAS_ASSERT_H 1
#define PJ_HAS_CTYPE_H 1
#define PJ_HAS_ERRNO_H 0 /* Must be zero, otherwise errno_test() fails. */
#define PJ_HAS_LINUX_SOCKET_H 0
#define PJ_HAS_MALLOC_H 1
#define PJ_HAS_NETDB_H 0
#define PJ_HAS_NETINET_IN_H 0
#define PJ_HAS_NETINET_TCP_H 0
#define PJ_HAS_SETJMP_H 1
#define PJ_HAS_STDARG_H 1
#define PJ_HAS_STDDEF_H 1
#define PJ_HAS_STDIO_H 1
#define PJ_HAS_STDLIB_H 1
#define PJ_HAS_STRING_H 1
#define PJ_HAS_SYS_IOCTL_H 0
#define PJ_HAS_SYS_SELECT_H 0
#define PJ_HAS_SYS_SOCKET_H 0
#define PJ_HAS_SYS_TIME_H 0
#define PJ_HAS_SYS_TIMEB_H 0 /* Doesn't have sys/timeb.h */
#define PJ_HAS_SYS_TYPES_H 0 /* Doesn't have sys/types.h */
#define PJ_HAS_TIME_H 1
#define PJ_HAS_UNISTD_H 0
#define PJ_HAS_MSWSOCK_H 1
#define PJ_HAS_WINSOCK_H 0
#define PJ_HAS_WINSOCK2_H 1
#define PJ_SOCK_HAS_INET_ATON 0
/* Set 1 if native sockaddr_in has sin_len member.
* Default: 0
*/
#define PJ_SOCKADDR_HAS_LEN 0
/* Is errno a good way to retrieve OS errors? (no)
*/
#define PJ_HAS_ERRNO_VAR 0
/* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return
* the status of non-blocking connect() operation.
*/
#define PJ_HAS_SO_ERROR 0
/* This value specifies the value set in errno by the OS when a non-blocking
* socket recv() or send() can not return immediately.
*/
#define PJ_BLOCKING_ERROR_VAL WSAEWOULDBLOCK
/* This value specifies the value set in errno by the OS when a non-blocking
* socket connect() can not get connected immediately.
*/
#define PJ_BLOCKING_CONNECT_ERROR_VAL WSAEWOULDBLOCK
/**
* If this macro is set, it tells select I/O Queue that select() needs to
* be given correct value of nfds (i.e. largest fd + 1). This requires
* select ioqueue to re-scan the descriptors on each registration and
* unregistration.
* If this macro is not set, then ioqueue will always give FD_SETSIZE for
* nfds argument when calling select().
*
* Default: 0
*/
#define PJ_SELECT_NEEDS_NFDS 0
/* Endianness */
#ifndef PJ_IS_LITTLE_ENDIAN
# define PJ_IS_LITTLE_ENDIAN 1
# define PJ_IS_BIG_ENDIAN 0
#endif
/* Default threading is enabled, unless it's overridden. */
#ifndef PJ_HAS_THREADS
# define PJ_HAS_THREADS (1)
#endif
#define PJ_HAS_HIGH_RES_TIMER 1
#define PJ_HAS_MALLOC 1
#define PJ_OS_HAS_CHECK_STACK 1
#define PJ_ATOMIC_VALUE_TYPE long
/* No console. */
#define PJ_TERM_HAS_COLOR 0
/* TlsAlloc() error value. */
#define TLS_OUT_OF_INDEXES 0xFFFFFFFF
/* No rdtsc */
#define PJ_TIMESTAMP_USE_RDTSC 0
/* Native string is Unicode. */
#define PJ_NATIVE_STRING_IS_UNICODE 1
/* If 1, use Read/Write mutex emulation for platforms that don't support it */
#define PJ_EMULATE_RWMUTEX 1
/* If 1, pj_thread_create() should enforce the stack size when creating
* threads.
* Default: 0 (let OS decide the thread's stack size).
*/
#define PJ_THREAD_SET_STACK_SIZE 0
/* If 1, pj_thread_create() should allocate stack from the pool supplied.
* Default: 0 (let OS allocate memory for thread's stack).
*/
#define PJ_THREAD_ALLOCATE_STACK 0
#endif /* __PJ_COMPAT_OS_WIN32_WINCE_H__ */
/* $Id$ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PJ_COMPAT_OS_WINPHONE_H__
#define __PJ_COMPAT_OS_WIN32_WINPHONE_H__
/**
* @file os_win32.h
* @brief Describes Win32 operating system family specifics.
*/
#define PJ_OS_NAME "winphone"
#define WIN32_LEAN_AND_MEAN
#define RPC_NO_WINDOWS_H
#define PJ_WIN32_WINNT 0x0602 /*_WIN32_WINNT_WIN8*/
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#define _WIN32_WINNT PJ_WIN32_WINNT
#endif
#define PJ_HAS_ARPA_INET_H 0
#define PJ_HAS_ASSERT_H 1
#define PJ_HAS_CTYPE_H 1
#define PJ_HAS_ERRNO_H 0 /* Must be zero, otherwise errno_test() fails. */
#define PJ_HAS_LINUX_SOCKET_H 0
#define PJ_HAS_MALLOC_H 1
#define PJ_HAS_NETDB_H 0
#define PJ_HAS_NETINET_IN_H 0
#define PJ_HAS_NETINET_TCP_H 0
#define PJ_HAS_SETJMP_H 1
#define PJ_HAS_STDARG_H 1
#define PJ_HAS_STDDEF_H 1
#define PJ_HAS_STDIO_H 1
#define PJ_HAS_STDLIB_H 1
#define PJ_HAS_STRING_H 1
#define PJ_HAS_SYS_IOCTL_H 0
#define PJ_HAS_SYS_SELECT_H 0
#define PJ_HAS_SYS_SOCKET_H 0
#define PJ_HAS_SYS_TIME_H 0
#define PJ_HAS_SYS_TIMEB_H 0 /* Doesn't have sys/timeb.h */
#define PJ_HAS_SYS_TYPES_H 0 /* Doesn't have sys/types.h */
#define PJ_HAS_TIME_H 1
#define PJ_HAS_UNISTD_H 0
#define PJ_HAS_MSWSOCK_H 1
#define PJ_HAS_WINSOCK_H 0
#define PJ_HAS_WINSOCK2_H 1
#define PJ_SOCK_HAS_INET_ATON 0
/* Set 1 if native sockaddr_in has sin_len member.
* Default: 0
*/
#define PJ_SOCKADDR_HAS_LEN 0
/* Is errno a good way to retrieve OS errors? (no)
*/
#define PJ_HAS_ERRNO_VAR 0
/* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return
* the status of non-blocking connect() operation.
*/
#define PJ_HAS_SO_ERROR 0
/* This value specifies the value set in errno by the OS when a non-blocking
* socket recv() or send() can not return immediately.
*/
#define PJ_BLOCKING_ERROR_VAL WSAEWOULDBLOCK
/* This value specifies the value set in errno by the OS when a non-blocking
* socket connect() can not get connected immediately.
*/
#define PJ_BLOCKING_CONNECT_ERROR_VAL WSAEWOULDBLOCK
/**
* If this macro is set, it tells select I/O Queue that select() needs to
* be given correct value of nfds (i.e. largest fd + 1). This requires
* select ioqueue to re-scan the descriptors on each registration and
* unregistration.
* If this macro is not set, then ioqueue will always give FD_SETSIZE for
* nfds argument when calling select().
*
* Default: 0
*/
#define PJ_SELECT_NEEDS_NFDS 0
/* Endianness */
#ifndef PJ_IS_LITTLE_ENDIAN
# define PJ_IS_LITTLE_ENDIAN 1
# define PJ_IS_BIG_ENDIAN 0
#endif
/* Default threading is enabled, unless it's overridden. */
#ifndef PJ_HAS_THREADS
# define PJ_HAS_THREADS (1)
#endif
#define PJ_HAS_HIGH_RES_TIMER 1
#define PJ_HAS_MALLOC 1
#define PJ_OS_HAS_CHECK_STACK 1
#define PJ_ATOMIC_VALUE_TYPE long
/* No console. */
#define PJ_TERM_HAS_COLOR 0
/* TlsAlloc() error value. */
#define TLS_OUT_OF_INDEXES 0xFFFFFFFF
/* No rdtsc */
#define PJ_TIMESTAMP_USE_RDTSC 0
/* Native string is Unicode. */
#define PJ_NATIVE_STRING_IS_UNICODE 1
/* If 1, use Read/Write mutex emulation for platforms that don't support it */
#define PJ_EMULATE_RWMUTEX 1
/* If 1, pj_thread_create() should enforce the stack size when creating
* threads.
* Default: 0 (let OS decide the thread's stack size).
*/
#define PJ_THREAD_SET_STACK_SIZE 0
/* If 1, pj_thread_create() should allocate stack from the pool supplied.
* Default: 0 (let OS allocate memory for thread's stack).
*/
#define PJ_THREAD_ALLOCATE_STACK 0
#endif /* __PJ_COMPAT_OS_WIN32_WINCE_H__ */
#endif /* __PJ_COMPAT_OS_WIN32_WINPHONE_H__ */

View File

@ -35,13 +35,13 @@
static pj_status_t get_file_size(HANDLE hFile, pj_off_t *size)
{
#ifdef PJ_WIN32_WINPHONE
FILE_STANDARD_INFO fileInfo;
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
FILE_COMPRESSION_INFO fileInfo;
if (GetFileInformationByHandleEx(hFile, FileStandardInfo, &fileInfo,
sizeof(FILE_STANDARD_INFO)))
if (GetFileInformationByHandleEx(hFile, FileCompressionInfo, &fileInfo,
sizeof(FILE_COMPRESSION_INFO)))
{
*size = fileInfo.AllocationSize.QuadPart;
*size = fileInfo.CompressedFileSize.QuadPart;
} else {
*size = -1;
return PJ_RETURN_OS_ERROR(GetLastError());
@ -70,7 +70,7 @@ static HANDLE WINAPI create_file(LPCTSTR filename, DWORD desired_access,
DWORD flags_and_attributes,
HANDLE template_file)
{
#ifdef PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
PJ_UNUSED_ARG(security_attributes);
PJ_UNUSED_ARG(flags_and_attributes);
PJ_UNUSED_ARG(template_file);
@ -215,7 +215,7 @@ PJ_DEF(pj_status_t) pj_file_getstat(const char *filename, pj_file_stat *stat)
PJ_DECL_UNICODE_TEMP_BUF(wfilename,256)
HANDLE hFile;
FILETIME creationTime, accessTime, writeTime;
#ifdef PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
FILE_BASIC_INFO fileInfo;
#endif
@ -233,7 +233,7 @@ PJ_DEF(pj_status_t) pj_file_getstat(const char *filename, pj_file_stat *stat)
CloseHandle(hFile);
return PJ_RETURN_OS_ERROR(GetLastError());
}
#ifdef PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
if (GetFileInformationByHandleEx(hFile, FileBasicInfo, &fileInfo,
sizeof(FILE_BASIC_INFO)))
{

View File

@ -88,7 +88,7 @@ PJ_DEF(pj_status_t) pj_file_open( pj_pool_t *pool,
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
#ifdef PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
hFile = CreateFile2(PJ_STRING_TO_NATIVE(pathname,
wpathname,sizeof(wpathname)),
dwDesiredAccess, dwShareMode, dwCreationDisposition,
@ -189,7 +189,7 @@ static pj_status_t set_file_pointer(pj_oshandle_t fd,
pj_off_t* newPos,
DWORD dwMoveMethod)
{
#ifdef PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
LARGE_INTEGER liDistance, liNewPos;
liDistance.QuadPart = offset;

View File

@ -879,8 +879,20 @@ PJ_DEF(int) pj_ioqueue_poll( pj_ioqueue_t *ioqueue, const pj_time_val *timeout)
/* Unlock ioqueue before select(). */
pj_lock_release(ioqueue->lock);
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
count = 0;
__try {
#endif
count = pj_sock_select(ioqueue->nfds+1, &rfdset, &wfdset, &xfdset,
timeout);
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
/* Ignore Invalid Handle Exception raised by select().*/
} __except(GetExceptionCode() == STATUS_INVALID_HANDLE?
EXCEPTION_CONTINUE_EXECUTION:EXCEPTION_CONTINUE_SEARCH) {
}
#endif
if (count == 0)
return 0;

View File

@ -38,8 +38,8 @@
# include <winsock2.h>
#endif
#if PJ_WIN32_WINPHONE
# include "../../third_party/threademulation/include/ThreadEmulation.h"
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
# include "../../../third_party/threademulation/include/ThreadEmulation.h"
#endif
#if PJ_WIN32_WINNT >= 0x0602
@ -305,7 +305,7 @@ PJ_DEF(pj_bool_t) pj_thread_is_registered(void)
*/
PJ_DEF(int) pj_thread_get_prio(pj_thread_t *thread)
{
#if PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
PJ_UNUSED_ARG(thread);
return -1;
#else
@ -325,7 +325,11 @@ PJ_DEF(pj_status_t) pj_thread_set_prio(pj_thread_t *thread, int prio)
prio<=THREAD_PRIORITY_TIME_CRITICAL,
PJ_EINVAL);
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
if (SetThreadPriorityRT(thread->hthread, prio) == FALSE)
#else
if (SetThreadPriority(thread->hthread, prio) == FALSE)
#endif
return PJ_RETURN_OS_ERROR(GetLastError());
return PJ_SUCCESS;
@ -486,6 +490,10 @@ PJ_DEF(pj_status_t) pj_thread_create( pj_pool_t *pool,
DWORD dwflags = 0;
pj_thread_t *rec;
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
PJ_UNUSED_ARG(stack_size);
#endif
PJ_CHECK_STACK();
PJ_ASSERT_RETURN(pool && proc && thread_ptr, PJ_EINVAL);
@ -520,10 +528,10 @@ PJ_DEF(pj_status_t) pj_thread_create( pj_pool_t *pool,
rec->proc = proc;
rec->arg = arg;
#ifdef PJ_WIN32_WINPHONE
rec->hthread = CreateThread(NULL, stack_size,
thread_main, rec,
dwflags, NULL);
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
rec->hthread = CreateThreadRT(NULL, 0,
thread_main, rec,
dwflags, NULL);
#else
rec->hthread = CreateThread(NULL, stack_size,
thread_main, rec,
@ -561,7 +569,11 @@ PJ_DEF(pj_status_t) pj_thread_resume(pj_thread_t *p)
PJ_CHECK_STACK();
PJ_ASSERT_RETURN(p, PJ_EINVAL);
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
if (ResumeThreadRT(rec->hthread) == (DWORD)-1)
#else
if (ResumeThread(rec->hthread) == (DWORD)-1)
#endif
return PJ_RETURN_OS_ERROR(GetLastError());
else
return PJ_SUCCESS;
@ -605,7 +617,7 @@ PJ_DEF(pj_status_t) pj_thread_join(pj_thread_t *p)
PJ_LOG(6, (pj_thread_this()->obj_name, "Joining thread %s", p->obj_name));
#if PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
rc = WaitForSingleObjectEx(rec->hthread, INFINITE, FALSE);
#else
rc = WaitForSingleObject(rec->hthread, INFINITE);
@ -641,7 +653,11 @@ PJ_DEF(pj_status_t) pj_thread_destroy(pj_thread_t *p)
PJ_DEF(pj_status_t) pj_thread_sleep(unsigned msec)
{
PJ_CHECK_STACK();
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
SleepRT(msec);
#else
Sleep(msec);
#endif
return PJ_SUCCESS;
}
@ -835,7 +851,11 @@ PJ_DEF(pj_status_t) pj_thread_local_alloc(long *index)
//beginning before main thread is initialized.
//PJ_CHECK_STACK();
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
*index = TlsAllocRT();
#else
*index = TlsAlloc();
#endif
if (*index == TLS_OUT_OF_INDEXES)
return PJ_RETURN_OS_ERROR(GetLastError());
@ -849,7 +869,11 @@ PJ_DEF(pj_status_t) pj_thread_local_alloc(long *index)
PJ_DEF(void) pj_thread_local_free(long index)
{
PJ_CHECK_STACK();
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
TlsFreeRT(index);
#else
TlsFree(index);
#endif
}
/*
@ -862,7 +886,11 @@ PJ_DEF(pj_status_t) pj_thread_local_set(long index, void *value)
//Can't check stack because this function is called in the
//beginning before main thread is initialized.
//PJ_CHECK_STACK();
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
rc = TlsSetValueRT(index, value);
#else
rc = TlsSetValue(index, value);
#endif
return rc!=0 ? PJ_SUCCESS : PJ_RETURN_OS_ERROR(GetLastError());
}
@ -874,7 +902,11 @@ PJ_DEF(void*) pj_thread_local_get(long index)
//Can't check stack because this function is called
//by PJ_CHECK_STACK() itself!!!
//PJ_CHECK_STACK();
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
return TlsGetValueRT(index);
#else
return TlsGetValue(index);
#endif
}
///////////////////////////////////////////////////////////////////////////////
@ -883,7 +915,7 @@ static pj_status_t init_mutex(pj_mutex_t *mutex, const char *name)
PJ_CHECK_STACK();
#if PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
InitializeCriticalSectionEx(&mutex->crit, 0, 0);
#elif PJ_WIN32_WINNT >= 0x0400
InitializeCriticalSection(&mutex->crit);
@ -1139,7 +1171,7 @@ PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool,
PJ_ASSERT_RETURN(pool && sem_ptr, PJ_EINVAL);
sem = pj_pool_alloc(pool, sizeof(*sem));
#if PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
/** SEMAPHORE_ALL_ACCESS **/
sem->hSemaphore = CreateSemaphoreEx(NULL, initial, max, NULL, 0,
SEMAPHORE_ALL_ACCESS);
@ -1176,7 +1208,7 @@ static pj_status_t pj_sem_wait_for(pj_sem_t *sem, unsigned timeout)
LOG_MUTEX((sem->obj_name, "Semaphore: thread %s is waiting",
pj_thread_this()->obj_name));
#if PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
result = WaitForSingleObjectEx(sem->hSemaphore, timeout, FALSE);
#else
result = WaitForSingleObject(sem->hSemaphore, timeout);
@ -1278,7 +1310,7 @@ PJ_DEF(pj_status_t) pj_event_create( pj_pool_t *pool,
if (!event)
return PJ_ENOMEM;
#if PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
event->hEvent = CreateEventEx(NULL, NULL,
(manual_reset?0x1:0x0)|(initial?0x2:0x0),
EVENT_ALL_ACCESS);
@ -1317,7 +1349,7 @@ static pj_status_t pj_event_wait_for(pj_event_t *event, unsigned timeout)
PJ_LOG(6, (event->obj_name, "Event: thread %s is waiting",
pj_thread_this()->obj_name));
#if PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
result = WaitForSingleObjectEx(event->hEvent, timeout, FALSE);
#else
result = WaitForSingleObject(event->hEvent, timeout);
@ -1379,7 +1411,7 @@ PJ_DEF(pj_status_t) pj_event_set(pj_event_t *event)
*/
PJ_DEF(pj_status_t) pj_event_pulse(pj_event_t *event)
{
#ifdef PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
PJ_UNUSED_ARG(event);
pj_assert(!"pj_event_pulse() not supported!");
return PJ_ENOTSUP;

View File

@ -186,7 +186,7 @@ PJ_DEF(const pj_sys_info*) pj_get_sys_info(void)
#endif
#elif defined(_MSC_VER)
{
#ifdef PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
si.os_name = pj_str("winphone");
#else
OSVERSIONINFO ovi;
@ -209,7 +209,7 @@ PJ_DEF(const pj_sys_info*) pj_get_sys_info(void)
{
SYSTEM_INFO wsi;
#ifdef PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
GetNativeSystemInfo(&wsi);
#else
GetSystemInfo(&wsi);
@ -237,7 +237,7 @@ PJ_DEF(const pj_sys_info*) pj_get_sys_info(void)
break;
#endif /* PJ_WIN32_WINCE || PJ_WIN32_WINPHONE */
}
#ifdef PJ_WIN32_WINPHONE
#if defined(PJ_WIN32_WINPHONE) && PJ_WIN32_WINPHONE
/* Avoid compile warning. */
goto get_sdk_info;
#endif

View File

@ -33,29 +33,27 @@
#include <windows.h>
#ifdef __cplusplus
namespace ThreadEmulation
{
extern "C" {
//namespace ThreadEmulation
//{
extern "C"
{
#endif
#ifndef CREATE_SUSPENDED
#define CREATE_SUSPENDED 0x00000004
#endif
HANDLE WINAPI CreateThread(_In_opt_ LPSECURITY_ATTRIBUTES unusedThreadAttributes, _In_ SIZE_T unusedStackSize, _In_ LPTHREAD_START_ROUTINE lpStartAddress, _In_opt_ LPVOID lpParameter, _In_ DWORD dwCreationFlags, _Out_opt_ LPDWORD unusedThreadId);
DWORD WINAPI ResumeThread(_In_ HANDLE hThread);
BOOL WINAPI SetThreadPriority(_In_ HANDLE hThread, _In_ int nPriority);
HANDLE WINAPI CreateThreadRT(_In_opt_ LPSECURITY_ATTRIBUTES unusedThreadAttributes, _In_ SIZE_T unusedStackSize, _In_ LPTHREAD_START_ROUTINE lpStartAddress, _In_opt_ LPVOID lpParameter, _In_ DWORD dwCreationFlags, _Out_opt_ LPDWORD unusedThreadId);
DWORD WINAPI ResumeThreadRT(_In_ HANDLE hThread);
BOOL WINAPI SetThreadPriorityRT(_In_ HANDLE hThread, _In_ int nPriority);
VOID WINAPI Sleep(_In_ DWORD dwMilliseconds);
VOID WINAPI SleepRT(_In_ DWORD dwMilliseconds);
DWORD WINAPI TlsAlloc();
BOOL WINAPI TlsFree(_In_ DWORD dwTlsIndex);
LPVOID WINAPI TlsGetValue(_In_ DWORD dwTlsIndex);
BOOL WINAPI TlsSetValue(_In_ DWORD dwTlsIndex, _In_opt_ LPVOID lpTlsValue);
DWORD WINAPI TlsAllocRT();
BOOL WINAPI TlsFreeRT(_In_ DWORD dwTlsIndex);
LPVOID WINAPI TlsGetValueRT(_In_ DWORD dwTlsIndex);
BOOL WINAPI TlsSetValueRT(_In_ DWORD dwTlsIndex, _In_opt_ LPVOID lpTlsValue);
void WINAPI TlsShutdown();
#ifdef __cplusplus
}
}
#endif
#endif

View File

@ -5,7 +5,6 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//#include "ThreadEmulation.h"
#include "../include/ThreadEmulation.h"
#include <assert.h>
@ -19,11 +18,8 @@ using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::System::Threading;
#ifdef __cplusplus
namespace ThreadEmulation
{
#endif
//namespace ThreadEmulation
//{
// Stored data for CREATE_SUSPENDED and ResumeThread.
struct PendingThreadInfo
{
@ -83,7 +79,8 @@ namespace ThreadEmulation
ThreadPool::RunAsync(workItemHandler, GetWorkItemPriority(nPriority), WorkItemOptions::TimeSliced);
}
_Use_decl_annotations_ HANDLE WINAPI CreateThread(LPSECURITY_ATTRIBUTES unusedThreadAttributes, SIZE_T unusedStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD unusedThreadId)
_Use_decl_annotations_ HANDLE WINAPI CreateThreadRT(LPSECURITY_ATTRIBUTES unusedThreadAttributes, SIZE_T unusedStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD unusedThreadId)
{
// Validate parameters.
assert(unusedThreadAttributes == nullptr);
@ -142,7 +139,8 @@ namespace ThreadEmulation
}
}
_Use_decl_annotations_ DWORD WINAPI ResumeThread(HANDLE hThread)
_Use_decl_annotations_ DWORD WINAPI ResumeThreadRT(HANDLE hThread)
{
lock_guard<mutex> lock(pendingThreadsLock);
@ -175,7 +173,7 @@ namespace ThreadEmulation
}
_Use_decl_annotations_ BOOL WINAPI SetThreadPriority(HANDLE hThread, int nPriority)
_Use_decl_annotations_ BOOL WINAPI SetThreadPriorityRT(HANDLE hThread, int nPriority)
{
lock_guard<mutex> lock(pendingThreadsLock);
@ -196,7 +194,7 @@ namespace ThreadEmulation
}
_Use_decl_annotations_ VOID WINAPI Sleep(DWORD dwMilliseconds)
_Use_decl_annotations_ VOID WINAPI SleepRT(DWORD dwMilliseconds)
{
static HANDLE singletonEvent = nullptr;
@ -225,7 +223,7 @@ namespace ThreadEmulation
}
DWORD WINAPI TlsAlloc()
DWORD WINAPI TlsAllocRT()
{
lock_guard<mutex> lock(tlsAllocationLock);
@ -242,7 +240,7 @@ namespace ThreadEmulation
}
_Use_decl_annotations_ BOOL WINAPI TlsFree(DWORD dwTlsIndex)
_Use_decl_annotations_ BOOL WINAPI TlsFreeRT(DWORD dwTlsIndex)
{
lock_guard<mutex> lock(tlsAllocationLock);
@ -272,7 +270,7 @@ namespace ThreadEmulation
}
_Use_decl_annotations_ LPVOID WINAPI TlsGetValue(DWORD dwTlsIndex)
_Use_decl_annotations_ LPVOID WINAPI TlsGetValueRT(DWORD dwTlsIndex)
{
ThreadLocalData* threadData = currentThreadData;
@ -289,7 +287,7 @@ namespace ThreadEmulation
}
_Use_decl_annotations_ BOOL WINAPI TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue)
_Use_decl_annotations_ BOOL WINAPI TlsSetValueRT(DWORD dwTlsIndex, LPVOID lpTlsValue)
{
ThreadLocalData* threadData = currentThreadData;
@ -354,6 +352,4 @@ namespace ThreadEmulation
delete threadData;
}
}
#ifdef __cplusplus
}
#endif
//}