// Copyright 2014 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

#include "media/base/closure_thread.h"

namespace media {

ClosureThread::ClosureThread(
    const std::string& name_prefix,
    const base::Closure& task)
    : base::SimpleThread(name_prefix), task_(task) {}

ClosureThread::~ClosureThread() {
  if (!HasBeenJoined())
    Join();
}

void ClosureThread::Run() { task_.Run(); }

}  // namespace media

// Copyright 2014 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

#include "media/base/closure_thread.h"

namespace media {

ClosureThread::ClosureThread(
    const std::string& name_prefix,
    const base::Closure& task)
    : base::SimpleThread(name_prefix), task_(task) {}

ClosureThread::~ClosureThread() {
  if (HasBeenStarted() && !HasBeenJoined())
    Join();
}

void ClosureThread::Run() { task_.Run(); }

}  // namespace media

Fix ClosureThread unittest crash in release build
Fix ClosureThread unittest crash in release build

The crash happens if the thread is created but never started. An
improper Join triggered the crash. We should not call Join if the thread
is not started.

Change-Id: Icace740889089d3b2e15cf6c76c2b0887eb84535
