Locking file before writing counters

Change-Id: I6367bf234160275b0afdf4623bdf8bbcd759980b