Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(483)

Side by Side Diff: mojo/public/cpp/utility/lib/thread.cc

Issue 814543006: Move //mojo/{public, edk} underneath //third_party (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/cpp/utility/lib/run_loop.cc ('k') | mojo/public/cpp/utility/lib/thread_local.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/public/cpp/utility/thread.h"
6
7 #include <assert.h>
8
9 namespace mojo {
10
11 Thread::Thread() : options_(), thread_(), started_(false), joined_(false) {
12 }
13
14 Thread::Thread(const Options& options)
15 : options_(options), thread_(), started_(false), joined_(false) {
16 }
17
18 Thread::~Thread() {
19 // If it was started, it must have been joined.
20 assert(!started_ || joined_);
21 }
22
23 void Thread::Start() {
24 assert(!started_);
25 assert(!joined_);
26
27 pthread_attr_t attr;
28 int rv = pthread_attr_init(&attr);
29 MOJO_ALLOW_UNUSED_LOCAL(rv);
30 assert(rv == 0);
31
32 // Non-default stack size?
33 if (options_.stack_size() != 0) {
34 rv = pthread_attr_setstacksize(&attr, options_.stack_size());
35 assert(rv == 0);
36 }
37
38 started_ = true;
39 rv = pthread_create(&thread_, &attr, &ThreadRunTrampoline, this);
40 assert(rv == 0);
41
42 rv = pthread_attr_destroy(&attr);
43 assert(rv == 0);
44 }
45
46 void Thread::Join() {
47 // Must have been started but not yet joined.
48 assert(started_);
49 assert(!joined_);
50
51 joined_ = true;
52 int rv = pthread_join(thread_, nullptr);
53 MOJO_ALLOW_UNUSED_LOCAL(rv);
54 assert(rv == 0);
55 }
56
57 // static
58 void* Thread::ThreadRunTrampoline(void* arg) {
59 Thread* self = static_cast<Thread*>(arg);
60 self->Run();
61 return nullptr;
62 }
63
64 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/utility/lib/run_loop.cc ('k') | mojo/public/cpp/utility/lib/thread_local.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698