Commit d5b2c3f2 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Lock _MB_CP_LOCK lock in setmbcp.

parent 4fc2b729
......@@ -599,18 +599,14 @@ MSVCRT_pthreadlocinfo CDECL get_locinfo(void) {
return *get_locinfo_ptr();
}
MSVCRT_pthreadmbcinfo* CDECL get_mbcinfo_ptr(void) {
/* INTERNAL: returns pthreadmbcinfo struct */
MSVCRT_pthreadmbcinfo CDECL get_mbcinfo(void) {
thread_data_t *data = msvcrt_get_thread_data();
if(!data || !(data->locale_flags & LOCALE_THREAD))
return &MSVCRT_locale->mbcinfo;
return &data->mbcinfo;
}
return MSVCRT_locale->mbcinfo;
/* INTERNAL: returns pthreadmbcinfo struct */
MSVCRT_pthreadmbcinfo CDECL get_mbcinfo(void) {
return *get_mbcinfo_ptr();
return data->mbcinfo;
}
/* INTERNAL: constructs string returned by setlocale */
......
......@@ -28,6 +28,7 @@
#include <mbctype.h>
#include "msvcrt.h"
#include "mtdll.h"
#include "winnls.h"
#include "wine/debug.h"
......@@ -209,9 +210,6 @@ int CDECL ___mb_cur_max_l_func(MSVCRT__locale_t locale)
}
#endif
/*********************************************************************
* INTERNAL: _setmbcp_l
*/
MSVCRT_threadmbcinfo* create_mbcinfo(int cp, LCID lcid, MSVCRT_threadmbcinfo *old_mbcinfo)
{
MSVCRT_threadmbcinfo *mbcinfo;
......@@ -386,20 +384,30 @@ MSVCRT_threadmbcinfo* create_mbcinfo(int cp, LCID lcid, MSVCRT_threadmbcinfo *ol
*/
int CDECL _setmbcp(int cp)
{
MSVCRT_threadmbcinfo **old_mbcinfo = get_mbcinfo_ptr();
thread_data_t *data = msvcrt_get_thread_data();
MSVCRT_threadmbcinfo *mbcinfo;
mbcinfo = create_mbcinfo(cp, -1, *old_mbcinfo);
if(!mbcinfo) {
mbcinfo = create_mbcinfo(cp, -1, get_mbcinfo());
if(!mbcinfo)
{
*MSVCRT__errno() = MSVCRT_EINVAL;
return -1;
}
free_mbcinfo(*old_mbcinfo);
*old_mbcinfo = mbcinfo;
if(mbcinfo == MSVCRT_locale->mbcinfo)
if(data->locale_flags & LOCALE_THREAD)
{
if(data->locale_flags & LOCALE_FREE)
free_mbcinfo(data->mbcinfo);
data->mbcinfo = mbcinfo;
}
else
{
_lock(_MB_CP_LOCK);
free_mbcinfo(MSVCRT_locale->mbcinfo);
MSVCRT_locale->mbcinfo = mbcinfo;
memcpy(MSVCRT_mbctype, MSVCRT_locale->mbcinfo->mbctype, sizeof(MSVCRT_mbctype));
_unlock(_MB_CP_LOCK);
}
return 0;
}
......
......@@ -1008,7 +1008,6 @@ MSVCRT__locale_t CDECL get_current_locale_noalloc(MSVCRT__locale_t locale) DECLS
void CDECL free_locale_noalloc(MSVCRT__locale_t locale) DECLSPEC_HIDDEN;
MSVCRT_pthreadlocinfo CDECL get_locinfo(void) DECLSPEC_HIDDEN;
MSVCRT_pthreadmbcinfo CDECL get_mbcinfo(void) DECLSPEC_HIDDEN;
MSVCRT_pthreadmbcinfo* CDECL get_mbcinfo_ptr(void) DECLSPEC_HIDDEN;
void __cdecl MSVCRT__free_locale(MSVCRT__locale_t);
MSVCRT_threadmbcinfo* create_mbcinfo(int, LCID, MSVCRT_threadmbcinfo*) DECLSPEC_HIDDEN;
void free_locinfo(MSVCRT_pthreadlocinfo) DECLSPEC_HIDDEN;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment