compat_mutex.c 989 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* Copyright (c) 2003-2004, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. /**
  6. * \file compat_mutex.c
  7. *
  8. * \brief Portable wrapper for platform mutex implementations.
  9. **/
  10. #include "lib/lock/compat_mutex.h"
  11. #include "lib/malloc/util_malloc.h"
  12. /** Return a newly allocated, ready-for-use mutex. */
  13. tor_mutex_t *
  14. tor_mutex_new(void)
  15. {
  16. tor_mutex_t *m = tor_malloc_zero(sizeof(tor_mutex_t));
  17. tor_mutex_init(m);
  18. return m;
  19. }
  20. /** Return a newly allocated, ready-for-use mutex. This one might be
  21. * non-recursive, if that's faster. */
  22. tor_mutex_t *
  23. tor_mutex_new_nonrecursive(void)
  24. {
  25. tor_mutex_t *m = tor_malloc_zero(sizeof(tor_mutex_t));
  26. tor_mutex_init_nonrecursive(m);
  27. return m;
  28. }
  29. /** Release all storage and system resources held by <b>m</b>. */
  30. void
  31. tor_mutex_free_(tor_mutex_t *m)
  32. {
  33. if (!m)
  34. return;
  35. tor_mutex_uninit(m);
  36. tor_free(m);
  37. }