Skip to content

Commit

Permalink
Switch to parking_lot RwLock and Mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
locka99 committed Apr 18, 2022
1 parent 389c930 commit 4f03395
Show file tree
Hide file tree
Showing 72 changed files with 348 additions and 247 deletions.
94 changes: 81 additions & 13 deletions Cargo.lock

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

16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,21 @@ Read the [setup](./docs/setup.md) for instructions on building OPCUA for Rust.
Read [cross compilation](./docs/cross-compile.md) for hints for cross compiling OPC UA for Rust to other
platforms.

# Migrating from 0.9 and below
# Migration notes

## Migration from 0.10 and below

OPC UA for Rust uses synchronization `RwLock` and `Mutex` from the [parking_lot](https://crates.io/crates/parking_lot) crate instead
of `std`. So if you have compiler errors, replace your imports with:

```rust
use opcua::sync::*;
```

They haven't been added to the `opcua::client::prelude` or `opcua::server::prelude` in case
your code uses `std::sync` types for other reasons that you need to resolve manually.

## Migrating from 0.9 and below

OPC UA for Rust is now a single crate instead of many crates as it used to be. This makes it simpler to use, and also
maintain and publish. If you are using 0.9 or below, you will have to make some minor adjustments to use the new
Expand Down
15 changes: 8 additions & 7 deletions integration/src/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
atomic::{AtomicUsize, Ordering},
mpsc,
mpsc::channel,
Arc, Mutex, RwLock,
Arc,
},
thread, time,
};
Expand All @@ -19,6 +19,7 @@ use opcua::{
builder::ServerBuilder, callbacks, config::ServerEndpoint, prelude::*,
session::SessionManager,
},
sync::*,
};

use crate::*;
Expand Down Expand Up @@ -217,13 +218,13 @@ pub fn new_server(port: u16) -> Server {
// Allow untrusted access to the server
{
let certificate_store = server.certificate_store();
let mut certificate_store = certificate_store.write().unwrap();
let mut certificate_store = certificate_store.write();
certificate_store.set_trust_unknown_certs(true);
}

{
let address_space = server.address_space();
let mut address_space = address_space.write().unwrap();
let mut address_space = address_space.write();

// Populate the address space with some variables
let v1_node = v1_node_id();
Expand Down Expand Up @@ -558,7 +559,7 @@ pub fn regular_client_test<T>(
let session = client
.connect_to_endpoint(client_endpoint, identity_token)
.unwrap();
let session = session.read().unwrap();
let session = session.read();

// Read the variable
let mut values = {
Expand Down Expand Up @@ -592,7 +593,7 @@ pub fn invalid_session_client_test<T>(
let session = client
.connect_to_endpoint(client_endpoint, identity_token)
.unwrap();
let session = session.read().unwrap();
let session = session.read();

// Read the variable and expect that to fail
let read_nodes = vec![ReadValueId::from(v1_node_id())];
Expand Down Expand Up @@ -643,7 +644,7 @@ pub fn regular_server_test(rx_server_command: mpsc::Receiver<ServerCommand>, ser
// Tell the server to quit
{
info!("1. ------------------------ Server test received quit");
let mut server = server2.write().unwrap();
let mut server = server2.write();
server.abort();
}
// wait for server thread to quit
Expand Down Expand Up @@ -696,7 +697,7 @@ pub fn connect_with_invalid_token(

pub fn connect_with(
port: u16,
mut client_endpoint: EndpointDescription,
client_endpoint: EndpointDescription,
identity_token: IdentityToken,
) {
connect_with_client_test(
Expand Down
17 changes: 9 additions & 8 deletions integration/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
sync::{mpsc, mpsc::channel, Arc, RwLock},
sync::{mpsc, mpsc::channel, Arc},
thread,
};

Expand All @@ -8,6 +8,7 @@ use log::*;

use opcua::client::prelude::*;
use opcua::server::prelude::*;
use opcua::sync::*;

use crate::harness::*;

Expand Down Expand Up @@ -139,7 +140,7 @@ fn server_abort() {

{
// Set the abort flag
server2.write().unwrap().abort();
server2.write().abort();
}

// Wait for the message or timeout to occur
Expand Down Expand Up @@ -423,7 +424,7 @@ fn read_write_read() {

// Read the existing value
{
let session = session.read().unwrap();
let session = session.read();
let results = session
.read(&[node_id.clone().into()], TimestampsToReturn::Both, 1.0)
.unwrap();
Expand All @@ -433,7 +434,7 @@ fn read_write_read() {
}

{
let session = session.read().unwrap();
let session = session.read();
let results = session
.write(&[WriteValue {
node_id: node_id.clone(),
Expand All @@ -447,7 +448,7 @@ fn read_write_read() {
}

{
let session = session.read().unwrap();
let session = session.read();
let results = session
.read(&[node_id.into()], TimestampsToReturn::Both, 1.0)
.unwrap();
Expand All @@ -456,7 +457,7 @@ fn read_write_read() {
}

{
let session = session.read().unwrap();
let session = session.read();
session.disconnect();
}
},
Expand All @@ -481,7 +482,7 @@ fn subscribe_1000() {
let session = client
.connect_to_endpoint(client_endpoint, identity_token)
.unwrap();
let session = session.read().unwrap();
let session = session.read();

let start_time = Utc::now();

Expand Down Expand Up @@ -558,7 +559,7 @@ fn method_call() {
let session = client
.connect_to_endpoint(client_endpoint, IdentityToken::Anonymous)
.unwrap();
let session = session.read().unwrap();
let session = session.read();

// Call the method
let input_arguments = Some(vec![Variant::from("Foo")]);
Expand Down
2 changes: 2 additions & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ http = ["actix-web"]
[dependencies]
log = "0.4"
chrono = { version = "0.4", features = ["serde"] }
# Enable deadlock_detection if there are any deadlocks in sync code
parking_lot = { version = "0.12", features = ["send_guard"] }
futures = "0.3"
tokio = { version = "1", features = ["full"] }
tokio-util = { version = "0.6", features = ["codec"] }
Expand Down
Loading

0 comments on commit 4f03395

Please sign in to comment.