Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
00f2df49
Kaydet (Commit)
00f2df49
authored
Ock 09, 2009
tarafından
Kristján Valur Jónsson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 3582. Improved thread support and TLS for Windows
üst
d89f5b20
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
65 deletions
+91
-65
thread_nt.h
Python/thread_nt.h
+91
-65
No files found.
Python/thread_nt.h
Dosyayı görüntüle @
00f2df49
...
@@ -104,20 +104,16 @@ PyThread__init_thread(void)
...
@@ -104,20 +104,16 @@ PyThread__init_thread(void)
typedef
struct
{
typedef
struct
{
void
(
*
func
)(
void
*
);
void
(
*
func
)(
void
*
);
void
*
arg
;
void
*
arg
;
long
id
;
HANDLE
done
;
}
callobj
;
}
callobj
;
static
int
/* thunker to call a __cdecl function instead of a __stdcall */
static
unsigned
__stdcall
bootstrap
(
void
*
call
)
bootstrap
(
void
*
call
)
{
{
callobj
*
obj
=
(
callobj
*
)
call
;
callobj
*
obj
=
(
callobj
*
)
call
;
/* copy callobj since other thread might free it before we're done */
void
(
*
func
)(
void
*
)
=
obj
->
func
;
void
(
*
func
)(
void
*
)
=
obj
->
func
;
void
*
arg
=
obj
->
arg
;
void
*
arg
=
obj
->
arg
;
HeapFree
(
GetProcessHeap
(),
0
,
obj
);
obj
->
id
=
PyThread_get_thread_ident
();
ReleaseSemaphore
(
obj
->
done
,
1
,
NULL
);
func
(
arg
);
func
(
arg
);
return
0
;
return
0
;
}
}
...
@@ -125,42 +121,41 @@ bootstrap(void *call)
...
@@ -125,42 +121,41 @@ bootstrap(void *call)
long
long
PyThread_start_new_thread
(
void
(
*
func
)(
void
*
),
void
*
arg
)
PyThread_start_new_thread
(
void
(
*
func
)(
void
*
),
void
*
arg
)
{
{
Py_uintptr_t
rv
;
HANDLE
hThread
;
callobj
obj
;
unsigned
threadID
;
callobj
*
obj
;
dprintf
((
"%ld: PyThread_start_new_thread called
\n
"
,
dprintf
((
"%ld: PyThread_start_new_thread called
\n
"
,
PyThread_get_thread_ident
()));
PyThread_get_thread_ident
()));
if
(
!
initialized
)
if
(
!
initialized
)
PyThread_init_thread
();
PyThread_init_thread
();
obj
.
id
=
-
1
;
/* guilty until proved innocent */
obj
=
(
callobj
*
)
HeapAlloc
(
GetProcessHeap
(),
0
,
sizeof
(
*
obj
));
obj
.
func
=
func
;
if
(
!
obj
)
obj
.
arg
=
arg
;
obj
.
done
=
CreateSemaphore
(
NULL
,
0
,
1
,
NULL
);
if
(
obj
.
done
==
NULL
)
return
-
1
;
return
-
1
;
obj
->
func
=
func
;
rv
=
_beginthread
(
bootstrap
,
obj
->
arg
=
arg
;
hThread
=
(
HANDLE
)
_beginthreadex
(
0
,
Py_SAFE_DOWNCAST
(
_pythread_stacksize
,
Py_SAFE_DOWNCAST
(
_pythread_stacksize
,
Py_ssize_t
,
int
),
Py_ssize_t
,
unsigned
int
),
&
obj
);
bootstrap
,
obj
,
if
(
rv
==
(
Py_uintptr_t
)
-
1
)
{
0
,
&
threadID
);
if
(
hThread
==
0
)
{
/* I've seen errno == EAGAIN here, which means "there are
/* I've seen errno == EAGAIN here, which means "there are
* too many threads".
* too many threads".
*/
*/
dprintf
((
"%ld: PyThread_start_new_thread failed: %p errno %d
\n
"
,
dprintf
((
"%ld: PyThread_start_new_thread failed, errno %d
\n
"
,
PyThread_get_thread_ident
(),
(
void
*
)
rv
,
errno
));
PyThread_get_thread_ident
(),
errno
));
obj
.
id
=
-
1
;
threadID
=
(
unsigned
)
-
1
;
HeapFree
(
GetProcessHeap
(),
0
,
obj
);
}
}
else
{
else
{
dprintf
((
"%ld: PyThread_start_new_thread succeeded: %p
\n
"
,
dprintf
((
"%ld: PyThread_start_new_thread succeeded: %p
\n
"
,
PyThread_get_thread_ident
(),
(
void
*
)
rv
));
PyThread_get_thread_ident
(),
(
void
*
)
hThread
));
/* wait for thread to initialize, so we can get its id */
/* wait for thread to initialize, so we can get its id */
WaitForSingleObject
(
obj
.
done
,
INFINITE
);
CloseHandle
(
hThread
);
assert
(
obj
.
id
!=
-
1
);
}
}
CloseHandle
((
HANDLE
)
obj
.
done
);
return
(
long
)
threadID
;
return
obj
.
id
;
}
}
/*
/*
...
@@ -176,52 +171,22 @@ PyThread_get_thread_ident(void)
...
@@ -176,52 +171,22 @@ PyThread_get_thread_ident(void)
return
GetCurrentThreadId
();
return
GetCurrentThreadId
();
}
}
static
void
do_PyThread_exit_thread
(
int
no_cleanup
)
{
dprintf
((
"%ld: PyThread_exit_thread called
\n
"
,
PyThread_get_thread_ident
()));
if
(
!
initialized
)
if
(
no_cleanup
)
_exit
(
0
);
else
exit
(
0
);
_endthread
();
}
void
void
PyThread_exit_thread
(
void
)
PyThread_exit_thread
(
void
)
{
{
do_PyThread_exit_thread
(
0
);
dprintf
((
"%ld: PyThread_exit_thread called
\n
"
,
PyThread_get_thread_ident
()));
}
void
PyThread__exit_thread
(
void
)
{
do_PyThread_exit_thread
(
1
);
}
#ifndef NO_EXIT_PROG
static
void
do_PyThread_exit_prog
(
int
status
,
int
no_cleanup
)
{
dprintf
((
"PyThread_exit_prog(%d) called
\n
"
,
status
));
if
(
!
initialized
)
if
(
!
initialized
)
if
(
no_cleanup
)
exit
(
0
);
_exit
(
status
);
_endthreadex
(
0
);
else
exit
(
status
);
}
}
#ifndef NO_EXIT_PROG
void
void
PyThread_exit_prog
(
int
status
)
PyThread_exit_prog
(
int
status
)
{
{
do_PyThread_exit_prog
(
status
,
0
);
dprintf
((
"PyThread_exit_prog(%d) called
\n
"
,
status
));
}
if
(
!
initialized
)
exit
(
status
);
void
PyThread__exit_prog
(
int
status
)
{
do_PyThread_exit_prog
(
status
,
1
);
}
}
#endif
/* NO_EXIT_PROG */
#endif
/* NO_EXIT_PROG */
...
@@ -309,3 +274,64 @@ _pythread_nt_set_stacksize(size_t size)
...
@@ -309,3 +274,64 @@ _pythread_nt_set_stacksize(size_t size)
}
}
#define THREAD_SET_STACKSIZE(x) _pythread_nt_set_stacksize(x)
#define THREAD_SET_STACKSIZE(x) _pythread_nt_set_stacksize(x)
/* use native Windows TLS functions */
#define Py_HAVE_NATIVE_TLS
#ifdef Py_HAVE_NATIVE_TLS
int
PyThread_create_key
(
void
)
{
return
(
int
)
TlsAlloc
();
}
void
PyThread_delete_key
(
int
key
)
{
TlsFree
(
key
);
}
/* We must be careful to emulate the strange semantics implemented in thread.c,
* where the value is only set if it hasn't been set before.
*/
int
PyThread_set_key_value
(
int
key
,
void
*
value
)
{
BOOL
ok
;
void
*
oldvalue
;
assert
(
value
!=
NULL
);
oldvalue
=
TlsGetValue
(
key
);
if
(
oldvalue
!=
NULL
)
/* ignore value if already set */
return
0
;
ok
=
TlsSetValue
(
key
,
value
);
if
(
!
ok
)
return
-
1
;
return
0
;
}
void
*
PyThread_get_key_value
(
int
key
)
{
return
TlsGetValue
(
key
);
}
void
PyThread_delete_key_value
(
int
key
)
{
/* NULL is used as "key missing", and it is also the default
* given by TlsGetValue() if nothing has been set yet.
*/
TlsSetValue
(
key
,
NULL
);
}
/* reinitialization of TLS is not necessary after fork when using
* the native TLS functions. And forking isn't supported on Windows either.
*/
void
PyThread_ReInitTLS
(
void
)
{}
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment