summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/platform_thread.cc13
-rw-r--r--base/platform_thread.h3
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: