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
19717fa3
Kaydet (Commit)
19717fa3
authored
Eki 09, 2004
tarafından
Tim Peters
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Style guide & consistency changes. No semantic changes.
üst
4c1f5ecf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
29 deletions
+41
-29
pystate.c
Python/pystate.c
+29
-23
thread.c
Python/thread.c
+12
-6
No files found.
Python/pystate.c
Dosyayı görüntüle @
19717fa3
...
...
@@ -388,18 +388,20 @@ static int autoTLSkey = 0;
/* Internal initialization/finalization functions called by
Py_Initialize/Py_Finalize
*/
void
_PyGILState_Init
(
PyInterpreterState
*
i
,
PyThreadState
*
t
)
void
_PyGILState_Init
(
PyInterpreterState
*
i
,
PyThreadState
*
t
)
{
assert
(
i
&&
t
);
/* must init with
a
valid states */
assert
(
i
&&
t
);
/* must init with valid states */
autoTLSkey
=
PyThread_create_key
();
autoInterpreterState
=
i
;
/* Now stash the thread state for this thread in TLS */
PyThread_set_key_value
(
autoTLSkey
,
(
void
*
)
t
);
assert
(
t
->
gilstate_counter
==
0
);
/* must be a new thread state */
assert
(
t
->
gilstate_counter
==
0
);
/* must be a new thread state */
t
->
gilstate_counter
=
1
;
}
void
_PyGILState_Fini
(
void
)
void
_PyGILState_Fini
(
void
)
{
PyThread_delete_key
(
autoTLSkey
);
autoTLSkey
=
0
;
...
...
@@ -407,14 +409,16 @@ void _PyGILState_Fini(void)
}
/* The public functions */
PyThreadState
*
PyGILState_GetThisThreadState
(
void
)
PyThreadState
*
PyGILState_GetThisThreadState
(
void
)
{
if
(
autoInterpreterState
==
NULL
||
autoTLSkey
==
0
)
if
(
autoInterpreterState
==
NULL
||
autoTLSkey
==
0
)
return
NULL
;
return
(
PyThreadState
*
)
PyThread_get_key_value
(
autoTLSkey
);
return
(
PyThreadState
*
)
PyThread_get_key_value
(
autoTLSkey
);
}
PyGILState_STATE
PyGILState_Ensure
(
void
)
PyGILState_STATE
PyGILState_Ensure
(
void
)
{
int
current
;
PyThreadState
*
tcur
;
...
...
@@ -425,30 +429,32 @@ PyGILState_STATE PyGILState_Ensure(void)
*/
assert
(
autoInterpreterState
);
/* Py_Initialize() hasn't been called! */
tcur
=
PyThread_get_key_value
(
autoTLSkey
);
if
(
tcur
==
NULL
)
{
if
(
tcur
==
NULL
)
{
/* Create a new thread state for this thread */
tcur
=
PyThreadState_New
(
autoInterpreterState
);
if
(
tcur
==
NULL
)
if
(
tcur
==
NULL
)
Py_FatalError
(
"Couldn't create thread-state for new thread"
);
PyThread_set_key_value
(
autoTLSkey
,
(
void
*
)
tcur
);
current
=
0
;
/* new thread state is never current */
}
else
}
else
current
=
PyThreadState_IsCurrent
(
tcur
);
if
(
!
current
)
if
(
current
==
0
)
PyEval_RestoreThread
(
tcur
);
/* Update our counter in the thread-state - no need for locks:
- tcur will remain valid as we hold the GIL.
- the counter is safe as we are the only thread "allowed"
to modify this value
*/
tcur
->
gilstate_counter
++
;
++
tcur
->
gilstate_counter
;
return
current
?
PyGILState_LOCKED
:
PyGILState_UNLOCKED
;
}
void
PyGILState_Release
(
PyGILState_STATE
oldstate
)
void
PyGILState_Release
(
PyGILState_STATE
oldstate
)
{
PyThreadState
*
tcur
=
PyThread_get_key_value
(
autoTLSkey
);
if
(
tcur
==
NULL
)
if
(
tcur
==
NULL
)
Py_FatalError
(
"auto-releasing thread-state, "
"but no thread-state for this thread"
);
/* We must hold the GIL and have our thread state current */
...
...
@@ -456,27 +462,27 @@ void PyGILState_Release(PyGILState_STATE oldstate)
but while this is very new (April 2003), the extra check
by release-only users can't hurt.
*/
if
(
!
PyThreadState_IsCurrent
(
tcur
))
if
(
!
PyThreadState_IsCurrent
(
tcur
))
Py_FatalError
(
"This thread state must be current when releasing"
);
assert
(
PyThreadState_IsCurrent
(
tcur
));
tcur
->
gilstate_counter
-=
1
;
assert
(
tcur
->
gilstate_counter
>=
0
);
/* illegal counter value */
assert
(
PyThreadState_IsCurrent
(
tcur
));
--
tcur
->
gilstate_counter
;
assert
(
tcur
->
gilstate_counter
>=
0
);
/* illegal counter value */
/* If we are about to destroy this thread-state, we must
clear it while the lock is held, as destructors may run
*/
if
(
tcur
->
gilstate_counter
==
0
)
{
if
(
tcur
->
gilstate_counter
==
0
)
{
/* can't have been locked when we created it */
assert
(
oldstate
==
PyGILState_UNLOCKED
);
assert
(
oldstate
==
PyGILState_UNLOCKED
);
PyThreadState_Clear
(
tcur
);
}
/* Release the lock if necessary */
if
(
oldstate
==
PyGILState_UNLOCKED
)
if
(
oldstate
==
PyGILState_UNLOCKED
)
PyEval_ReleaseThread
(
tcur
);
/* Now complete destruction of the thread if necessary */
if
(
tcur
->
gilstate_counter
==
0
)
{
if
(
tcur
->
gilstate_counter
==
0
)
{
/* Delete this thread from our TLS */
PyThread_delete_key_value
(
autoTLSkey
);
/* Delete the thread-state */
...
...
Python/thread.c
Dosyayı görüntüle @
19717fa3
...
...
@@ -157,7 +157,8 @@ static struct key *keyhead = NULL;
static
int
nkeys
=
0
;
static
PyThread_type_lock
keymutex
=
NULL
;
static
struct
key
*
find_key
(
int
key
,
void
*
value
)
static
struct
key
*
find_key
(
int
key
,
void
*
value
)
{
struct
key
*
p
;
long
id
=
PyThread_get_thread_ident
();
...
...
@@ -180,14 +181,16 @@ static struct key *find_key(int key, void *value)
return
p
;
}
int
PyThread_create_key
(
void
)
int
PyThread_create_key
(
void
)
{
if
(
keymutex
==
NULL
)
keymutex
=
PyThread_allocate_lock
();
return
++
nkeys
;
}
void
PyThread_delete_key
(
int
key
)
void
PyThread_delete_key
(
int
key
)
{
struct
key
*
p
,
**
q
;
PyThread_acquire_lock
(
keymutex
,
1
);
...
...
@@ -204,7 +207,8 @@ void PyThread_delete_key(int key)
PyThread_release_lock
(
keymutex
);
}
int
PyThread_set_key_value
(
int
key
,
void
*
value
)
int
PyThread_set_key_value
(
int
key
,
void
*
value
)
{
struct
key
*
p
=
find_key
(
key
,
value
);
if
(
p
==
NULL
)
...
...
@@ -213,7 +217,8 @@ int PyThread_set_key_value(int key, void *value)
return
0
;
}
void
*
PyThread_get_key_value
(
int
key
)
void
*
PyThread_get_key_value
(
int
key
)
{
struct
key
*
p
=
find_key
(
key
,
NULL
);
if
(
p
==
NULL
)
...
...
@@ -222,7 +227,8 @@ void *PyThread_get_key_value(int key)
return
p
->
value
;
}
void
PyThread_delete_key_value
(
int
key
)
void
PyThread_delete_key_value
(
int
key
)
{
long
id
=
PyThread_get_thread_ident
();
struct
key
*
p
,
**
q
;
...
...
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