Skip to content

Commit 60c0ecf

Browse files
committed
reflow docs for synchronization primitives
1 parent c455432 commit 60c0ecf

File tree

7 files changed

+132
-140
lines changed

7 files changed

+132
-140
lines changed

R/sync.R

Lines changed: 74 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,53 @@
1919
#' Condition Variables
2020
#'
2121
#' \code{cv} creates a new condition variable (protected by a mutex internal to
22-
#' the object).
22+
#' the object).
2323
#'
24-
#' @return For \strong{cv}: a \sQuote{conditionVariable} object.
24+
#' Pass the \sQuote{conditionVariable} to the asynchronous receive functions
25+
#' \code{\link{recv_aio}} or \code{\link{request}}. Alternatively, to be
26+
#' notified of a pipe event, pass it to \code{\link{pipe_notify}}.
2527
#'
26-
#' For \strong{wait}: (invisibly) logical TRUE, or else FALSE if a flag has
27-
#' been set.
28+
#' Completion of the receive or pipe event, which happens asynchronously and
29+
#' independently of the main R thread, will signal the condition variable by
30+
#' incrementing it by 1.
2831
#'
29-
#' For \strong{until}: (invisibly) logical TRUE if signalled, or else FALSE
30-
#' if the timeout was reached.
32+
#' This will cause the R execution thread waiting on the condition variable
33+
#' using \code{wait} or \code{until} to wake and continue.
3134
#'
32-
#' For \strong{cv_value}: integer value of the condition variable.
35+
#' For argument \sQuote{msec}, non-integer values will be coerced to integer.
36+
#' Non-numeric input will be ignored and return immediately.
3337
#'
34-
#' For \strong{cv_reset} and \strong{cv_signal}: zero (invisibly).
38+
#' @return For \strong{cv}: a \sQuote{conditionVariable} object.
3539
#'
36-
#' @details Pass the \sQuote{conditionVariable} to the asynchronous receive
37-
#' functions \code{\link{recv_aio}} or \code{\link{request}}. Alternatively,
38-
#' to be notified of a pipe event, pass it to \code{\link{pipe_notify}}.
40+
#' For \strong{wait}: (invisibly) logical TRUE, or else FALSE if a flag has
41+
#' been set.
3942
#'
40-
#' Completion of the receive or pipe event, which happens asynchronously and
41-
#' independently of the main R thread, will signal the condition variable by
42-
#' incrementing it by 1.
43+
#' For \strong{until}: (invisibly) logical TRUE if signalled, or else FALSE if
44+
#' the timeout was reached.
4345
#'
44-
#' This will cause the R execution thread waiting on the condition variable
45-
#' using \code{wait} or \code{until} to wake and continue.
46+
#' For \strong{cv_value}: integer value of the condition variable.
4647
#'
47-
#' For argument \sQuote{msec}, non-integer values will be coerced to
48-
#' integer. Non-numeric input will be ignored and return immediately.
48+
#' For \strong{cv_reset} and \strong{cv_signal}: zero (invisibly).
4949
#'
5050
#' @section Condition:
5151
#'
52-
#' The condition internal to this \sQuote{conditionVariable} maintains a
53-
#' state (value). Each signal increments the value by 1. Each time
54-
#' \code{wait} or \code{until} returns (apart from due to timeout), the
55-
#' value is decremented by 1.
52+
#' The condition internal to this \sQuote{conditionVariable} maintains a state
53+
#' (value). Each signal increments the value by 1. Each time \code{wait} or
54+
#' \code{until} returns (apart from due to timeout), the value is decremented
55+
#' by 1.
5656
#'
57-
#' The internal condition may be inspected at any time using \code{cv_value}
58-
#' and reset using \code{cv_reset}. This affords a high degree of
59-
#' flexibility in designing complex concurrent applications.
57+
#' The internal condition may be inspected at any time using \code{cv_value} and
58+
#' reset using \code{cv_reset}. This affords a high degree of flexibility in
59+
#' designing complex concurrent applications.
6060
#'
6161
#' @section Flag:
6262
#'
63-
#' The condition variable also contains a flag that certain signalling
64-
#' functions such as \code{\link{pipe_notify}} can set. When this flag has
65-
#' been set, all subsequent \code{wait} calls will return logical FALSE
66-
#' instead of TRUE.
63+
#' The condition variable also contains a flag that certain signalling functions
64+
#' such as \code{\link{pipe_notify}} can set. When this flag has been set, all
65+
#' subsequent \code{wait} calls will return logical FALSE instead of TRUE.
6766
#'
68-
#' Note that the flag is not automatically reset, but may be reset manually
69-
#' using \code{cv_reset}.
67+
#' Note that the flag is not automatically reset, but may be reset manually
68+
#' using \code{cv_reset}.
7069
#'
7170
#' @examples
7271
#' cv <- cv()
@@ -78,8 +77,8 @@ cv <- function() .Call(rnng_cv_alloc)
7877
#' Condition Variables - Wait
7978
#'
8079
#' \code{wait} waits on a condition being signalled by completion of an
81-
#' asynchronous receive or pipe event. \cr \code{wait_} is a variant that
82-
#' allows user interrupts, suitable for interactive use.
80+
#' asynchronous receive or pipe event. \cr \code{wait_} is a variant that allows
81+
#' user interrupts, suitable for interactive use.
8382
#'
8483
#' @param cv a \sQuote{conditionVariable} object.
8584
#'
@@ -102,11 +101,11 @@ wait_ <- function(cv) invisible(.Call(rnng_cv_wait_safe, cv))
102101
#' Condition Variables - Until
103102
#'
104103
#' \code{until} waits until a future time on a condition being signalled by
105-
#' completion of an asynchronous receive or pipe event. \cr \code{until_} is
106-
#' a variant that allows user interrupts, suitable for interactive use.
104+
#' completion of an asynchronous receive or pipe event. \cr \code{until_} is a
105+
#' variant that allows user interrupts, suitable for interactive use.
107106
#'
108107
#' @param msec maximum time in milliseconds to wait for the condition variable
109-
#' to be signalled.
108+
#' to be signalled.
110109
#'
111110
#' @examples
112111
#' until(cv, 10L)
@@ -163,32 +162,31 @@ cv_signal <- function(cv) invisible(.Call(rnng_cv_signal, cv))
163162
#' Pipe Notify
164163
#'
165164
#' Signals a \sQuote{conditionVariable} whenever pipes (individual connections)
166-
#' are added or removed at a socket.
165+
#' are added or removed at a socket.
166+
#'
167+
#' For add: this event occurs after the pipe is fully added to the socket. Prior
168+
#' to this time, it is not possible to communicate over the pipe with the socket.
169+
#'
170+
#' For remove: this event occurs after the pipe has been removed from the socket.
171+
#' The underlying transport may be closed at this point, and it is not possible
172+
#' to communicate using this pipe.
167173
#'
168174
#' @param socket a Socket.
169175
#' @param cv a \sQuote{conditionVariable} to signal, or NULL to cancel a
170-
#' previously set signal.
176+
#' previously set signal.
171177
#' @param cv2 [default NULL] optionally, if specified, a second
172-
#' \sQuote{conditionVariable} to signal. Note that this cv is signalled
173-
#' sequentially after the first condition variable.
178+
#' \sQuote{conditionVariable} to signal. Note that this cv is signalled
179+
#' sequentially after the first condition variable.
174180
#' @param add [default FALSE] logical value whether to signal (or cancel signal)
175-
#' when a pipe is added.
181+
#' when a pipe is added.
176182
#' @param remove [default FALSE] logical value whether to signal (or cancel
177-
#' signal) when a pipe is removed.
183+
#' signal) when a pipe is removed.
178184
#' @param flag [default FALSE] logical value whether to also set a flag in the
179-
#' \sQuote{conditionVariable}. This can help distinguish between different
180-
#' types of signal, and causes any subsequent \code{\link{wait}} to return
181-
#' FALSE instead of TRUE. If a signal from the \pkg{tools} package, e.g.
182-
#' \code{tools::SIGINT}, or an equivalent integer value is supplied, this
183-
#' sets a flag and additionally raises this signal upon the flag being set.
184-
#'
185-
#' @details For add: this event occurs after the pipe is fully added to the
186-
#' socket. Prior to this time, it is not possible to communicate over the
187-
#' pipe with the socket.
188-
#'
189-
#' For remove: this event occurs after the pipe has been removed from the
190-
#' socket. The underlying transport may be closed at this point, and it is
191-
#' not possible to communicate using this pipe.
185+
#' \sQuote{conditionVariable}. This can help distinguish between different
186+
#' types of signal, and causes any subsequent \code{\link{wait}} to return
187+
#' FALSE instead of TRUE. If a signal from the \pkg{tools} package, e.g.
188+
#' \code{tools::SIGINT}, or an equivalent integer value is supplied, this sets
189+
#' a flag and additionally raises this signal upon the flag being set.
192190
#'
193191
#' @return Invisibly, zero on success (will otherwise error).
194192
#'
@@ -227,16 +225,15 @@ pipe_notify <- function(socket, cv, cv2 = NULL, add = FALSE, remove = FALSE, fla
227225
#' Lock / Unlock a Socket
228226
#'
229227
#' Prevents further pipe connections from being established at a Socket. If a
230-
#' socket is locked, new pipe connections are closed before they can be
231-
#' added to the socket.
228+
#' socket is locked, new pipe connections are closed before they can be added to
229+
#' the socket.
232230
#'
233231
#' @param socket a Socket.
234232
#' @param cv (optional) a \sQuote{conditionVariable}. If supplied, the socket is
235-
#' locked only whilst the condition variable is an odd value. This is
236-
#' designed to allow an initial connection, as well as subsequent
237-
#' re-connections after a connection has ended, if the conditon variable is
238-
#' also registered with \code{\link{pipe_notify}} for both add and remove
239-
#' pipe events.
233+
#' locked only whilst the condition variable is an odd value. This is designed
234+
#' to allow an initial connection, as well as subsequent re-connections after
235+
#' a connection has ended, if the conditon variable is also registered with
236+
#' \code{\link{pipe_notify}} for both add and remove pipe events.
240237
#'
241238
#' @return Invisibly, zero on success (will otherwise error).
242239
#'
@@ -274,24 +271,24 @@ unlock <- function(socket) invisible(.Call(rnng_socket_unlock, socket))
274271
#'
275272
#' Forwards signals from one \sQuote{conditionVariable} to another.
276273
#'
274+
#' The condition value of \sQuote{cv} is initially reset to zero when this
275+
#' operator returns. Only one forwarder can be active on a \sQuote{cv} at any
276+
#' given time, and assigning a new forwarding target cancels any currently
277+
#' existing forwarding.
278+
#'
279+
#' Changes in the condition value of \sQuote{cv} are forwarded to \sQuote{cv2},
280+
#' but only on each occassion \sQuote{cv} is signalled. This means that waiting
281+
#' on \sQuote{cv} will cause a temporary divergence between the actual condition
282+
#' value of \sQuote{cv} and that recorded at \sQuote{cv2}, until the next time
283+
#' \sQuote{cv} is signalled.
284+
#'
277285
#' @param cv a \sQuote{conditionVariable} object, from which to forward the
278-
#' signal.
286+
#' signal.
279287
#' @param cv2 a \sQuote{conditionVariable} object, to which the signal is
280-
#' forwarded.
288+
#' forwarded.
281289
#'
282290
#' @return Invisibly, \sQuote{cv2}.
283291
#'
284-
#' @details The condition value of \sQuote{cv} is initially reset to zero when
285-
#' this operator returns. Only one forwarder can be active on a \sQuote{cv}
286-
#' at any given time, and assigning a new forwarding target cancels any
287-
#' currently existing forwarding.
288-
#'
289-
#' Changes in the condition value of \sQuote{cv} are forwarded to
290-
#' \sQuote{cv2}, but only on each occassion \sQuote{cv} is signalled. This
291-
#' means that waiting on \sQuote{cv} will cause a temporary divergence
292-
#' between the actual condition value of \sQuote{cv} and that recorded at
293-
#' \sQuote{cv2}, until the next time \sQuote{cv} is signalled.
294-
#'
295292
#' @examples
296293
#' cva <- cv(); cvb <- cv(); cv1 <- cv(); cv2 <- cv()
297294
#'
@@ -310,8 +307,7 @@ unlock <- function(socket) invisible(.Call(rnng_socket_unlock, socket))
310307
#' Dispatcher Socket
311308
#'
312309
#' Creates a Dispatcher socket, which is a special type of \sQuote{req} socket,
313-
#' with FIFO scheduling using a threaded implementation (for internal use
314-
#' only).
310+
#' with FIFO scheduling using a threaded implementation (for internal use only).
315311
#'
316312
#' @param host \sQuote{inproc://} url connecting the host to the thread.
317313
#' @param url the URLs at which to listen for rep nodes.
@@ -328,7 +324,7 @@ unlock <- function(socket) invisible(.Call(rnng_socket_unlock, socket))
328324
#' Read Online Status
329325
#'
330326
#' Reads the online status of threaded dispatcher sockets (for internal use
331-
#' only).
327+
#' only).
332328
#'
333329
#' @param sock a dispatcher Socket.
334330
#'

man/cv.Rd

Lines changed: 33 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/dot-dispatcher.Rd

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/dot-online.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/grapes-twiddle-greater-than-grapes.Rd

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)