代码拉取完成,页面将自动刷新
同步操作将从 百度开源/BRPC 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "butil/compiler_specific.h"
#include "butil/threading/platform_thread.h"
#include <gtest/gtest.h>
namespace butil {
// Trivial tests that thread runs and doesn't crash on create and join ---------
class TrivialThread : public PlatformThread::Delegate {
public:
TrivialThread() : did_run_(false) {}
virtual void ThreadMain() OVERRIDE {
did_run_ = true;
}
bool did_run() const { return did_run_; }
private:
bool did_run_;
DISALLOW_COPY_AND_ASSIGN(TrivialThread);
};
TEST(PlatformThreadTest, Trivial) {
TrivialThread thread;
PlatformThreadHandle handle;
ASSERT_FALSE(thread.did_run());
ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle));
PlatformThread::Join(handle);
ASSERT_TRUE(thread.did_run());
}
TEST(PlatformThreadTest, TrivialTimesTen) {
TrivialThread thread[10];
PlatformThreadHandle handle[arraysize(thread)];
for (size_t n = 0; n < arraysize(thread); n++)
ASSERT_FALSE(thread[n].did_run());
for (size_t n = 0; n < arraysize(thread); n++)
ASSERT_TRUE(PlatformThread::Create(0, &thread[n], &handle[n]));
for (size_t n = 0; n < arraysize(thread); n++)
PlatformThread::Join(handle[n]);
for (size_t n = 0; n < arraysize(thread); n++)
ASSERT_TRUE(thread[n].did_run());
}
// Tests of basic thread functions ---------------------------------------------
class FunctionTestThread : public TrivialThread {
public:
FunctionTestThread() : thread_id_(0) {}
virtual void ThreadMain() OVERRIDE {
thread_id_ = PlatformThread::CurrentId();
PlatformThread::YieldCurrentThread();
PlatformThread::Sleep(TimeDelta::FromMilliseconds(50));
// Make sure that the thread ID is the same across calls.
EXPECT_EQ(thread_id_, PlatformThread::CurrentId());
TrivialThread::ThreadMain();
}
PlatformThreadId thread_id() const { return thread_id_; }
private:
PlatformThreadId thread_id_;
DISALLOW_COPY_AND_ASSIGN(FunctionTestThread);
};
TEST(PlatformThreadTest, Function) {
PlatformThreadId main_thread_id = PlatformThread::CurrentId();
FunctionTestThread thread;
PlatformThreadHandle handle;
ASSERT_FALSE(thread.did_run());
ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle));
PlatformThread::Join(handle);
ASSERT_TRUE(thread.did_run());
EXPECT_NE(thread.thread_id(), main_thread_id);
// Make sure that the thread ID is the same across calls.
EXPECT_EQ(main_thread_id, PlatformThread::CurrentId());
}
TEST(PlatformThreadTest, FunctionTimesTen) {
PlatformThreadId main_thread_id = PlatformThread::CurrentId();
FunctionTestThread thread[10];
PlatformThreadHandle handle[arraysize(thread)];
for (size_t n = 0; n < arraysize(thread); n++)
ASSERT_FALSE(thread[n].did_run());
for (size_t n = 0; n < arraysize(thread); n++)
ASSERT_TRUE(PlatformThread::Create(0, &thread[n], &handle[n]));
for (size_t n = 0; n < arraysize(thread); n++)
PlatformThread::Join(handle[n]);
for (size_t n = 0; n < arraysize(thread); n++) {
ASSERT_TRUE(thread[n].did_run());
EXPECT_NE(thread[n].thread_id(), main_thread_id);
// Make sure no two threads get the same ID.
for (size_t i = 0; i < n; ++i) {
EXPECT_NE(thread[i].thread_id(), thread[n].thread_id());
}
}
// Make sure that the thread ID is the same across calls.
EXPECT_EQ(main_thread_id, PlatformThread::CurrentId());
}
} // namespace butil
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。