-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Address warnings related to casting of void* to 64 #401
Conversation
This looks problematic to me. I think that the index field in reaction_t needs to be 64 bits regardless of the platform. The low-order 16 bits of this field are the level, and the remaining bits are the deadline. If we limit this field to 32 bits, then the deadline can only be 16 bits, which means that no deadline can be longer than 2^16 ns, or about 65us. If I'm understanding correctly, with these changes, the following function will return a 32-bit number on a 32-bit platform:
Note that if a deadline is given that is bigger than 2^16, then I think it will wrap around, which could lead to errors in reaction ordering. With the index being 64 bits, deadlines are limited to about one hour, I think (2^48 ns). A better alternative might be to change the reaction queue is a manner similar to what @byeonggiljun is doing for the event queue, where a priority is always a pointer and comparison functions are provided to compare reactions. This could eliminate the use of the index altogether and use the inferred deadline first for ordering and then the level when the inferred deadline is the same. This would also simplify the code. |
The index field of |
Yes, updating the
If you look for |
Thanks for the explanation, I think the effort from @byeonggiljun makes sense here. But what is still puzzling to me is why we would want to cast a pointer to a reaction struct into a |
No, I don't think we ever want to directly compare pointers. When the priority is a pointer, the |
Thanks for the information. It is clear that I need to take a close look at how the pqueue is used before making any changes. I will coordinate with @byeonggiljun if necessary. I am marking this PR as a draft, and I will come back to it. |
In this PR I address compiler warnings for our 32bit targets due to a casting from a
void*
to auint64_t
found in the pqueue implementation. It is discussed in #388.I define the
pqueue_pri_t
to be auintptr_t
which is the safe way of interpreting a pointer as an integer. It will be 64 or 32 bit, depending on architecture. Since we still want the reaction index to be 64bit, I no longer use thepqueue_pri_t
as the type of this field.I dont fully understand the relationship between the pointers on the pqueue and the reaction-indices. It seems wierd that we should cast the pointers of the pqueue elements to integers in the first place.