package ru.job4j.wait;


/**
 * Class <Name class>.
 *
 * @author Alexey Rastorguev (rastorguev00@gmail.com)
 * @version 0.1
 * @since 11.02.2018
 */
public class SimpleLock {
    private boolean block = false;

    public void lock() {
        if (block) {
            try {
                Thread.currentThread().wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } else {
            block = true;
        }
    }

    public void unlock() {
        if (block) {
            block = false;
            Thread.currentThread().notifyAll();
        }
    }

}

@@ -208,51 +208,199 @@
 se;%0A
-%0A    public void lock() %7B%0A        if (block
+    private Thread lockThred = null;%0A    private int lockCount = 0;%0A%0A    public void lock() %7B%0A        Thread curThread = Thread.currentThread();%0A        while (block && lockThred != curThread
 ) %7B%0A
@@ -433,39 +433,16 @@
         
-Thread.currentThread().
 wait();%0A
@@ -552,20 +552,9 @@
    %7D
- else %7B%0A    
+%0A
     
@@ -571,33 +571,75 @@
 = true;%0A        
-%7D
+lockCount++;%0A        lockThred = curThread;
 %0A    %7D%0A%0A    publ
@@ -669,21 +669,121 @@
     if (
-block
+Thread.currentThread() == this.lockThred) %7B%0A            lockCount--;%0A        %7D%0A        if (lockCount == 0
 ) %7B%0A    
@@ -821,40 +821,14 @@
     
-Thread.currentThread().
 notify
-All
 ();%0A

modify block Lock [task #1100]