You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ThreadSafeDeltaCache.java 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (C) 2010, Google Inc. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.internal.storage.pack;
  11. import java.util.concurrent.locks.ReentrantLock;
  12. import org.eclipse.jgit.storage.pack.PackConfig;
  13. class ThreadSafeDeltaCache extends DeltaCache {
  14. private final ReentrantLock lock;
  15. ThreadSafeDeltaCache(PackConfig pc) {
  16. super(pc);
  17. lock = new ReentrantLock();
  18. }
  19. @Override
  20. boolean canCache(int length, ObjectToPack src, ObjectToPack res) {
  21. lock.lock();
  22. try {
  23. return super.canCache(length, src, res);
  24. } finally {
  25. lock.unlock();
  26. }
  27. }
  28. @Override
  29. void credit(int reservedSize) {
  30. lock.lock();
  31. try {
  32. super.credit(reservedSize);
  33. } finally {
  34. lock.unlock();
  35. }
  36. }
  37. @Override
  38. Ref cache(byte[] data, int actLen, int reservedSize) {
  39. data = resize(data, actLen);
  40. lock.lock();
  41. try {
  42. return super.cache(data, actLen, reservedSize);
  43. } finally {
  44. lock.unlock();
  45. }
  46. }
  47. }