compat_mutex.c 889 B

12345678910111213141516171819202122232425262728293031323334
  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. #include "lib/lock/compat_mutex.h"
  6. #include "lib/malloc/util_malloc.h"
  7. /** Return a newly allocated, ready-for-use mutex. */
  8. tor_mutex_t *
  9. tor_mutex_new(void)
  10. {
  11. tor_mutex_t *m = tor_malloc_zero(sizeof(tor_mutex_t));
  12. tor_mutex_init(m);
  13. return m;
  14. }
  15. /** Return a newly allocated, ready-for-use mutex. This one might be
  16. * non-recursive, if that's faster. */
  17. tor_mutex_t *
  18. tor_mutex_new_nonrecursive(void)
  19. {
  20. tor_mutex_t *m = tor_malloc_zero(sizeof(tor_mutex_t));
  21. tor_mutex_init_nonrecursive(m);
  22. return m;
  23. }
  24. /** Release all storage and system resources held by <b>m</b>. */
  25. void
  26. tor_mutex_free_(tor_mutex_t *m)
  27. {
  28. if (!m)
  29. return;
  30. tor_mutex_uninit(m);
  31. tor_free(m);
  32. }