Update to latest libHttpClient (#180)
* Using new libHttpClient events to manage tasks * New subsystemId parameter used * Added memhook functions. Still not using these until xsapi core also honors them
This commit is contained in:
Родитель
11c2ab3f38
Коммит
61ca772a53
|
@ -229,10 +229,6 @@ namespace Microsoft.Xbox.Services.Statistics.Manager
|
|||
// Invokes the c method
|
||||
XSAPI_RESULT errCode = StatsManagerGetStatNames(user.Impl.XboxLiveUserPtr, out cStatListPtr, out statListCount, out cErrMessage);
|
||||
|
||||
// Handles error
|
||||
string errMessage = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(cErrMessage));
|
||||
Marshal.FreeHGlobal(cErrMessage);
|
||||
|
||||
if (errCode != XSAPI_RESULT.XSAPI_RESULT_OK)
|
||||
{
|
||||
throw new XboxException(errCode, cErrMessage);
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Microsoft.Xbox.Services
|
|||
try
|
||||
{
|
||||
#if WINDOWS_UWP
|
||||
var result = XBLGlobalInitialize();
|
||||
var result = XsapiGlobalInitialize();
|
||||
if (result != XSAPI_RESULT.XSAPI_RESULT_OK)
|
||||
{
|
||||
throw new XboxException(result);
|
||||
|
@ -50,7 +50,7 @@ namespace Microsoft.Xbox.Services
|
|||
|
||||
~XboxLive()
|
||||
{
|
||||
XBLGlobalCleanup();
|
||||
XsapiGlobalCleanup();
|
||||
}
|
||||
|
||||
public static XboxLive Instance
|
||||
|
@ -138,9 +138,9 @@ namespace Microsoft.Xbox.Services
|
|||
}
|
||||
|
||||
[DllImport(XboxLive.FlatCDllName)]
|
||||
private static extern XSAPI_RESULT XBLGlobalInitialize();
|
||||
private static extern XSAPI_RESULT XsapiGlobalInitialize();
|
||||
|
||||
[DllImport(XboxLive.FlatCDllName)]
|
||||
private static extern void XBLGlobalCleanup();
|
||||
private static extern void XsapiGlobalCleanup();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,9 +99,6 @@
|
|||
<ItemGroup>
|
||||
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
|
||||
<None Include="project.json" />
|
||||
<Content Include="Microsoft.Xbox.Services.140.UWP.C.dll">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="XboxServices.config">
|
||||
<SubType>Designer</SubType>
|
||||
</Content>
|
||||
|
|
|
@ -142,7 +142,7 @@
|
|||
<ClCompile Include="..\..\Source\Services\Common\pch.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\Services\Common\services_global.cpp" />
|
||||
<ClCompile Include="..\..\Source\Services\Common\xbox_live_global.cpp" />
|
||||
<ClCompile Include="..\..\Source\Services\Common\xbox_live_context.cpp" />
|
||||
<ClCompile Include="..\..\Source\Services\Common\xbox_live_context_impl.cpp" />
|
||||
<ClCompile Include="..\..\Source\Services\Leaderboard\leaderboard.cpp" />
|
||||
|
@ -172,7 +172,6 @@
|
|||
<ClInclude Include="..\..\Include\xsapi\privacy_c.h" />
|
||||
<ClInclude Include="..\..\Include\xsapi\leaderboard_c.h" />
|
||||
<ClInclude Include="..\..\Include\xsapi\presence_c.h" />
|
||||
<ClInclude Include="..\..\Include\xsapi\services_c.h" />
|
||||
<ClInclude Include="..\..\Include\xsapi\social_manager_c.h" />
|
||||
<ClInclude Include="..\..\Include\xsapi\stats_manager_c.h" />
|
||||
<ClInclude Include="..\..\Include\xsapi\system_c.h" />
|
||||
|
@ -181,6 +180,7 @@
|
|||
<ClInclude Include="..\..\Include\xsapi\types_c.h" />
|
||||
<ClInclude Include="..\..\Include\xsapi\xbox_live_app_config_c.h" />
|
||||
<ClInclude Include="..\..\Include\xsapi\xbox_live_context_c.h" />
|
||||
<ClInclude Include="..\..\Include\xsapi\xbox_live_global_c.h" />
|
||||
<ClInclude Include="..\..\Source\Services\Common\pch.h" />
|
||||
<ClInclude Include="..\..\Source\Services\Common\pch_common.h" />
|
||||
<ClInclude Include="..\..\Source\Services\Common\taskargs.h" />
|
||||
|
|
|
@ -45,9 +45,6 @@
|
|||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\Include\xsapi\services_c.h">
|
||||
<Filter>C++ Public Includes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\Services\Common\pch.h">
|
||||
<Filter>C++ Source\Services\Common</Filter>
|
||||
</ClInclude>
|
||||
|
@ -144,6 +141,9 @@
|
|||
<ClInclude Include="..\..\Source\Services\Social\Manager\social_manager_helper.h">
|
||||
<Filter>C++ Source\Services\Social\Manager</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Include\xsapi\xbox_live_global_c.h">
|
||||
<Filter>C++ Public Includes</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\Source\Services\Common\pch.cpp">
|
||||
|
@ -167,9 +167,6 @@
|
|||
<ClCompile Include="..\..\Source\Shared\threadpool.cpp">
|
||||
<Filter>C++ Source\Shared</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\Services\Common\services_global.cpp">
|
||||
<Filter>C++ Source\Services\Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\Shared\singleton.cpp">
|
||||
<Filter>C++ Source\Shared</Filter>
|
||||
</ClCompile>
|
||||
|
@ -221,6 +218,9 @@
|
|||
<ClCompile Include="..\..\Source\Services\Social\Manager\social_manager_helper.cpp">
|
||||
<Filter>C++ Source\Services\Social\Manager</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\Services\Common\xbox_live_global.cpp">
|
||||
<Filter>C++ Source\Services\Common</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 5985365ea828e667eb4a1d8ce1be75335950db5a
|
||||
Subproject commit e1b160f6247a90f4bbc46968f44d178800793f61
|
|
@ -1,36 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#pragma once
|
||||
#pragma warning(disable: 4265)
|
||||
#pragma warning(disable: 4266)
|
||||
#pragma warning(disable: 4062)
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Global APIs
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the library instance.
|
||||
/// This must be called before any other method, except for HCMemSetFunctions() and HCMemGetFunctions()
|
||||
/// Should have a corresponding call to HCGlobalCleanup().
|
||||
/// </summary>
|
||||
XBL_API XSAPI_RESULT XBL_CALLING_CONV
|
||||
XBLGlobalInitialize() XSAPI_NOEXCEPT;
|
||||
|
||||
/// <summary>
|
||||
/// Immediately reclaims all resources associated with the library.
|
||||
/// If you called HCMemSetFunctions(), call this before shutting down your app's memory manager.
|
||||
/// </summary>
|
||||
XBL_API void XBL_CALLING_CONV
|
||||
XBLGlobalCleanup() XSAPI_NOEXCEPT;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // end extern "C"
|
||||
#endif // defined(__cplusplus)
|
||||
|
|
@ -84,4 +84,6 @@
|
|||
#define XSAPI_NOEXCEPT noexcept
|
||||
#else
|
||||
#define XSAPI_NOEXCEPT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef uint32_t XSAPI_MEMORY_TYPE;
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
// Copyright (c) Microsoft Corporation
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#pragma once
|
||||
#pragma warning(disable: 4265)
|
||||
#pragma warning(disable: 4266)
|
||||
#pragma warning(disable: 4062)
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Memory APIs
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// A callback invoked every time a new memory buffer must be dynamically allocated by the library.
|
||||
/// This callback is optionally installed by calling XSAPIMemSetFunctions()
|
||||
///
|
||||
/// The callback must allocate and return a pointer to a contiguous block of memory of the
|
||||
/// specified size that will remain valid until the app's corresponding XSAPI_MEM_FREE_FUNC
|
||||
/// callback is invoked to release it.
|
||||
///
|
||||
/// Every non-null pointer returned by this method will be subsequently passed to the corresponding
|
||||
/// XSAPI_MEM_FREE_FUNC callback once the memory is no longer needed.
|
||||
/// </summary>
|
||||
/// <returns>A pointer to an allocated block of memory of the specified size, or a null
|
||||
/// pointer if allocation failed.</returns>
|
||||
/// <param name="size">The size of the allocation to be made. This value will never be zero.</param>
|
||||
/// <param name="memoryTypeId">An opaque identifier representing the internal category of
|
||||
/// memory being allocated.</param>
|
||||
typedef _Ret_maybenull_ _Post_writable_byte_size_(size) void*
|
||||
(XBL_CALLING_CONV* XSAPI_MEM_ALLOC_FUNC)(
|
||||
_In_ size_t size,
|
||||
_In_ XSAPI_MEMORY_TYPE memoryType
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// A callback invoked every time a previously allocated memory buffer is no longer needed by
|
||||
/// the library and can be freed. This callback is optionally installed by calling XSAPIMemSetFunctions()
|
||||
///
|
||||
/// The callback is invoked whenever the library has finished using a memory buffer previously
|
||||
/// returned by the app's corresponding XSAPI_MEM_ALLOC_FUNC such that the application can free the
|
||||
/// memory buffer.
|
||||
/// </summary>
|
||||
/// <param name="pointer">The pointer to the memory buffer previously allocated. This value will
|
||||
/// never be a null pointer.</param>
|
||||
/// <param name="memoryTypeId">An opaque identifier representing the internal category of
|
||||
/// memory being allocated.</param>
|
||||
typedef void
|
||||
(HC_CALLING_CONV* XSAPI_MEM_FREE_FUNC)(
|
||||
_In_ _Post_invalid_ void* pointer,
|
||||
_In_ XSAPI_MEMORY_TYPE memoryType
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Optionally sets the memory hook functions to allow callers to control route memory
|
||||
/// allocations to their own memory manager. This must be called before HCGlobalInitialize()
|
||||
/// and can not be called again until HCGlobalCleanup()
|
||||
///
|
||||
/// This method allows the application to install custom memory allocation routines in order
|
||||
/// to service all requests for new memory buffers instead of using default allocation routines.
|
||||
///
|
||||
/// The <paramref name="memAllocFunc" /> and <paramref name="memFreeFunc" /> parameters can be null
|
||||
/// pointers to restore the default routines. Both callback pointers must be null or both must
|
||||
/// be non-null. Mixing custom and default routines is not permitted.
|
||||
/// </summary>
|
||||
/// <param name="memAllocFunc">A pointer to the custom allocation callback to use, or a null
|
||||
/// pointer to restore the default.</param>
|
||||
/// <param name="memFreeFunc">A pointer to the custom freeing callback to use, or a null
|
||||
/// pointer to restore the default.</param>
|
||||
HC_API void HC_CALLING_CONV
|
||||
XsapiMemSetFunctions(
|
||||
_In_opt_ XSAPI_MEM_ALLOC_FUNC memAllocFunc,
|
||||
_In_opt_ XSAPI_MEM_FREE_FUNC memFreeFunc
|
||||
) XSAPI_NOEXCEPT;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the memory hook functions to allow callers to control route memory allocations to their
|
||||
/// own memory manager. This method allows the application get the default memory allocation routines.
|
||||
/// This can be used along with XSAPIMemSetFunctions() to monitor all memory allocations.
|
||||
/// </summary>
|
||||
/// <param name="memAllocFunc">Set to the current allocation callback. Returns the default routine
|
||||
/// if not previously set</param>
|
||||
/// <param name="memFreeFunc">Set to the to the current memory free callback. Returns the default
|
||||
/// routine if not previously set</param>
|
||||
/// <returns>Result code for this API operation. Possible values are XSAPI_RESULT_OK, XSAPI_RESULT_E_HC_INVALIDARG, or XSAPI_RESULT_E_HC_FAIL.</returns>
|
||||
HC_API XSAPI_RESULT HC_CALLING_CONV
|
||||
XsapiMemGetFunctions(
|
||||
_Out_ XSAPI_MEM_ALLOC_FUNC* memAllocFunc,
|
||||
_Out_ XSAPI_MEM_FREE_FUNC* memFreeFunc
|
||||
) XSAPI_NOEXCEPT;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Global APIs
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the library instance.
|
||||
/// This must be called before any other method, except for XSAPIMemSetFunctions() and XSAPIMemGetFunctions()
|
||||
/// Should have a corresponding call to XSAPIGlobalCleanup().
|
||||
/// </summary>
|
||||
XBL_API XSAPI_RESULT XBL_CALLING_CONV
|
||||
XsapiGlobalInitialize() XSAPI_NOEXCEPT;
|
||||
|
||||
/// <summary>
|
||||
/// Immediately reclaims all resources associated with the library.
|
||||
/// If you called XSAPIMemSetFunctions(), call this before shutting down your app's memory manager.
|
||||
/// </summary>
|
||||
XBL_API void XBL_CALLING_CONV
|
||||
XsapiGlobalCleanup() XSAPI_NOEXCEPT;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // end extern "C"
|
||||
#endif // defined(__cplusplus)
|
||||
|
|
@ -75,7 +75,7 @@ typedef int32_t FUNCTION_CONTEXT;
|
|||
|
||||
#include "xsapi/types_c.h"
|
||||
#include "xsapi/errors_c.h"
|
||||
#include "xsapi/services_c.h"
|
||||
#include "xsapi/xbox_live_global_c.h"
|
||||
#include "utils.h"
|
||||
#include "singleton.h"
|
||||
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
XBL_API XSAPI_RESULT XBL_CALLING_CONV
|
||||
XBLGlobalInitialize() XSAPI_NOEXCEPT
|
||||
try
|
||||
{
|
||||
auto singleton = get_xsapi_singleton(true);
|
||||
auto hcr = HCGlobalInitialize();
|
||||
if (hcr != HC_OK)
|
||||
{
|
||||
return utils::xsapi_result_from_hc_result(hcr);
|
||||
}
|
||||
singleton->m_threadPool->start_threads();
|
||||
|
||||
return XSAPI_RESULT_OK;
|
||||
}
|
||||
CATCH_RETURN()
|
||||
|
||||
XBL_API void XBL_CALLING_CONV
|
||||
XBLGlobalCleanup() XSAPI_NOEXCEPT
|
||||
try
|
||||
{
|
||||
cleanup_xsapi_singleton();
|
||||
HCGlobalCleanup();
|
||||
}
|
||||
CATCH_RETURN_WITH(;)
|
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) Microsoft Corporation
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
HC_API void HC_CALLING_CONV
|
||||
XsapiMemSetFunctions(
|
||||
_In_opt_ XSAPI_MEM_ALLOC_FUNC memAllocFunc,
|
||||
_In_opt_ XSAPI_MEM_FREE_FUNC memFreeFunc
|
||||
) XSAPI_NOEXCEPT
|
||||
{
|
||||
HCMemSetFunctions(memAllocFunc, memFreeFunc);
|
||||
}
|
||||
|
||||
HC_API XSAPI_RESULT HC_CALLING_CONV
|
||||
XsapiMemGetFunctions(
|
||||
_Out_ XSAPI_MEM_ALLOC_FUNC* memAllocFunc,
|
||||
_Out_ XSAPI_MEM_FREE_FUNC* memFreeFunc
|
||||
) XSAPI_NOEXCEPT
|
||||
{
|
||||
return utils::xsapi_result_from_hc_result(HCMemGetFunctions(memAllocFunc, memFreeFunc));
|
||||
}
|
||||
|
||||
XBL_API XSAPI_RESULT XBL_CALLING_CONV
|
||||
XsapiGlobalInitialize() XSAPI_NOEXCEPT
|
||||
try
|
||||
{
|
||||
auto singleton = get_xsapi_singleton(true);
|
||||
auto hcr = HCGlobalInitialize();
|
||||
if (hcr != HC_OK)
|
||||
{
|
||||
return utils::xsapi_result_from_hc_result(hcr);
|
||||
}
|
||||
singleton->m_threadPool->start_threads();
|
||||
|
||||
return XSAPI_RESULT_OK;
|
||||
}
|
||||
CATCH_RETURN()
|
||||
|
||||
XBL_API void XBL_CALLING_CONV
|
||||
XsapiGlobalCleanup() XSAPI_NOEXCEPT
|
||||
try
|
||||
{
|
||||
auto singleton = get_xsapi_singleton();
|
||||
if (singleton != nullptr)
|
||||
{
|
||||
singleton->m_threadPool->shutdown_active_threads();
|
||||
cleanup_xsapi_singleton();
|
||||
}
|
||||
HCGlobalCleanup();
|
||||
}
|
||||
CATCH_RETURN_WITH(;)
|
|
@ -134,6 +134,7 @@ try
|
|||
);
|
||||
|
||||
return utils::xsapi_result_from_hc_result(HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
LeaderboardResultGetNextExecute,
|
||||
static_cast<void*>(args),
|
||||
|
|
|
@ -46,6 +46,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
TCUIShowProfileCardUIExecute,
|
||||
static_cast<void*>(args),
|
||||
|
@ -88,6 +89,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
TCUICheckGamingPrivilegeSilentlyExecute,
|
||||
static_cast<void*>(tcuiArgs),
|
||||
|
@ -137,6 +139,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
TCUICheckGamingPrivilegeWithUIExecute,
|
||||
static_cast<void*>(tcuiArgs),
|
||||
|
|
|
@ -65,6 +65,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
get_privacy_list_execute,
|
||||
static_cast<void*>(args),
|
||||
|
@ -94,6 +95,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
get_privacy_list_execute,
|
||||
static_cast<void*>(args),
|
||||
|
@ -150,6 +152,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
check_permission_execute,
|
||||
static_cast<void*>(args),
|
||||
|
@ -228,6 +231,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
check_multiple_permissions_execute,
|
||||
static_cast<void*>(args),
|
||||
|
|
|
@ -61,6 +61,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
get_quota_execute,
|
||||
static_cast<void*>(args),
|
||||
|
@ -141,6 +142,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
get_blob_metadata_execute,
|
||||
static_cast<void*>(args),
|
||||
|
@ -201,6 +203,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
blob_metadata_result_get_next_execute,
|
||||
static_cast<void*>(args),
|
||||
|
@ -309,6 +312,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
delete_blob_execute,
|
||||
static_cast<void*>(args),
|
||||
|
@ -387,6 +391,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
download_blob_execute,
|
||||
static_cast<void*>(args),
|
||||
|
@ -454,6 +459,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
upload_blob_execute,
|
||||
static_cast<void*>(args),
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "pch.h"
|
||||
#include "threadpool.h"
|
||||
#include "xsapi/services_c.h"
|
||||
|
||||
#define MAX_THREADS 64
|
||||
|
||||
|
@ -14,6 +13,8 @@ xsapi_thread_pool::xsapi_thread_pool() :
|
|||
{
|
||||
memset(m_hActiveThreads, 0, sizeof(HANDLE) * MAX_THREADS);
|
||||
m_stopRequestedHandle.set(CreateEvent(nullptr, true, false, nullptr));
|
||||
m_completeReadyHandle.set(CreateEvent(nullptr, false, false, nullptr));
|
||||
m_pendingReadyHandle.set(CreateEvent(nullptr, false, false, nullptr));
|
||||
}
|
||||
|
||||
long xsapi_thread_pool::get_num_active_threads()
|
||||
|
@ -35,34 +36,51 @@ void xsapi_thread_pool::set_target_num_active_threads(long targetNumThreads)
|
|||
}
|
||||
}
|
||||
|
||||
HANDLE xsapi_thread_pool::get_pending_ready_handle()
|
||||
{
|
||||
return m_pendingReadyHandle.get();
|
||||
}
|
||||
|
||||
HANDLE xsapi_thread_pool::get_complete_ready_handle()
|
||||
{
|
||||
return m_completeReadyHandle.get();
|
||||
}
|
||||
|
||||
HANDLE xsapi_thread_pool::get_stop_handle()
|
||||
{
|
||||
return m_stopRequestedHandle.get();
|
||||
}
|
||||
|
||||
HANDLE xsapi_thread_pool::get_ready_handle()
|
||||
{
|
||||
return m_readyHandle.get();
|
||||
}
|
||||
|
||||
void xsapi_thread_pool::set_async_op_ready()
|
||||
{
|
||||
SetEvent(get_ready_handle());
|
||||
}
|
||||
|
||||
DWORD WINAPI xbox_live_thread_proc(LPVOID lpParam)
|
||||
{
|
||||
HANDLE stopRequestedHandle = *((HANDLE*)(lpParam));
|
||||
auto threadPool = reinterpret_cast<xsapi_thread_pool*>(lpParam);
|
||||
HANDLE hEvents[3] =
|
||||
{
|
||||
threadPool->get_pending_ready_handle(),
|
||||
threadPool->get_complete_ready_handle(),
|
||||
threadPool->get_stop_handle()
|
||||
};
|
||||
|
||||
bool stop = false;
|
||||
while (!stop)
|
||||
{
|
||||
DWORD dwResult = WaitForSingleObject(stopRequestedHandle, 20);
|
||||
DWORD dwResult = WaitForMultipleObjectsEx(3, hEvents, false, INFINITE, false);
|
||||
switch (dwResult)
|
||||
{
|
||||
case WAIT_TIMEOUT:
|
||||
HCTaskProcessNextPendingTask();
|
||||
HCTaskProcessNextCompletedTask(0);
|
||||
case WAIT_OBJECT_0:
|
||||
HCTaskProcessNextPendingTask(HC_SUBSYSTEM_ID_XSAPI);
|
||||
if (HCTaskGetPendingTaskQueueSize(HC_SUBSYSTEM_ID_XSAPI) > 0)
|
||||
{
|
||||
SetEvent(threadPool->get_pending_ready_handle());
|
||||
};
|
||||
|
||||
break;
|
||||
case WAIT_OBJECT_0 + 1:
|
||||
HCTaskProcessNextCompletedTask(HC_SUBSYSTEM_ID_XSAPI, 0);
|
||||
if (HCTaskGetCompletedTaskQueueSize(HC_SUBSYSTEM_ID_XSAPI, 0) > 0)
|
||||
{
|
||||
SetEvent(threadPool->get_complete_ready_handle());
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -74,11 +92,38 @@ DWORD WINAPI xbox_live_thread_proc(LPVOID lpParam)
|
|||
return 0;
|
||||
}
|
||||
|
||||
HC_RESULT libhttpclient_event_handler(
|
||||
_In_opt_ void* context,
|
||||
_In_ HC_TASK_EVENT_TYPE eventType,
|
||||
_In_ HC_TASK_HANDLE taskHandle
|
||||
)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(taskHandle);
|
||||
|
||||
auto threadPool = reinterpret_cast<xsapi_thread_pool*>(context);
|
||||
switch (eventType)
|
||||
{
|
||||
case HC_TASK_EVENT_TYPE::HC_TASK_EVENT_PENDING:
|
||||
SetEvent(threadPool->get_pending_ready_handle());
|
||||
break;
|
||||
|
||||
case HC_TASK_EVENT_TYPE::HC_TASK_EVENT_EXECUTE_STARTED:
|
||||
break;
|
||||
|
||||
case HC_TASK_EVENT_TYPE::HC_TASK_EVENT_EXECUTE_COMPLETED:
|
||||
SetEvent(threadPool->get_complete_ready_handle());
|
||||
break;
|
||||
}
|
||||
return HC_OK;
|
||||
}
|
||||
|
||||
void xsapi_thread_pool::start_threads()
|
||||
{
|
||||
HCAddTaskEventHandler(HC_SUBSYSTEM_ID_XSAPI, this, libhttpclient_event_handler, &m_hcEventHandle);
|
||||
|
||||
for (int i = 0; i < m_targetNumThreads; i++)
|
||||
{
|
||||
m_hActiveThreads[i] = CreateThread(nullptr, 0, xbox_live_thread_proc, &m_stopRequestedHandle, 0, nullptr);
|
||||
m_hActiveThreads[i] = CreateThread(nullptr, 0, xbox_live_thread_proc, this, 0, nullptr);
|
||||
if (m_defaultIdealProcessor != MAXIMUM_PROCESSORS)
|
||||
{
|
||||
SetThreadIdealProcessor(m_hActiveThreads[i], m_defaultIdealProcessor);
|
||||
|
@ -90,6 +135,8 @@ void xsapi_thread_pool::start_threads()
|
|||
|
||||
void xsapi_thread_pool::shutdown_active_threads()
|
||||
{
|
||||
HCRemoveTaskEventHandler(m_hcEventHandle);
|
||||
|
||||
SetEvent(m_stopRequestedHandle.get());
|
||||
DWORD dwResult = WaitForMultipleObjectsEx(m_numActiveThreads, m_hActiveThreads, true, INFINITE, false);
|
||||
if (dwResult >= WAIT_OBJECT_0 && dwResult <= WAIT_OBJECT_0 + m_numActiveThreads - 1)
|
||||
|
|
|
@ -6,7 +6,7 @@ class xsapi_thread_pool
|
|||
{
|
||||
public:
|
||||
xsapi_thread_pool();
|
||||
|
||||
|
||||
void start_threads();
|
||||
|
||||
void set_target_num_active_threads(long targetNumThreads);
|
||||
|
@ -14,16 +14,19 @@ public:
|
|||
long get_num_active_threads();
|
||||
void set_thread_ideal_processor(_In_ int threadIndex, _In_ DWORD dwIdealProcessor);
|
||||
|
||||
HANDLE get_pending_ready_handle();
|
||||
HANDLE get_complete_ready_handle();
|
||||
HANDLE get_stop_handle();
|
||||
HANDLE get_ready_handle();
|
||||
void set_async_op_ready();
|
||||
|
||||
private:
|
||||
long m_targetNumThreads;
|
||||
win32_handle m_stopRequestedHandle;
|
||||
win32_handle m_readyHandle;
|
||||
win32_handle m_pendingReadyHandle;
|
||||
win32_handle m_completeReadyHandle;
|
||||
|
||||
long m_numActiveThreads;
|
||||
HANDLE m_hActiveThreads[64];
|
||||
DWORD m_defaultIdealProcessor;
|
||||
|
||||
HC_TASK_EVENT_HANDLE m_hcEventHandle;
|
||||
};
|
||||
|
|
|
@ -116,6 +116,7 @@ XSAPI_RESULT XboxLiveUserSignInHelper(
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID::HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
XboxLiveUserSignInExecute,
|
||||
static_cast<void*>(args),
|
||||
|
@ -254,6 +255,7 @@ try
|
|||
|
||||
return utils::xsapi_result_from_hc_result(
|
||||
HCTaskCreate(
|
||||
HC_SUBSYSTEM_ID::HC_SUBSYSTEM_ID_XSAPI,
|
||||
taskGroupId,
|
||||
XboxLiveUserGetTokenAndSignatureExecute,
|
||||
static_cast<void*>(args),
|
||||
|
|
Загрузка…
Ссылка в новой задаче