e105029f62
This CL also removes ability to assign names to mutexes which was
added in c25ebfff96 but did not yield
any interesting data.
TEST=ci
CoreLibraryReviewExempt: Changes to dart:concurrent only.
Cq-Include-Trybots: luci.dart.try:vm-fuchsia-release-x64-try,vm-win-debug-x64-try,vm-win-release-x64-try,vm-aot-linux-product-x64-try
Change-Id: Id41e1d29832f6008e02f0a571ee67564e1a84224
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375300
Reviewed-by: Martin Kustermann <kustermann@google.com>
100 lines
2.9 KiB
C++
100 lines
2.9 KiB
C++
// Copyright (c) 2016, 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.
|
|
|
|
#include "platform/globals.h"
|
|
#if defined(DART_HOST_OS_FUCHSIA) && !defined(DART_USE_ABSL)
|
|
|
|
#include "bin/thread.h"
|
|
|
|
#include <errno.h> // NOLINT
|
|
#include <sys/time.h> // NOLINT
|
|
#include <zircon/status.h>
|
|
#include <zircon/syscalls.h>
|
|
#include <zircon/threads.h>
|
|
#include <zircon/types.h>
|
|
|
|
#include "platform/assert.h"
|
|
#include "platform/utils.h"
|
|
|
|
namespace dart {
|
|
namespace bin {
|
|
|
|
class ThreadStartData {
|
|
public:
|
|
ThreadStartData(const char* name,
|
|
Thread::ThreadStartFunction function,
|
|
uword parameter)
|
|
: name_(name), function_(function), parameter_(parameter) {}
|
|
|
|
const char* name() const { return name_; }
|
|
Thread::ThreadStartFunction function() const { return function_; }
|
|
uword parameter() const { return parameter_; }
|
|
|
|
private:
|
|
const char* name_;
|
|
Thread::ThreadStartFunction function_;
|
|
uword parameter_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ThreadStartData);
|
|
};
|
|
|
|
// Dispatch to the thread start function provided by the caller. This trampoline
|
|
// is used to ensure that the thread is properly destroyed if the thread just
|
|
// exits.
|
|
static void* ThreadStart(void* data_ptr) {
|
|
ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr);
|
|
|
|
const char* name = data->name();
|
|
Thread::ThreadStartFunction function = data->function();
|
|
uword parameter = data->parameter();
|
|
delete data;
|
|
|
|
// Set the thread name.
|
|
char truncated_name[ZX_MAX_NAME_LEN];
|
|
snprintf(truncated_name, ZX_MAX_NAME_LEN, "%s", name);
|
|
zx_handle_t thread_handle = thrd_get_zx_handle(thrd_current());
|
|
zx_object_set_property(thread_handle, ZX_PROP_NAME, truncated_name,
|
|
ZX_MAX_NAME_LEN);
|
|
|
|
// Call the supplied thread start function handing it its parameters.
|
|
function(parameter);
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
int Thread::Start(const char* name,
|
|
ThreadStartFunction function,
|
|
uword parameter) {
|
|
pthread_attr_t attr;
|
|
int result = pthread_attr_init(&attr);
|
|
RETURN_ON_PTHREAD_FAILURE(result);
|
|
|
|
result = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
RETURN_ON_PTHREAD_FAILURE(result);
|
|
|
|
result = pthread_attr_setstacksize(&attr, Thread::GetMaxStackSize());
|
|
RETURN_ON_PTHREAD_FAILURE(result);
|
|
|
|
ThreadStartData* data = new ThreadStartData(name, function, parameter);
|
|
|
|
pthread_t tid;
|
|
result = pthread_create(&tid, &attr, ThreadStart, data);
|
|
RETURN_ON_PTHREAD_FAILURE(result);
|
|
|
|
result = pthread_attr_destroy(&attr);
|
|
RETURN_ON_PTHREAD_FAILURE(result);
|
|
|
|
return 0;
|
|
}
|
|
|
|
intptr_t Thread::GetMaxStackSize() {
|
|
const int kStackSize = (128 * kWordSize * KB);
|
|
return kStackSize;
|
|
}
|
|
|
|
} // namespace bin
|
|
} // namespace dart
|
|
|
|
#endif // defined(DART_HOST_OS_FUCHSIA) && !defined(DART_USE_ABSL)
|