Closed jkoritzinsky closed 8 years ago
Interesting. They changed the semaphore code this summer, and I didn't notice that. I'll post a question in the commit that changed that stuff.
Awesome! BTW here's where the typedefs are located: http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a01214_source.html
And here's where they set the semaphore in their code: https://github.com/robotpy/allwpilib/blob/master/wpilibc/wpilibC++Devices/src/DriverStation.cpp#L49
They don't have the issue with the type punning because they have access to the native_handle
method. We can emulate that if we are willing to try to P/Invoke C++ methods (which is possible, but it's a bit of a pain).
I would rather just ask them to change it if possible. Here's were I asked the question.
https://usfirst.collab.net/gerrit/#/c/1008/
Python is going to run into the same issue as well, and they have official commit access, so they should be able to get it changed.
I just checked the python code and you're right. I found the same problem over there. I'll notify them of the issue as well.
The reason it probably didn't get noticed is that before this summer initializeMultiWait returned a raw pthread_cond_t. And then they changed it when they moved away from raw pointers this summer. The code was changed to allow windows builds of the HAL (which haven't been implemented yet), but I'm thinking this was thought to not be a big deal. And unless the py guys dug as deep as you did, they might not have noticed the change.
The multiwait thing used to be a terribly broken stupid hack thing. Hopefully they fixed it when migrating to semaphores.
Well as of right now they broke it more it looks like, but it can be fixed with a fairly easy change. Having no way to get a NATIVE_MULTIWAIT_ID without C++ code is an issue, but can be solved easily.
If you push a PR to our allwpilib repo, I'll forward it to gerrit. Though -- Thad, if you can comment on gerrit, you probably can push new reviews there.
I'll throw together a quick PR to the robotpy/allwpilib repo with the needed function.
I've tried multiple times, and I always get this error.
fatal: Upload denied for project 'allwpilib'
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Looking here https://usfirst.collab.net/sf/go/artf4148 it seems like even with gerrit comment access you need different permissions to push. I've asked multiple times but have never gotten a response from anyone at WPI.
Sent the pull request. Let me know if you need anything else.
@ThadHouse you can't push directly -- you have to use the git review -s
thing to upload as a review. Or something similar to that...
Fixed upstream
I was just looking through some of the code and I noticed something I thought was interesting/concerning with our Driver Station synchronization code. When we call
InitializeMultiWait
here, we get back a pointer to astd::condition_variable
from the HAL, which we see here (Note: in the corresponding header fileMULTIWAIT_ID
is typedefed tostd::condition_variable
here). When we callSetNewDataSem
here we send the pointer to thestd::condition_variable
that we just got back. However,setNewDataSem
(the C implementation), takes apthread_cond_t *
as a parameter (as seen here). These types don't match, so that's a little dangerous.However, it currently works because the first member (which is at the address of the full object) of a
std::condition_variable
in libstdc++ (the C++ standard library that is used on the roboRIO) happens to be apthread_cond_t
, which can be seen on lines 64-74 here. Also note that__gthread_cond_t
is defined to be apthread_cond_t
in a different file.Do we want to do anything about this? It probably won't be an issue at all, but it's something I just wanted to put out there.