Skip to content

Commit

Permalink
revert c level developer interfaces for now
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Nov 5, 2024
1 parent 84d61ac commit a1deb15
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 107 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: nanonext
Type: Package
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
Version: 1.3.0.9003
Version: 1.3.0.9004
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
a socket library implementing 'Scalability Protocols', a reliable,
high-performance standard for common communications patterns including
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,5 @@ export(until)
export(until_)
export(wait)
export(wait_)
export(with_lock)
export(write_cert)
useDynLib(nanonext, .registration = TRUE)
10 changes: 1 addition & 9 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# nanonext 1.3.0.9003 (development)

#### New Features

* Adds `with_lock()` to evaluate an expression while holding a mutex lock to prevent concurrent access by another thread which also requires the lock.
* Exports the following C level callables for developers:
- `rnng_thread_create()` which creates a thread running a C function with signature `void (*)(void *)` that takes a single `(void *)` argument, returning an external pointer to the thread.
- `rnng_cv_lock()` which locks the mutex internal to a 'conditionVariable' (safe to use from another thread).
- `rnng_cv_unlock()` which unlocks the mutex internal to a 'conditionVariable' (safe to use from another thread).
# nanonext 1.3.0.9004 (development)

#### Updates

Expand Down
27 changes: 0 additions & 27 deletions R/sync.R
Original file line number Diff line number Diff line change
Expand Up @@ -334,30 +334,3 @@ unlock <- function(socket) invisible(.Call(rnng_socket_unlock, socket))
#' @export
#'
.online <- function(sock) .Call(rnng_read_online, sock)

#' With Lock
#'
#' Evaluate an expression whilst holding a mutex lock internal to a
#' \sQuote{conditionVariable}. The purpose of this function is to prevent
#' access to objects guarded by the same lock from another thread.
#'
#' Do not attempt to call any function using the conditionVariable \sQuote{cv}
#' in \sQuote{expr} otherwise you will create a deadlock.
#'
#' @inheritParams wait
#' @param expr an expression to evaluate under lock.
#'
#' @return The return value of \sQuote{expr}.
#'
#' @examples
#' cv <- cv()
#' with_lock(cv, "hello")
#'
#' @export
#'
with_lock <- function(cv, expr) {
.Call(rnng_cv_assert, cv)
.Call(rnng_cv_lock, cv)
on.exit(.Call(rnng_cv_unlock, cv))
expr
}
30 changes: 0 additions & 30 deletions man/with_lock.Rd

This file was deleted.

6 changes: 0 additions & 6 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,8 @@ static const R_CallMethodDef callMethods[] = {
{"rnng_ctx_create", (DL_FUNC) &rnng_ctx_create, 1},
{"rnng_ctx_open", (DL_FUNC) &rnng_ctx_open, 1},
{"rnng_cv_alloc", (DL_FUNC) &rnng_cv_alloc, 0},
{"rnng_cv_assert", (DL_FUNC) &rnng_cv_assert, 1},
{"rnng_cv_lock", (DL_FUNC) &rnng_cv_lock, 1},
{"rnng_cv_reset", (DL_FUNC) &rnng_cv_reset, 1},
{"rnng_cv_signal", (DL_FUNC) &rnng_cv_signal, 1},
{"rnng_cv_unlock", (DL_FUNC) &rnng_cv_unlock, 1},
{"rnng_cv_until", (DL_FUNC) &rnng_cv_until, 2},
{"rnng_cv_until_safe", (DL_FUNC) &rnng_cv_until_safe, 2},
{"rnng_cv_value", (DL_FUNC) &rnng_cv_value, 1},
Expand Down Expand Up @@ -209,9 +206,6 @@ void attribute_visible R_init_nanonext(DllInfo* dll) {
R_registerRoutines(dll, NULL, callMethods, NULL, externalMethods);
R_useDynamicSymbols(dll, FALSE);
R_forceSymbols(dll, TRUE);
R_RegisterCCallable("nanonext", "rnng_thread_create", (DL_FUNC) &rnng_thread_create);
R_RegisterCCallable("nanonext", "rnng_cv_lock", (DL_FUNC) &rnng_cv_lock);
R_RegisterCCallable("nanonext", "rnng_cv_unlock", (DL_FUNC) &rnng_cv_unlock);
}

// # nocov start
Expand Down
5 changes: 0 additions & 5 deletions src/nanonext.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,8 @@ SEXP rnng_ctx_close(SEXP);
SEXP rnng_ctx_create(SEXP);
SEXP rnng_ctx_open(SEXP);
SEXP rnng_cv_alloc(void);
SEXP rnng_cv_assert(SEXP);
SEXP rnng_cv_lock(SEXP);
SEXP rnng_cv_reset(SEXP);
SEXP rnng_cv_signal(SEXP);
SEXP rnng_cv_unlock(SEXP);
SEXP rnng_cv_until(SEXP, SEXP);
SEXP rnng_cv_until_safe(SEXP, SEXP);
SEXP rnng_cv_value(SEXP);
Expand Down Expand Up @@ -376,6 +373,4 @@ SEXP rnng_version(void);
SEXP rnng_wait_thread_create(SEXP);
SEXP rnng_write_cert(SEXP, SEXP, SEXP);

SEXP rnng_thread_create(void (*)(void *), void *);

#endif
25 changes: 0 additions & 25 deletions src/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,31 +398,6 @@ SEXP rnng_cv_signal(SEXP cvar) {

}

SEXP rnng_cv_assert(SEXP cvar) {

if (NANO_TAG(cvar) != nano_CvSymbol)
Rf_error("'cv' is not a valid Condition Variable");

return nano_success;

}

SEXP rnng_cv_lock(SEXP cvar) {

nng_mtx_lock(((nano_cv *) NANO_PTR(cvar))->mtx);

return nano_success;

}

SEXP rnng_cv_unlock(SEXP cvar) {

nng_mtx_unlock(((nano_cv *) NANO_PTR(cvar))->mtx);

return nano_success;

}

// request ---------------------------------------------------------------------

SEXP rnng_request(SEXP con, SEXP data, SEXP sendmode, SEXP recvmode, SEXP timeout, SEXP cvar, SEXP clo) {
Expand Down
2 changes: 1 addition & 1 deletion src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void thread_finalizer(SEXP xptr) {

}

SEXP rnng_thread_create(void (*func)(void *), void *arg) {
static SEXP rnng_thread_create(void (*func)(void *), void *arg) {

nng_thread *thr;
int xc;
Expand Down
2 changes: 0 additions & 2 deletions tests/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,6 @@ test_zero(close(s2))
test_zero(close(s3))

test_type("externalptr", cv <- cv())
test_equal(with_lock(cv, "hello"), "hello")
test_error(with_lock("cv", "hello"), "valid Condition Variable")
test_error(.dispatcher(host = "inproc://hostdisp", url = "inproc://disp/1", tls = ""), "not a valid TLS Configuration")
test_type("externalptr", disp <- .dispatcher(host = "inproc://hostdisp", url = "inproc://disp/1", tls = NULL))
test_zero(.online(disp))
Expand Down

0 comments on commit a1deb15

Please sign in to comment.