cromo: Fix race condition on gobi sdk callbacks

gobi_modem.cc registers a bunch of callbacks through the Gobi SDK during
GobiModem::ApiConnect. These callbacks are unregistered during
GobiModem::ApiDisconnect. Although the GobiModem destructor calls
ApiDisconnect, there is a race condition between some of the threads
that process the callbacks and the GobiModem deallocation which causes the
callbacks to get called on garbage, causing invalid reads and writes.

This CL addresses this issue in two ways:

 - Added a flag that gets set to true by the GobiModem destructor that
   prevents any new callbacks from getting registered once the modem is
   set for deletion. This flag is mutex protected.

 - The GobiModem handler now explicitly removes all callbacks related to
   the GobiModem instance (via glib) and adds an idle callback that
   deletes GobiModem only after all sdk callbacks are scheduled to be
   deleted by glib.

BUG=chromium-os:35064
TEST=Ran custom script that runs suspend_stress_test and runs cromo via
valgrind repeatedly and logs valgrind output when valgrind exits. Ran
this script over the weekend. No invalid accesses occurred.

Change-Id: I34d8dcf7bacd62947b64c656e0d9e2343b080ffc
Reviewed-on: https://gerrit.chromium.org/gerrit/34898
Commit-Ready: Arman Uguray <armansito@chromium.org>
Reviewed-by: Arman Uguray <armansito@chromium.org>
Tested-by: Arman Uguray <armansito@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/35713
Reviewed-by: Ben Chan <benchan@chromium.org>
5 files changed