Skip to content

Commit

Permalink
reverts cv_adjust(); implements 'cv2' for pipe_notify()
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Mar 22, 2023
1 parent e726170 commit fc08c77
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 100 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export(base64enc)
export(call_aio)
export(context)
export(cv)
export(cv_adjust)
export(cv_reset)
export(cv_value)
export(device)
Expand Down
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#### New Features

* Implements condition variables (from the NNG library), which allows the R execution thread to wait until it is signalled by an incoming message or pipe event - adding functions `cv()`, `wait()`, `until()`, `cv_value()`, `cv_adjust()` and `cv_reset()`.
* Implements condition variables (from the NNG library), which allows the R execution thread to wait until it is signalled by an incoming message or pipe event - adding functions `cv()`, `wait()`, `until()`, `cv_value()`, and `cv_reset()`.
* Adds signalling receive functions `recv_aio_signal()` and `request_signal()`.
* Implements `pipe_notify()` to signal a condition variable whenever pipes are added or removed at a socket.
* Implements `pipe_notify()` to signal a condition variable (or 2 condition variables) whenever pipes are added or removed at a socket.
* Implements `msg_pipe()` to return the pipe connection associated with a 'recvAio' message.
* Exposes the `sha1()` cryptographic hash and HMAC generation function from the 'Mbed TLS' library (for secure applications, use one of the SHA-2 algorithms instead).

Expand Down
49 changes: 23 additions & 26 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ status_code <- function(x) .Call(rnng_status_code, x)
#'
#' For \code{cv_value}: integer value of the condition variable.
#'
#' For \code{cv_adjust} and \code{cv_reset}: invisible NULL.
#' For \code{cv_reset}: invisible NULL.
#'
#' @details Pass the 'conditionVariable' to the signalling forms of the
#' asynchronous receive functions: \code{\link{recv_aio_signal}} or
Expand All @@ -288,8 +288,8 @@ status_code <- function(x) .Call(rnng_status_code, x)
#' This will cause the R execution thread waiting on the condition variable
#' using \code{wait} or \code{until} to wake and continue.
#'
#' For arguments 'msec' and 'value', non-integer values will be coerced to
#' integer. Non-numeric input will be ignored and return immediately.
#' For argument 'msec', non-integer values will be coerced to integer.
#' Non-numeric input will be ignored and return immediately.
#'
#' @section Condition:
#'
Expand All @@ -298,10 +298,9 @@ status_code <- function(x) .Call(rnng_status_code, x)
#' \code{wait} or \code{until} returns (apart from due to timeout), the
#' counter is decremented by 1.
#'
#' The internal condition may be inspected at any time using \code{cv_value},
#' adjusted using \code{cv_adjust} and reset to zero using \code{cv_reset}.
#' This affords a high degree of flexibility in designing complex concurrent
#' applications.
#' The internal condition may be inspected at any time using \code{cv_value}
#' and reset to zero using \code{cv_reset}. This affords a high degree of
#' flexibility in designing complex concurrent applications.
#'
#' @section Flag:
#'
Expand Down Expand Up @@ -363,29 +362,16 @@ until <- function(cv, msec) invisible(.Call(rnng_cv_until, cv, msec))
#'
cv_value <- function(cv) .Call(rnng_cv_value, cv)

#' Condition Variables - Adjust
#' Condition Variables - Reset
#'
#' \code{cv_adjust} and \code{cv_reset} respectively adjust (by an integer
#' value) or reset the internal value of a condition variable.
#' \code{cv_reset} resets the internal value of a condition variable.
#'
#' @param value integer value by which to adjust the condition (counter).
#'
#' @examples
#' cv_adjust(cv, 2L)
#' cv_value(cv)
#'
#' @rdname cv
#' @export
#'
cv_adjust <- function(cv, value) invisible(.Call(rnng_cv_adjust, cv, value))

#' @param condition [default TRUE] logical value whether to reset the
#' condition (counter).
#' condition (counter) to zero.
#' @param flag [default TRUE] logical value whether to reset the flag.
#'
#' @examples
#' cv_reset(cv)
#' cv_value(cv)
#'
#' @rdname cv
#' @export
Expand Down Expand Up @@ -436,6 +422,9 @@ close.nanoPipe <- function(con, ...) invisible(.Call(rnng_pipe_close, con))
#'
#' @param socket a Socket.
#' @param cv a 'conditionVariable' to signal.
#' @param cv2 [default NULL] optionally, if specified, a second 'conditionVariable'
#' to signal. Note that this cv is signalled sequentially after the first
#' condition variable.
#' @param add [default TRUE] logical value whether to signal when a pipe is added.
#' @param remove [default TRUE] logical value whether to signal when a pipe is
#' removed.
Expand All @@ -457,18 +446,26 @@ close.nanoPipe <- function(con, ...) invisible(.Call(rnng_pipe_close, con))
#' @examples
#' s <- socket(listen = "inproc://nanopipe")
#' cv <- cv()
#' pipe_notify(s, cv, add = TRUE, remove = TRUE, flag = TRUE)
#' cv2 <- cv()
#'
#' pipe_notify(s, cv, cv2, add = TRUE, remove = TRUE, flag = TRUE)
#' cv_value(cv)
#' cv_value(cv2)
#'
#' s1 <- socket(dial = "inproc://nanopipe")
#' cv_value(cv)
#' cv_value(cv2)
#' close(s1)
#' cv_value(cv)
#' cv_value(cv2)
#'
#' (wait(cv))
#' (wait(cv2))
#'
#' close(s)
#'
#' @export
#'
pipe_notify <- function(socket, cv, add = TRUE, remove = TRUE, flag = TRUE)
invisible(.Call(rnng_pipe_notify, socket, cv, add, remove, flag))
pipe_notify <- function(socket, cv, cv2 = NULL, add = TRUE, remove = TRUE, flag = TRUE)
invisible(.Call(rnng_pipe_notify, socket, cv, cv2, add, remove, flag))

27 changes: 8 additions & 19 deletions man/cv.Rd

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

16 changes: 14 additions & 2 deletions man/pipe_notify.Rd

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

Loading

0 comments on commit fc08c77

Please sign in to comment.