diff options
author | deanm@google.com <deanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-06 10:06:59 +0000 |
---|---|---|
committer | deanm@google.com <deanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-06 10:06:59 +0000 |
commit | d1e0ec9cde64a4513859024b9ec4077c0771cff9 (patch) | |
tree | 5b3e9ba682b4731c29a25ef59290401a9bc4fa58 | |
parent | ec7dc1160836695462ee7311d4c02f2c2f61350e (diff) | |
download | chromium_src-d1e0ec9cde64a4513859024b9ec4077c0771cff9.zip chromium_src-d1e0ec9cde64a4513859024b9ec4077c0771cff9.tar.gz chromium_src-d1e0ec9cde64a4513859024b9ec4077c0771cff9.tar.bz2 |
Add YieldCurrentThread to PlatformThread, for giving up the current thread's timeslice.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@423 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/platform_thread.cc | 13 | ||||
-rw-r--r-- | base/platform_thread.h | 3 |
2 files changed, 16 insertions, 0 deletions
diff --git a/base/platform_thread.cc b/base/platform_thread.cc index 1966ab2..3cb8f39 100644 --- a/base/platform_thread.cc +++ b/base/platform_thread.cc @@ -27,6 +27,10 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#ifndef WIN32 +#include <sched.h> +#endif + #include "base/platform_thread.h" // static @@ -42,6 +46,15 @@ PlatformThread PlatformThread::Current() { return thread; } +// static +void PlatformThread::YieldCurrentThread() { +#ifdef WIN32 + ::Sleep(0); +#else + sched_yield(); +#endif +} + bool PlatformThread::operator==(const PlatformThread& other_thread) { #ifdef WIN32 return thread_ == other_thread.thread_; diff --git a/base/platform_thread.h b/base/platform_thread.h index b6fb45d..7f887d2 100644 --- a/base/platform_thread.h +++ b/base/platform_thread.h @@ -43,6 +43,9 @@ class PlatformThread { // Gets the current thread. static PlatformThread Current(); + // Yield the current thread so another thread can be scheduled. + static void YieldCurrentThread(); + bool operator==(const PlatformThread& other_thread); private: |