Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jul 21, 2017
2 parents 297d095 + 2956d32 commit 95a61af
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/main/java/org/cactoos/func/SyncFunc.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public final class SyncFunc<X, Y> implements Func<X, Y> {
*/
private final Func<X, Y> func;

/**
* Sync lock.
*/
private final Object lck;

/**
* Ctor.
* @param runnable Func original
Expand Down Expand Up @@ -75,14 +80,23 @@ public SyncFunc(final Proc<X> proc) {
* @param fnc Func original
*/
public SyncFunc(final Func<X, Y> fnc) {
this(fnc, fnc);
}

/**
* Ctor.
* @param fnc Func original
* @param lck Sync lock
*/
public SyncFunc(final Func<X, Y> fnc, final Object lck) {
this.func = fnc;
this.lck = lck;
}

@Override
public Y apply(final X input) throws Exception {
synchronized (this.func) {
synchronized (this.lck) {
return this.func.apply(input);
}
}

}
17 changes: 16 additions & 1 deletion src/main/java/org/cactoos/func/SyncScalar.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,32 @@ public final class SyncScalar<T> implements Scalar<T> {
*/
private final Scalar<T> source;

/**
* Sync lock.
*/
private final Object lck;

/**
* Ctor.
* @param src The Scalar to cache
*/
public SyncScalar(final Scalar<T> src) {
this(src, src);
}

/**
* Ctor.
* @param src The Scalar to cache
* @param lck Sync lock
*/
public SyncScalar(final Scalar<T> src, final Object lck) {
this.source = src;
this.lck = lck;
}

@Override
public T value() throws Exception {
synchronized (this.source) {
synchronized (this.lck) {
return this.source.value();
}
}
Expand Down

0 comments on commit 95a61af

Please sign in to comment.