forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
194 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#ifndef Py_INTERNAL_TYPEID_H | ||
#define Py_INTERNAL_TYPEID_H | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifndef Py_BUILD_CORE | ||
# error "this header requires Py_BUILD_CORE define" | ||
#endif | ||
|
||
#ifdef Py_GIL_DISABLED | ||
|
||
// This contains code for allocating unique ids for objects | ||
// and re-using those ids when the object is deallocated. | ||
// | ||
// The unique ids are used to implement per-thread reference counts of | ||
// heap types and code objects to avoid contention on the reference count | ||
// fields. Static type objects are immortal, so contention is not an issue for | ||
// those types. | ||
// | ||
// An id of -1 is used to indicate that the object doesn't use per-thread | ||
// refcounting. This value is used when a type object is finalized by the GC | ||
// and during interpreter shutdown to allow the type object to be | ||
// deallocated promptly when the object's refcount reaches zero. | ||
// | ||
// Each entry implicitly represents a unique id based on it's offset in the | ||
// table. Non-allocated entries form a free-list via the 'next' pointer. | ||
// Allocated entries store the corresponding PyObject. | ||
typedef union _Py_unique_id_entry { | ||
// Points to the next free type id, when part of the freelist | ||
union _Py_unique_id_entry *next; | ||
|
||
// Stores object when the id is assigned | ||
PyObject *object; | ||
} _Py_unique_id_entry; | ||
|
||
struct _Py_unique_id_pool { | ||
PyMutex mutex; | ||
|
||
// combined table of types with allocated type ids and unallocated | ||
// type ids. | ||
_Py_unique_id_entry *table; | ||
|
||
// Next entry to allocate inside 'table' or NULL | ||
_Py_unique_id_entry *freelist; | ||
|
||
// size of 'table' | ||
Py_ssize_t size; | ||
}; | ||
|
||
// Assigns the next id from the pool of type ids. | ||
extern Py_ssize_t _PyObject_AssignUniqueId(PyObject *obj); | ||
|
||
// Releases the allocated id back to the pool. | ||
extern void _PyObject_ReleaseUniqueId(Py_ssize_t id); | ||
|
||
// Merges the thread-local reference counts into the corresponding types. | ||
extern void _PyObject_MergeThreadLocalRefcounts(_PyThreadStateImpl *tstate); | ||
|
||
// Like _PyObject_MergeThreadLocalRefcounts, but also frees the thread-local | ||
// array of refcounts. | ||
extern void _PyObject_FinalizeThreadLocalRefcounts(_PyThreadStateImpl *tstate); | ||
|
||
// Frees the interpreter's pool of type ids. | ||
extern void _PyObject_FinalizeIdPool(PyInterpreterState *interp); | ||
|
||
// Increfs the object, resizing the thread-local refcount array if necessary. | ||
PyAPI_FUNC(void) _PyObject_ThreadIncrefSlow(PyObject *obj, Py_ssize_t unique_id); | ||
|
||
|
||
#endif /* Py_GIL_DISABLED */ | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif /* !Py_INTERNAL_TYPEID_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.