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

Side by Side Diff: base/platform_thread.h

Issue 18677: Use PlatformThreadId, not int when dealing with thread ids. (Closed)
Patch Set: Addressing comments Created 11 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 | « base/non_thread_safe.h ('k') | base/platform_thread_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // WARNING: You should *NOT* be using this class directly. PlatformThread is 5 // WARNING: You should *NOT* be using this class directly. PlatformThread is
6 // the low-level platform-specific abstraction to the OS's threading interface. 6 // the low-level platform-specific abstraction to the OS's threading interface.
7 // You should instead be using a message-loop driven Thread, see thread.h. 7 // You should instead be using a message-loop driven Thread, see thread.h.
8 8
9 #ifndef BASE_PLATFORM_THREAD_H_ 9 #ifndef BASE_PLATFORM_THREAD_H_
10 #define BASE_PLATFORM_THREAD_H_ 10 #define BASE_PLATFORM_THREAD_H_
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 13
14 // PlatformThreadHandle should not be assumed to be a numeric type, since the 14 // PlatformThreadHandle should not be assumed to be a numeric type, since the
15 // standard intends to allow pthread_t to be a structure. This means you 15 // standard intends to allow pthread_t to be a structure. This means you
16 // should not initialize it to a value, like 0. If it's a member variable, the 16 // should not initialize it to a value, like 0. If it's a member variable, the
17 // constructor can safely "value initialize" using () in the initializer list. 17 // constructor can safely "value initialize" using () in the initializer list.
18 #if defined(OS_WIN) 18 #if defined(OS_WIN)
19 #include <windows.h>
20 typedef DWORD PlatformThreadId;
19 typedef void* PlatformThreadHandle; // HANDLE 21 typedef void* PlatformThreadHandle; // HANDLE
20 #elif defined(OS_POSIX) 22 #elif defined(OS_POSIX)
21 #include <pthread.h> 23 #include <pthread.h>
22 typedef pthread_t PlatformThreadHandle; 24 typedef pthread_t PlatformThreadHandle;
25 #if defined(OS_LINUX)
26 #include <unistd.h>
27 typedef pid_t PlatformThreadId;
28 #elif defined(OS_MACOSX)
29 #include <mach/mach.h>
30 typedef mach_port_t PlatformThreadId;
31 #endif
23 #endif 32 #endif
24 33
25 // A namespace for low-level thread functions. 34 // A namespace for low-level thread functions.
26 class PlatformThread { 35 class PlatformThread {
27 public: 36 public:
28 // Gets the current thread id, which may be useful for logging purposes. 37 // Gets the current thread id, which may be useful for logging purposes.
29 static int CurrentId(); 38 static PlatformThreadId CurrentId();
30 39
31 // Yield the current thread so another thread can be scheduled. 40 // Yield the current thread so another thread can be scheduled.
32 static void YieldCurrentThread(); 41 static void YieldCurrentThread();
33 42
34 // Sleeps for the specified duration (units are milliseconds). 43 // Sleeps for the specified duration (units are milliseconds).
35 static void Sleep(int duration_ms); 44 static void Sleep(int duration_ms);
36 45
37 // Sets the thread name visible to a debugger. This has no effect otherwise. 46 // Sets the thread name visible to a debugger. This has no effect otherwise.
38 static void SetName(const char* name); 47 static void SetName(const char* name);
39 48
(...skipping 20 matching lines...) Expand all
60 // the caller until the designated thread exits. This will invalidate 69 // the caller until the designated thread exits. This will invalidate
61 // |thread_handle|. 70 // |thread_handle|.
62 static void Join(PlatformThreadHandle thread_handle); 71 static void Join(PlatformThreadHandle thread_handle);
63 72
64 private: 73 private:
65 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); 74 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread);
66 }; 75 };
67 76
68 #endif // BASE_PLATFORM_THREAD_H_ 77 #endif // BASE_PLATFORM_THREAD_H_
69 78
OLDNEW
« no previous file with comments | « base/non_thread_safe.h ('k') | base/platform_thread_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698