[ Web Proxy ]
URL:
Viewing:
https://github-redirect.dependabot.com/python/cpython/blob/main/Objects/mimalloc/bitmap.h
[Back]
[Original]
cpython/Objects/mimalloc/bitmap.h at main python/cpython GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
python
cpython
Repository navigation
Code
Issues
5k+
(5k+)
Pull requests
2.3k
(2.3k)
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
cpython
/
Objects
/
mimalloc
/
bitmap.h
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
119 lines (92 loc) 6.07 KB
main
Breadcrumbs
cpython
/
Objects
/
mimalloc
/
bitmap.h
Copy path
Top
File metadata and controls
Code
Blame
119 lines (92 loc) 6.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* ----------------------------------------------------------------------------
Copyright (c) 2019-2023 Microsoft Research, Daan Leijen
This is free software; you can redistribute it and/or modify it under the
terms of the MIT license. A copy of the license can be found in the file
"LICENSE" at the root of this distribution.
-----------------------------------------------------------------------------*/
/* ----------------------------------------------------------------------------
Concurrent bitmap that can set/reset sequences of bits atomically,
represented as an array of fields where each field is a machine word (`size_t`)
There are two api's; the standard one cannot have sequences that cross
between the bitmap fields (and a sequence must be <= MI_BITMAP_FIELD_BITS).
(this is used in region allocation)
The `_across` postfixed functions do allow sequences that can cross over
between the fields. (This is used in arena allocation)
---------------------------------------------------------------------------- */
#pragma
once
#ifndef
MI_BITMAP_H
#define
MI_BITMAP_H
/* -----------------------------------------------------------
Bitmap definition
----------------------------------------------------------- */
#define
MI_BITMAP_FIELD_BITS
(8*MI_SIZE_SIZE)
#define
MI_BITMAP_FIELD_FULL
(~((size_t)0)) // all bits set
// An atomic bitmap of `size_t` fields
typedef
_Atomic(
size_t
)
mi_bitmap_field_t
;
typedef
mi_bitmap_field_t
*
mi_bitmap_t
;
// A bitmap index is the index of the bit in a bitmap.
typedef
size_t
mi_bitmap_index_t
;
// Create a bit index.
static
inline
mi_bitmap_index_t
mi_bitmap_index_create_ex
(
size_t
idx
,
size_t
bitidx
) {
mi_assert_internal
(
bitidx
<=
MI_BITMAP_FIELD_BITS
);
return
(
idx
*
MI_BITMAP_FIELD_BITS
)
+
bitidx
;
}
static
inline
mi_bitmap_index_t
mi_bitmap_index_create
(
size_t
idx
,
size_t
bitidx
) {
mi_assert_internal
(
bitidx
<
MI_BITMAP_FIELD_BITS
);
return
mi_bitmap_index_create_ex
(
idx
,
bitidx
);
}
// Create a bit index.
static
inline
mi_bitmap_index_t
mi_bitmap_index_create_from_bit
(
size_t
full_bitidx
) {
return
mi_bitmap_index_create
(
full_bitidx
/
MI_BITMAP_FIELD_BITS
,
full_bitidx
%
MI_BITMAP_FIELD_BITS
);
}
// Get the field index from a bit index.
static
inline
size_t
mi_bitmap_index_field
(
mi_bitmap_index_t
bitmap_idx
) {
return
(
bitmap_idx
/
MI_BITMAP_FIELD_BITS
);
}
// Get the bit index in a bitmap field
static
inline
size_t
mi_bitmap_index_bit_in_field
(
mi_bitmap_index_t
bitmap_idx
) {
return
(
bitmap_idx
%
MI_BITMAP_FIELD_BITS
);
}
// Get the full bit index
static
inline
size_t
mi_bitmap_index_bit
(
mi_bitmap_index_t
bitmap_idx
) {
return
bitmap_idx
;
}
/* -----------------------------------------------------------
Claim a bit sequence atomically
----------------------------------------------------------- */
// Try to atomically claim a sequence of `count` bits in a single
// field at `idx` in `bitmap`. Returns `true` on success.
bool
_mi_bitmap_try_find_claim_field
(
mi_bitmap_t
bitmap
,
size_t
idx
,
const
size_t
count
,
mi_bitmap_index_t
*
bitmap_idx
);
// Starts at idx, and wraps around to search in all `bitmap_fields` fields.
// For now, `count` can be at most MI_BITMAP_FIELD_BITS and will never cross fields.
bool
_mi_bitmap_try_find_from_claim
(
mi_bitmap_t
bitmap
,
const
size_t
bitmap_fields
,
const
size_t
start_field_idx
,
const
size_t
count
,
mi_bitmap_index_t
*
bitmap_idx
);
// Like _mi_bitmap_try_find_from_claim but with an extra predicate that must be fullfilled
typedef
bool
(
mi_cdecl
*
mi_bitmap_pred_fun_t
)(
mi_bitmap_index_t
bitmap_idx
,
void
*
pred_arg
);
bool
_mi_bitmap_try_find_from_claim_pred
(
mi_bitmap_t
bitmap
,
const
size_t
bitmap_fields
,
const
size_t
start_field_idx
,
const
size_t
count
,
mi_bitmap_pred_fun_t
pred_fun
,
void
*
pred_arg
,
mi_bitmap_index_t
*
bitmap_idx
);
// Set `count` bits at `bitmap_idx` to 0 atomically
// Returns `true` if all `count` bits were 1 previously.
bool
_mi_bitmap_unclaim
(
mi_bitmap_t
bitmap
,
size_t
bitmap_fields
,
size_t
count
,
mi_bitmap_index_t
bitmap_idx
);
// Try to set `count` bits at `bitmap_idx` from 0 to 1 atomically.
// Returns `true` if successful when all previous `count` bits were 0.
bool
_mi_bitmap_try_claim
(
mi_bitmap_t
bitmap
,
size_t
bitmap_fields
,
size_t
count
,
mi_bitmap_index_t
bitmap_idx
);
// Set `count` bits at `bitmap_idx` to 1 atomically
// Returns `true` if all `count` bits were 0 previously. `any_zero` is `true` if there was at least one zero bit.
bool
_mi_bitmap_claim
(
mi_bitmap_t
bitmap
,
size_t
bitmap_fields
,
size_t
count
,
mi_bitmap_index_t
bitmap_idx
,
bool
*
any_zero
);
bool
_mi_bitmap_is_claimed
(
mi_bitmap_t
bitmap
,
size_t
bitmap_fields
,
size_t
count
,
mi_bitmap_index_t
bitmap_idx
);
bool
_mi_bitmap_is_any_claimed
(
mi_bitmap_t
bitmap
,
size_t
bitmap_fields
,
size_t
count
,
mi_bitmap_index_t
bitmap_idx
);
//--------------------------------------------------------------------------
// the `_across` functions work on bitmaps where sequences can cross over
// between the fields. This is used in arena allocation
//--------------------------------------------------------------------------
// Find `count` bits of zeros and set them to 1 atomically; returns `true` on success.
// Starts at idx, and wraps around to search in all `bitmap_fields` fields.
bool
_mi_bitmap_try_find_from_claim_across
(
mi_bitmap_t
bitmap
,
const
size_t
bitmap_fields
,
const
size_t
start_field_idx
,
const
size_t
count
,
mi_bitmap_index_t
*
bitmap_idx
);
// Set `count` bits at `bitmap_idx` to 0 atomically
// Returns `true` if all `count` bits were 1 previously.
bool
_mi_bitmap_unclaim_across
(
mi_bitmap_t
bitmap
,
size_t
bitmap_fields
,
size_t
count
,
mi_bitmap_index_t
bitmap_idx
);
// Set `count` bits at `bitmap_idx` to 1 atomically
// Returns `true` if all `count` bits were 0 previously. `any_zero` is `true` if there was at least one zero bit.
bool
_mi_bitmap_claim_across
(
mi_bitmap_t
bitmap
,
size_t
bitmap_fields
,
size_t
count
,
mi_bitmap_index_t
bitmap_idx
,
bool
*
pany_zero
,
size_t
*
already_set
);
bool
_mi_bitmap_is_claimed_across
(
mi_bitmap_t
bitmap
,
size_t
bitmap_fields
,
size_t
count
,
mi_bitmap_index_t
bitmap_idx
,
size_t
*
already_set
);
bool
_mi_bitmap_is_any_claimed_across
(
mi_bitmap_t
bitmap
,
size_t
bitmap_fields
,
size_t
count
,
mi_bitmap_index_t
bitmap_idx
);
#endif
Footer
© 2026 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Community
Docs
Contact
Manage cookies
Do not share my personal information
You cant perform that action at this time.
Web Proxy Viewer |
New URL
|
Original Page