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

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

Issue 1784643002: Mojo C++ bindings: remove the utility/ folder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@13_1_remove_thread_dep
Patch Set: Created 4 years, 9 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 #include "base/compiler_specific.h"
10
11 namespace mojo {
12
13 Thread::Thread() : options_(), thread_(), started_(false), joined_(false) {
14 }
15
16 Thread::Thread(const Options& options)
17 : options_(options), thread_(), started_(false), joined_(false) {
18 }
19
20 Thread::~Thread() {
21 // If it was started, it must have been joined.
22 assert(!started_ || joined_);
23 }
24
25 void Thread::Start() {
26 assert(!started_);
27 assert(!joined_);
28
29 pthread_attr_t attr;
30 int rv = pthread_attr_init(&attr);
31 ALLOW_UNUSED_LOCAL(rv);
32 assert(rv == 0);
33
34 // Non-default stack size?
35 if (options_.stack_size() != 0) {
36 rv = pthread_attr_setstacksize(&attr, options_.stack_size());
37 assert(rv == 0);
38 }
39
40 started_ = true;
41 rv = pthread_create(&thread_, &attr, &ThreadRunTrampoline, this);
42 assert(rv == 0);
43
44 rv = pthread_attr_destroy(&attr);
45 assert(rv == 0);
46 }
47
48 void Thread::Join() {
49 // Must have been started but not yet joined.
50 assert(started_);
51 assert(!joined_);
52
53 joined_ = true;
54 int rv = pthread_join(thread_, nullptr);
55 ALLOW_UNUSED_LOCAL(rv);
56 assert(rv == 0);
57 }
58
59 // static
60 void* Thread::ThreadRunTrampoline(void* arg) {
61 Thread* self = static_cast<Thread*>(arg);
62 self->Run();
63 return nullptr;
64 }
65
66 } // 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