Skip to content
Open
Binary file removed pkgs/unix_api/a.out
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to add this file too?

Binary file not shown.
2 changes: 2 additions & 0 deletions pkgs/unix_api/constants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@
- EMFILE
- ENOENT
- ENOSPC
- ENOSYS
- ENOTDIR
- ENOTEMPTY
- EPERM
- ETIMEDOUT
"<fcntl.h>":
- AT_FDCWD
- AT_REMOVEDIR
Expand Down
1 change: 1 addition & 0 deletions pkgs/unix_api/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void main(List<String> args) async {
assetName: 'libc_shim',
libraries: [
if ([OS.linux].contains(input.config.code.targetOS)) 'crypt',
if (input.config.code.targetOS != OS.android) 'pthread',
],
sources: [
'src/libc_shim.c',
Expand Down
103 changes: 102 additions & 1 deletion pkgs/unix_api/lib/src/bespoke.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import 'dart:ffi' as ffi;

import 'errno.dart';
import 'libc_bindings.g.dart';
export 'libc_bindings.g.dart' show DIR, dirent, Stat, timespec;
export 'libc_bindings.g.dart'
show DIR, dirent, Stat, timespec, pthread_t, pthread_attr_t;

/// Gets metadata for a file.
///
Expand Down Expand Up @@ -65,3 +66,103 @@ extension DirentPtrExtensions on ffi.Pointer<dirent> {
/// Need because of https://github.com/dart-lang/sdk/issues/41237.
ffi.Pointer<ffi.Char> get d_name_ptr => libc_shim_d_name_ptr(this);
}

// <pthread.h>

/// Unlocks all threads waiting on a condition variable.
///
/// See the [POSIX specification for `pthread_cond_broadcast`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_broadcast.html).
int pthread_cond_broadcast(ffi.Pointer<pthread_cond_t> cond) =>
libc_shim_pthread_cond_broadcast(cond, errnoPtr);

/// Destroys a condition variable.
///
/// See the [POSIX specification for `pthread_cond_destroy`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_destroy.html).
int pthread_cond_destroy(ffi.Pointer<pthread_cond_t> cond) =>
libc_shim_pthread_cond_destroy(cond, errnoPtr);

/// Initializes a condition variable.
///
/// See the [POSIX specification for `pthread_cond_init`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_init.html).
int pthread_cond_init(
ffi.Pointer<pthread_cond_t> cond,
ffi.Pointer<pthread_condattr_t> attr,
) => libc_shim_pthread_cond_init(cond, attr, errnoPtr);

/// Unlocks one thread waiting on a condition variable.
///
/// See the [POSIX specification for `pthread_cond_signal`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_signal.html).
int pthread_cond_signal(ffi.Pointer<pthread_cond_t> cond) =>
libc_shim_pthread_cond_signal(cond, errnoPtr);

/// Waits on a condition variable for a given amount of time.
///
/// See the [POSIX specification for `pthread_cond_timedwait`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html).
int pthread_cond_timedwait(
ffi.Pointer<pthread_cond_t> cond,
ffi.Pointer<pthread_mutex_t> mutex,
ffi.Pointer<timespec> abstime,
) => libc_shim_pthread_cond_timedwait(cond, mutex, abstime, errnoPtr);

/// Waits on a condition variable.
///
/// See the [POSIX specification for `pthread_cond_wait`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_wait.html).
int pthread_cond_wait(
ffi.Pointer<pthread_cond_t> cond,
ffi.Pointer<pthread_mutex_t> mutex,
) => libc_shim_pthread_cond_wait(cond, mutex, errnoPtr);

/// Creates a new thread.
///
/// See the [POSIX specification for `pthread_create`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_create.html).
int pthread_create(
ffi.Pointer<pthread_t> thread,
ffi.Pointer<pthread_attr_t> attr,
ffi.Pointer<
ffi.NativeFunction<ffi.Pointer<ffi.Void> Function(ffi.Pointer<ffi.Void>)>
>
start_routine,
ffi.Pointer<ffi.Void> arg,
) => libc_shim_pthread_create(thread, attr, start_routine, arg, errnoPtr);

/// Detaches a thread.
///
/// See the [POSIX specification for `pthread_detach`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_detach.html).
int pthread_detach(pthread_t thread) =>
libc_shim_pthread_detach(thread, errnoPtr);

/// Destroys a mutex.
///
/// See the [POSIX specification for `pthread_mutex_destroy`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_destroy.html).
int pthread_mutex_destroy(ffi.Pointer<pthread_mutex_t> mutex) =>
libc_shim_pthread_mutex_destroy(mutex, errnoPtr);

/// Initializes a mutex.
///
/// See the [POSIX specification for `pthread_mutex_init`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_init.html).
int pthread_mutex_init(
ffi.Pointer<pthread_mutex_t> mutex,
ffi.Pointer<pthread_mutexattr_t> attr,
) => libc_shim_pthread_mutex_init(mutex, attr, errnoPtr);

/// Locks a mutex.
///
/// See the [POSIX specification for `pthread_mutex_lock`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html).
int pthread_mutex_lock(ffi.Pointer<pthread_mutex_t> mutex) =>
libc_shim_pthread_mutex_lock(mutex, errnoPtr);

/// Locks a mutex, failing if the lock is not acquired before a timeout.
///
/// Available on Android and Linux.
///
/// See the [POSIX specification for `pthread_mutex_timedlock`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_timedlock.html).
int pthread_mutex_timedlock(
ffi.Pointer<pthread_mutex_t> mutex,
ffi.Pointer<timespec> abs_timeout,
) => libc_shim_pthread_mutex_timedlock(mutex, abs_timeout, errnoPtr);

/// Unlocks a mutex.
///
/// See the [POSIX specification for `pthread_mutex_unlock`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_unlock.html).
int pthread_mutex_unlock(ffi.Pointer<pthread_mutex_t> mutex) =>
libc_shim_pthread_mutex_unlock(mutex, errnoPtr);
6 changes: 6 additions & 0 deletions pkgs/unix_api/lib/src/constant_bindings.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions pkgs/unix_api/lib/src/constants.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

168 changes: 168 additions & 0 deletions pkgs/unix_api/lib/src/libc_bindings.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions pkgs/unix_api/src/constants.g.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading