13
13
14
14
15
15
#define MAX_MEMBER_COUNT ( static_cast <uint32_t >( 0xffff ) )
16
- #define SLOT_COUNT_MASK ( static_cast <uint32_t >( 0xffff ) )
17
- #define FLAGS_MASK ( static_cast <uint32_t >( 0xffff0000 ) )
18
- #define NOTIFICATION_BIT ( static_cast <uint32_t >( 1 << 16 ) )
19
- #define GUARD_BIT ( static_cast <uint32_t >( 1 << 17 ) )
20
- #define ATOMREF_BIT ( static_cast <uint32_t >( 1 << 18 ) )
21
- #define FROZEN_BIT ( static_cast <uint32_t >( 1 << 19 ) )
22
16
#define catom_cast ( o ) ( reinterpret_cast <atom::CAtom*>( o ) )
23
17
24
18
25
19
namespace atom
26
20
{
27
21
28
-
22
+ PACK (struct CAtomInfo {
23
+ uint16_t slot_count;
24
+ bool notifications_enabled: 1 ;
25
+ bool has_guards: 1 ;
26
+ bool has_atomref: 1 ;
27
+ bool is_frozen: 1 ;
28
+ uint16_t reserved: 12 ;
29
+ });
29
30
30
31
struct CAtom
31
32
{
32
33
PyObject_HEAD
33
- uint32_t bitfield; // lower 16 == slot count, upper 16 == flags
34
34
PyObject** slots;
35
35
ObserverPool* observers;
36
+ CAtomInfo info;
36
37
37
38
static PyType_Spec TypeObject_Spec;
38
39
@@ -42,12 +43,12 @@ struct CAtom
42
43
43
44
uint32_t get_slot_count ()
44
45
{
45
- return bitfield & SLOT_COUNT_MASK ;
46
+ return info. slot_count ;
46
47
}
47
48
48
- void set_slot_count ( uint32_t count )
49
+ void set_slot_count ( uint16_t count )
49
50
{
50
- bitfield = ( bitfield & FLAGS_MASK ) | ( count & SLOT_COUNT_MASK ) ;
51
+ info. slot_count = count;
51
52
}
52
53
53
54
PyObject* get_slot ( uint32_t index )
@@ -65,41 +66,32 @@ struct CAtom
65
66
66
67
bool get_notifications_enabled ()
67
68
{
68
- return ( bitfield & NOTIFICATION_BIT ) != 0 ;
69
+ return info. notifications_enabled ;
69
70
}
70
71
71
72
void set_notifications_enabled ( bool enabled )
72
73
{
73
- if ( enabled )
74
- bitfield |= NOTIFICATION_BIT;
75
- else
76
- bitfield &= ~NOTIFICATION_BIT;
74
+ info.notifications_enabled = enabled;
77
75
}
78
76
79
77
bool has_guards ()
80
78
{
81
- return ( bitfield & GUARD_BIT ) != 0 ;
79
+ return info. has_guards ;
82
80
}
83
81
84
82
void set_has_guards ( bool has_guards )
85
83
{
86
- if ( has_guards )
87
- bitfield |= GUARD_BIT;
88
- else
89
- bitfield &= ~GUARD_BIT;
84
+ info.has_guards = has_guards;
90
85
}
91
86
92
87
bool has_atomref ()
93
88
{
94
- return ( bitfield & ATOMREF_BIT ) != 0 ;
89
+ return info. has_atomref ;
95
90
}
96
91
97
92
void set_has_atomref ( bool has_ref )
98
93
{
99
- if ( has_ref )
100
- bitfield |= ATOMREF_BIT;
101
- else
102
- bitfield &= ~ATOMREF_BIT;
94
+ info.has_atomref = has_ref;
103
95
}
104
96
105
97
bool has_observers ( PyObject* topic )
@@ -125,15 +117,12 @@ struct CAtom
125
117
126
118
bool is_frozen ()
127
119
{
128
- return ( bitfield & FROZEN_BIT ) != 0 ;
120
+ return info. is_frozen ;
129
121
}
130
122
131
123
void set_frozen ( bool frozen )
132
124
{
133
- if ( frozen )
134
- bitfield |= FROZEN_BIT;
135
- else
136
- bitfield &= ~FROZEN_BIT;
125
+ info.is_frozen = frozen;
137
126
}
138
127
139
128
bool observe ( PyObject* topic, PyObject* callback )
0 commit comments