Files
sdk/runtime/platform/thread.h
T
sgjesse@google.com 68d10e1568 Move Mutex and Monitor from vm/ to platform/
The tests are still in runtime/vm/thread_test.cc.

R=ager@google.com, iposva@google.com

BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//9196002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3349 260f80e4-7a28-3924-810f-c04153c831b5
2012-01-17 10:29:24 +00:00

87 lines
1.6 KiB
C++

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef PLATFORM_THREAD_H_
#define PLATFORM_THREAD_H_
#include "platform/globals.h"
// Declare the OS-specific types ahead of defining the generic classes.
#if defined(TARGET_OS_LINUX)
#include "platform/thread_linux.h"
#elif defined(TARGET_OS_MACOS)
#include "platform/thread_macos.h"
#elif defined(TARGET_OS_WINDOWS)
#include "platform/thread_win.h"
#else
#error Unknown target os.
#endif
namespace dart {
class Thread {
public:
// Function to be called on thread start.
typedef void (*ThreadStartFunction) (uword parameter);
// TODO(iposva): Define the proper interface for spawning and killing threads.
Thread(ThreadStartFunction function, uword parameters);
~Thread();
private:
ThreadData data_;
DISALLOW_COPY_AND_ASSIGN(Thread);
};
class Mutex {
public:
Mutex();
~Mutex();
void Lock();
bool TryLock();
void Unlock();
private:
MutexData data_;
DISALLOW_COPY_AND_ASSIGN(Mutex);
};
class Monitor {
public:
enum WaitResult {
kNotified,
kTimedOut
};
static const int64_t kNoTimeout = 0;
Monitor();
~Monitor();
void Enter();
void Exit();
// Wait for notification or timeout.
WaitResult Wait(int64_t millis);
// Notify waiting threads.
void Notify();
void NotifyAll();
private:
MonitorData data_; // OS-specific data.
DISALLOW_COPY_AND_ASSIGN(Monitor);
};
} // namespace dart
#endif // PLATFORM_THREAD_H_