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-07-24 23:07:44 +04:00
|
|
|
#if (!defined(_WIN32)) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600))
|
2012-09-19 02:36:13 +04:00
|
|
|
|
2012-09-18 23:51:33 +04:00
|
|
|
BOOL InitOnceBeginInitialize(LPINIT_ONCE lpInitOnce, DWORD dwFlags, PBOOL fPending, LPVOID* lpContext)
|
|
|
|
{
|
2014-07-24 23:07:44 +04:00
|
|
|
fprintf(stderr, "%s: not implemented\n", __FUNCTION__);
|
|
|
|
return FALSE;
|
2012-09-18 23:51:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL InitOnceComplete(LPINIT_ONCE lpInitOnce, DWORD dwFlags, LPVOID lpContext)
|
|
|
|
{
|
2014-07-24 23:07:44 +04:00
|
|
|
fprintf(stderr, "%s: not implemented\n", __FUNCTION__);
|
|
|
|
return FALSE;
|
2012-09-18 23:51:33 +04:00
|
|
|
}
|
|
|
|
|
2014-07-24 23:07:44 +04:00
|
|
|
VOID InitOnceInitialize(PINIT_ONCE InitOnce)
|
2012-09-18 23:51:33 +04:00
|
|
|
{
|
2014-07-24 23:07:44 +04:00
|
|
|
fprintf(stderr, "%s: not implemented\n", __FUNCTION__);
|
2012-09-18 23:51:33 +04:00
|
|
|
}
|
|
|
|
|
2014-07-24 23:07:44 +04:00
|
|
|
BOOL 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 (;;)
|
|
|
|
{
|
|
|
|
switch((ULONG_PTR)InitOnce->Ptr & 3)
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
/* already completed successfully */
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
/* first time */
|
|
|
|
if (InterlockedCompareExchangePointer(&InitOnce->Ptr, (PVOID)1, (PVOID)0) != (PVOID)0)
|
|
|
|
{
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
/* in progress */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s: internal error\n", __FUNCTION__);
|
|
|
|
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
|