SFU-Embedded-Cosplay / Halo-Suit-BeagleBone

2 stars 0 forks source link

Refactor beagleblue_exit() and beagleblue_join() #8

Open HamiltonChris opened 9 years ago

HamiltonChris commented 9 years ago

I think that these two functions could be contained in one function since they should always be called together anyway. The functions beagleblue_exit() and beagleblue_join() are defined in /include/beagleblue/beagleblue.h and implemented in /beagleblue/beagleblue.c around lines 285 and 324. The function beagleblue_exit basically changes a boolean variable that all the threads share to notify them that they should stop running and then it calles beagleblue_join and then closes the four open sockets. The beagleblue_join function joins all the active pthreads in the beagleblue module. Since the beagleblue_join function is already contained inside the beagleblue_exit function I don't think it needs to be a public function and would simplify the interface if it was removed from the beagleblue.h . This would also mean removing the call to beagleblue_join in the main.c on line 77.

TODO:

- remove beagleblue_join declaration from beagleblue.h

- rename beagleblue_join in the implementation

- create a helper function that closes the open sockets

- replace the socket closing code in beagleblue_exit with the helper function

Note: The refactoring of the interface will affect the mockBluetooth implementation in issue #5 .

abrykajlo commented 9 years ago

I suggest making beagleblue_join an inline function instead. I intended it originally as a thread join function for all the threads. In case anybody else was to use my code. beagleblue_exit just happens to use it because it needs to wait for it to join after the bool is changed to being done. Beagleblue_join may still be useful for other purposes

HamiltonChris commented 9 years ago

Ok I see what you're saying but I'm not really clear on why it should be a inline function?

HamiltonChris commented 9 years ago

Information on inline functions can be found here.