1313
1414
1515#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 ) )
2216#define catom_cast ( o ) ( reinterpret_cast <atom::CAtom*>( o ) )
2317
2418
2519namespace atom
2620{
2721
28-
22+ PACK (struct CAtomMeta {
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+ });
2930
3031struct CAtom
3132{
3233 PyObject_HEAD
33- uint32_t bitfield; // lower 16 == slot count, upper 16 == flags
3434 PyObject** slots;
3535 ObserverPool* observers;
36+ CAtomMeta meta;
3637
3738 static PyType_Spec TypeObject_Spec;
3839
@@ -42,12 +43,12 @@ struct CAtom
4243
4344 uint32_t get_slot_count ()
4445 {
45- return bitfield & SLOT_COUNT_MASK ;
46+ return meta. slot_count ;
4647 }
4748
48- void set_slot_count ( uint32_t count )
49+ void set_slot_count ( uint16_t count )
4950 {
50- bitfield = ( bitfield & FLAGS_MASK ) | ( count & SLOT_COUNT_MASK ) ;
51+ meta. slot_count = count;
5152 }
5253
5354 PyObject* get_slot ( uint32_t index )
@@ -65,41 +66,32 @@ struct CAtom
6566
6667 bool get_notifications_enabled ()
6768 {
68- return ( bitfield & NOTIFICATION_BIT ) != 0 ;
69+ return meta. notifications_enabled ;
6970 }
7071
7172 void set_notifications_enabled ( bool enabled )
7273 {
73- if ( enabled )
74- bitfield |= NOTIFICATION_BIT;
75- else
76- bitfield &= ~NOTIFICATION_BIT;
74+ meta.notifications_enabled = enabled;
7775 }
7876
7977 bool has_guards ()
8078 {
81- return ( bitfield & GUARD_BIT ) != 0 ;
79+ return meta. has_guards ;
8280 }
8381
8482 void set_has_guards ( bool has_guards )
8583 {
86- if ( has_guards )
87- bitfield |= GUARD_BIT;
88- else
89- bitfield &= ~GUARD_BIT;
84+ meta.has_guards = has_guards;
9085 }
9186
9287 bool has_atomref ()
9388 {
94- return ( bitfield & ATOMREF_BIT ) != 0 ;
89+ return meta. has_atomref ;
9590 }
9691
9792 void set_has_atomref ( bool has_ref )
9893 {
99- if ( has_ref )
100- bitfield |= ATOMREF_BIT;
101- else
102- bitfield &= ~ATOMREF_BIT;
94+ meta.has_atomref = has_ref;
10395 }
10496
10597 bool has_observers ( PyObject* topic )
@@ -125,15 +117,12 @@ struct CAtom
125117
126118 bool is_frozen ()
127119 {
128- return ( bitfield & FROZEN_BIT ) != 0 ;
120+ return meta. is_frozen ;
129121 }
130122
131123 void set_frozen ( bool frozen )
132124 {
133- if ( frozen )
134- bitfield |= FROZEN_BIT;
135- else
136- bitfield &= ~FROZEN_BIT;
125+ meta.is_frozen = frozen;
137126 }
138127
139128 bool observe ( PyObject* topic, PyObject* callback )
0 commit comments