mariadb/mysys/my_wincond.c
Vladislav Vaintroub 3d6eb7afcf MDEV-25602 get rid of __WIN__ in favor of standard _WIN32
This fixed the MySQL bug# 20338 about misuse of double underscore
prefix __WIN__, which was old MySQL's idea of identifying Windows
Replace it by _WIN32 standard symbol for targeting Windows OS
(both 32 and 64 bit)

Not that connect storage engine is not fixed in this patch (must be
fixed in "upstream" branch)
2021-06-06 13:21:03 +02:00

114 lines
2.7 KiB
C

/* Copyright (c) 2000, 2014, Oracle and/or its affiliates.
Copyright (c) 2011, 2016, MariaDB
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; version 2 of the License.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
/*****************************************************************************
** The following is a simple implementation of posix conditions
*****************************************************************************/
#if defined(_WIN32)
#undef SAFE_MUTEX /* Avoid safe_mutex redefinitions */
#include "mysys_priv.h"
#include <m_string.h>
#include <process.h>
#include <sys/timeb.h>
/**
Convert abstime to milliseconds
*/
static DWORD get_milliseconds(const struct timespec *abstime)
{
struct timespec current_time;
long long ms;
if (abstime == NULL)
return INFINITE;
set_timespec_nsec(current_time, 0);
ms= (abstime->tv_sec - current_time.tv_sec)*1000LL +
(abstime->tv_nsec - current_time.tv_nsec)/1000000LL;
if(ms < 0 )
ms= 0;
if(ms > UINT_MAX)
ms= INFINITE;
return (DWORD)ms;
}
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
{
InitializeConditionVariable(cond);
return 0;
}
int pthread_cond_destroy(pthread_cond_t *cond)
{
return 0;
}
int pthread_cond_broadcast(pthread_cond_t *cond)
{
WakeAllConditionVariable(cond);
return 0;
}
int pthread_cond_signal(pthread_cond_t *cond)
{
WakeConditionVariable(cond);
return 0;
}
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
const struct timespec *abstime)
{
DWORD timeout= get_milliseconds(abstime);
if (!SleepConditionVariableCS(cond, mutex, timeout))
return ETIMEDOUT;
return 0;
}
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{
return pthread_cond_timedwait(cond, mutex, NULL);
}
int pthread_attr_init(pthread_attr_t *connect_att)
{
connect_att->dwStackSize = 0;
connect_att->dwCreatingFlag = 0;
return 0;
}
int pthread_attr_setstacksize(pthread_attr_t *connect_att,size_t stack)
{
DBUG_ASSERT(stack < UINT_MAX);
connect_att->dwStackSize=(DWORD)stack;
return 0;
}
int pthread_attr_destroy(pthread_attr_t *connect_att)
{
bzero((uchar*) connect_att,sizeof(*connect_att));
return 0;
}
#endif /* _WIN32 */