vibe_signal.dhover×61all
#!/usr/bin/env dub
/+ dub.sdl:
    name "vibe_signal"
    dependency "vibe-core" version="2.14.0"
    buildType "checked" {
        buildOptions "optimize" "inline" "debugInfo"
    }
    platforms "linux"
+/

import 
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(module) core.sys.posix.signal

D header file for POSIX.

Source

core/sys/posix/signal.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0@authorsSean Kelly, Alex Rønne Petersen@standardsThe Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
signal
;
import
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(module) core.sys.posix.pthread

D header file for POSIX.

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0.@authorsSean Kelly, Alex Rønne Petersen@standardsThe Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
pthread
:
(alias) vibe_signal.pthread_self = ulong core.sys.posix.pthread.pthread_self() nothrow @nogc
pthread_self
;
import
(package) std
std
.
(module) std.stdio
Category Symbols
File handles _popen File isFileHandle openNetwork stderr stdin stdout
Reading chunks lines readf readfln readln
Writing toFile write writef writefln writeln
Misc KeepTerminator LockType StdioException

Standard I/O functions that extend core.stdc.stdio. core.stdc.stdio is publically imported when importing std.stdio.

There are three layers of I/O:

  1. The lowest layer is the operating system layer. The two main schemes are Windows and Posix.

  2. C's stdio.h which unifies the two operating system schemes.

  3. std.stdio, this module, unifies the various stdio.h implementations into a high level package for D programs.

Source

std/stdio.d

@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Alex Rønne Petersen
stdio
:
(alias template) vibe_signal.writeln = std.stdio.writeln(T...)(T args)

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
;
void
void D main()
main
()
{ int
(local variable) int received
received
;
// Application POSIX adapter. sigwait runs in ordinary thread context, so // no event, allocation or mutex operation is called from a signal handler.
void vibe_signal.runWorker(void delegate() work)
runWorker
({
(struct) core.sys.posix.signal.sigset_t
sigset_t
(local variable) core.sys.posix.signal.sigset_t signals
signals
,
(local variable) core.sys.posix.signal.sigset_t previous
previous
;
assert(
int core.sys.posix.signal.sigemptyset(core.sys.posix.signal.sigset_t*) nothrow @nogc
sigemptyset
(&
(local variable) core.sys.posix.signal.sigset_t signals
signals
) == 0);
assert(
int core.sys.posix.signal.sigaddset(core.sys.posix.signal.sigset_t*, int) nothrow @nogc
sigaddset
(&
(local variable) core.sys.posix.signal.sigset_t signals
signals
,
(constant) int core.sys.posix.signal.SIGUSR1 = 10
SIGUSR1
) == 0);
assert(
int core.sys.posix.signal.pthread_sigmask(int, scope const(core.sys.posix.signal.sigset_t*), core.sys.posix.signal.sigset_t*) nothrow @nogc
pthread_sigmask
(
(constant) int core.sys.posix.signal.SIG_BLOCK = 0
SIG_BLOCK
, &
(local variable) core.sys.posix.signal.sigset_t signals
signals
, &
(local variable) core.sys.posix.signal.sigset_t previous
previous
) == 0);
scope(exit) assert(
int core.sys.posix.signal.pthread_sigmask(int, scope const(core.sys.posix.signal.sigset_t*), core.sys.posix.signal.sigset_t*) nothrow @nogc
pthread_sigmask
(
(constant) int core.sys.posix.signal.SIG_SETMASK = 2
SIG_SETMASK
, &
(local variable) core.sys.posix.signal.sigset_t previous
previous
, null) == 0);
assert(
int core.sys.posix.signal.pthread_kill(ulong, int) nothrow @nogc
pthread_kill
(
ulong core.sys.posix.pthread.pthread_self() nothrow @nogc
pthread_self
(),
(constant) int core.sys.posix.signal.SIGUSR1 = 10
SIGUSR1
) == 0);
assert(
int core.sys.posix.signal.sigwait(scope const(core.sys.posix.signal.sigset_t*), int*) nothrow @nogc
sigwait
(&
(local variable) core.sys.posix.signal.sigset_t signals
signals
, &
(local variable) int received
received
) == 0);
}); assert(
(local variable) int received
received
==
(constant) int core.sys.posix.signal.SIGUSR1 = 10
SIGUSR1
);
void std.stdio.writeln!string(string __param_0) @safe

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Example

Reads stdin and writes it to stdout with an argument counter.

import std.stdio;

void main()
{
    string line;

    for (size_t count = 0; (line = readln) !is null; count++)
    {
         writeln("Input ", count, ": ", line);
    }
}
@paramargs the items to write to stdout@throwsIn case of an I/O error, throws an StdioException.
writeln
("got signal SIGUSR1");
} void
void vibe_signal.runWorker(void delegate() work)
runWorker
(void delegate()
(parameter) void delegate() work
work
)
{ import
(package) vibe
vibe
.
(package) vibe.core
core
.
(module) vibe.core.sync

Event loop compatible task synchronization facilities.

This module provides replacement primitives for the modules in core.sync`` that do not block vibe.d's event loop in their wait states. These should always be preferred over the ones in Druntime under usual circumstances.

Using a standard Mutex is possible as long as it is ensured that no event loop based functionality (I/O, task interaction or anything that implicitly calls vibe.core.core.yield) is executed within a section of code that is protected by the mutex. Failure to do so may result in dead-locks and high-level race-conditions!

@copyright© 2012-2019 Sönke Ludwig@authorsLeonid Kramer, Sönke Ludwig, Manuel Frischknecht@licenseSubject to the terms of the MIT license, as written in the included LICENSE.txt file.
sync
:
(alias) createSharedManualEvent = shared(vibe.core.sync.ManualEvent) vibe.core.sync.createSharedManualEvent() nothrow @trusted

Creates a new signal that can be shared between fibers.

createSharedManualEvent
;
import
(package) core
core
.
(module) core.thread

The thread module provides support for thread creation and management.

Source

core/thread/package.d

@copyrightCopyright Sean Kelly 2005 - 2012.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly, Walter Bright, Alex Rønne Petersen, Martin Nowak
thread
:
(class) core.thread.osthread.Thread

This class encapsulates all threading functionality for the D programming language. As thread manipulation is a required facility for garbage collection, all user threads should derive from this class, and instances of this class should never be explicitly deleted. A new thread may be created using either derivation or composition, as in the following example.

Thread
;
auto
(local variable) shared(vibe.core.sync.ManualEvent) completed
completed
=
shared(vibe.core.sync.ManualEvent) vibe.core.sync.createSharedManualEvent() nothrow @trusted

Creates a new signal that can be shared between fibers.

createSharedManualEvent
();
auto
(local variable) core.thread.osthread.Thread thread
thread
= new
(class) core.thread.osthread.Thread

This class encapsulates all threading functionality for the D programming language. As thread manipulation is a required facility for garbage collection, all user threads should derive from this class, and instances of this class should never be explicitly deleted. A new thread may be created using either derivation or composition, as in the following example.

Thread
({
(parameter) void delegate() work
work
();
(local variable) shared(vibe.core.sync.ManualEvent) completed
completed
.
int vibe.core.sync.ManualEvent.emit() shared nothrow @trusted

Emits the signal, waking up all owners of the signal.

emit
(); });
(local variable) core.thread.osthread.Thread thread
thread
.
core.thread.osthread.Thread core.thread.osthread.Thread.start() nothrow

Starts the thread and invokes the function or delegate passed upon construction.

In

This routine may only be called once per thread instance.

@throwsThreadException if the thread fails to start.
start
();
(local variable) shared(vibe.core.sync.ManualEvent) completed
completed
.
int vibe.core.sync.ManualEvent.wait(int emit_count) shared @safe

Acquires ownership and waits until the emit count differs from the given one or until a timeout is reached.

@throwsMay throw an InterruptException if the task gets interrupted using Task.interrupt().
wait
(0); // parks the fiber, while the worker owns sigwait
(local variable) core.thread.osthread.Thread thread
thread
.
object.Throwable core.thread.osthread.Thread.join(bool rethrow = true)

Waits for this thread to complete. If the thread terminated as the result of an unhandled exception, this exception will be rethrown.

@paramrethrow Rethrow any unhandled exception which may have caused this thread to terminate.@throwsThreadException if the operation fails. Any exception not handled by the joined thread.@returnsAny exception not handled by this thread if rethrow = false, null otherwise.
join
();
}