TaskRunner starts the background thread only when needed

Test: libhidl_test
Test: hidl_test
Test: boots
Change-Id: I5b6de5cd4a475b0653102e8004953ba008288ab1
diff --git a/base/include/hidl/TaskRunner.h b/base/include/hidl/TaskRunner.h
index b6e9a95..8ecceca 100644
--- a/base/include/hidl/TaskRunner.h
+++ b/base/include/hidl/TaskRunner.h
@@ -32,7 +32,7 @@
 public:
     using Task = std::function<void(void)>;
 
-    /* Kicks off the loop immediately. */
+    /* Create an empty task runner. Nothing will be done until start() is called. */
     TaskRunner();
 
     /*
@@ -43,19 +43,19 @@
     ~TaskRunner();
 
     /*
+     * Sets the queue limit. Fails the push operation once the limit is reached.
+     * Then kicks off the loop.
+     */
+    void start(size_t limit);
+
+    /*
      * Add a task. Return true if successful, false if
      * the queue's size exceeds limit or t doesn't contain a callable target.
      */
     inline bool push(const Task &t) {
-        return (!!t) && this->mQueue->push(t);
+        return (mQueue != nullptr) && (!!t) && this->mQueue->push(t);
     }
 
-    /*
-     * Sets the queue limit. Fails the push operation once the limit is reached.
-     */
-    inline void setLimit(size_t limit) {
-        this->mQueue->setLimit(limit);
-    }
 private:
     std::shared_ptr<SynchronizedQueue<Task>> mQueue;
 };