2012-09-18 23:51:33 +04:00
|
|
|
/**
|
|
|
|
* WinPR: Windows Portable Runtime
|
|
|
|
* Synchronization Functions
|
|
|
|
*
|
|
|
|
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2014-07-28 23:55:57 +04:00
|
|
|
* Copyright 2014 Thincast Technologies GmbH
|
2014-07-24 23:07:44 +04:00
|
|
|
* Copyright 2014 Norbert Federa <norbert.federa@thincast.com>
|
2012-09-18 23:51:33 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <winpr/synch.h>
|
2014-07-24 23:07:44 +04:00
|
|
|
#include <winpr/interlocked.h>
|
2012-09-18 23:51:33 +04:00
|
|
|
|
2014-08-18 19:22:22 +04:00
|
|
|
#include "../log.h"
|
2014-08-18 20:57:08 +04:00
|
|
|
#define TAG WINPR_TAG("sync")
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2014-07-24 23:07:44 +04:00
|
|
|
#if (!defined(_WIN32)) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
|
2012-09-19 02:36:13 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL winpr_InitOnceBeginInitialize(LPINIT_ONCE lpInitOnce, DWORD dwFlags, PBOOL fPending,
|
|
|
|
LPVOID* lpContext)
|
2012-09-18 23:51:33 +04:00
|
|
|
{
|
2014-08-18 19:22:22 +04:00
|
|
|
WLog_ERR(TAG, "not implemented");
|
2014-07-24 23:07:44 +04:00
|
|
|
return FALSE;
|
2012-09-18 23:51:33 +04:00
|
|
|
}
|
|
|
|
|
2016-06-16 12:47:33 +03:00
|
|
|
BOOL winpr_InitOnceComplete(LPINIT_ONCE lpInitOnce, DWORD dwFlags, LPVOID lpContext)
|
2012-09-18 23:51:33 +04:00
|
|
|
{
|
2014-08-18 19:22:22 +04:00
|
|
|
WLog_ERR(TAG, "not implemented");
|
2014-07-24 23:07:44 +04:00
|
|
|
return FALSE;
|
2012-09-18 23:51:33 +04:00
|
|
|
}
|
|
|
|
|
2016-06-16 12:47:33 +03:00
|
|
|
VOID winpr_InitOnceInitialize(PINIT_ONCE InitOnce)
|
2012-09-18 23:51:33 +04:00
|
|
|
{
|
2014-08-18 19:22:22 +04:00
|
|
|
WLog_ERR(TAG, "not implemented");
|
2012-09-18 23:51:33 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL winpr_InitOnceExecuteOnce(PINIT_ONCE InitOnce, PINIT_ONCE_FN InitFn, PVOID Parameter,
|
|
|
|
LPVOID* Context)
|
2012-09-18 23:51:33 +04:00
|
|
|
{
|
2014-07-24 23:07:44 +04:00
|
|
|
for (;;)
|
|
|
|
{
|
2014-08-18 19:22:22 +04:00
|
|
|
switch ((ULONG_PTR)InitOnce->Ptr & 3)
|
2014-07-24 23:07:44 +04:00
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
/* already completed successfully */
|
|
|
|
return TRUE;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2014-07-24 23:07:44 +04:00
|
|
|
case 0:
|
2014-08-18 19:22:22 +04:00
|
|
|
|
2014-07-24 23:07:44 +04:00
|
|
|
/* first time */
|
2019-11-06 17:24:51 +03:00
|
|
|
if (InterlockedCompareExchangePointer(&InitOnce->Ptr, (PVOID)1, (PVOID)0) !=
|
|
|
|
(PVOID)0)
|
2014-07-24 23:07:44 +04:00
|
|
|
{
|
|
|
|
/* some other thread was faster */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* it's our job to call the init function */
|
|
|
|
if (InitFn(InitOnce, Parameter, Context))
|
|
|
|
{
|
|
|
|
/* success */
|
|
|
|
InitOnce->Ptr = (PVOID)2;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the init function returned an error, reset the status */
|
|
|
|
InitOnce->Ptr = (PVOID)0;
|
|
|
|
return FALSE;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2014-07-24 23:07:44 +04:00
|
|
|
case 1:
|
|
|
|
/* in progress */
|
|
|
|
break;
|
2014-08-18 20:57:08 +04:00
|
|
|
|
2014-07-24 23:07:44 +04:00
|
|
|
default:
|
2014-08-18 19:22:22 +04:00
|
|
|
WLog_ERR(TAG, "internal error");
|
2014-07-24 23:07:44 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2012-09-18 23:51:33 +04:00
|
|
|
|
2014-07-24 23:07:44 +04:00
|
|
|
Sleep(5);
|
|
|
|
}
|
2012-09-18 23:51:33 +04:00
|
|
|
}
|
2012-09-19 02:36:13 +04:00
|
|
|
|
|
|
|
#endif
|