locking.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* locking.h - Scute locking interface.
  2. Copyright (C) 2006 g10 Code GmbH
  3. This file is part of Scute[1].
  4. [1] Derived from the RSA Security Inc. PKCS #11 Cryptographic Token
  5. Interface (Cryptoki).
  6. Scute is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. Scute is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Scute; if not, write to the Free Software Foundation,
  16. Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. In addition, as a special exception, g10 Code GmbH gives permission
  18. to link this library: with the Mozilla Foundation's code for
  19. Mozilla (or with modified versions of it that use the same license
  20. as the "Mozilla" code), and distribute the linked executables. You
  21. must obey the GNU General Public License in all respects for all of
  22. the code used other than "Mozilla". If you modify this file, you
  23. may extend this exception to your version of the file, but you are
  24. not obligated to do so. If you do not wish to do so, delete this
  25. exception statement from your version. */
  26. #ifndef LOCKING_H
  27. #define LOCKING_H 1
  28. #include "cryptoki.h"
  29. /* The lock type. */
  30. typedef void *mutex_t;
  31. /* Initialize the locking support. ARGS is as provided to
  32. C_Initialize. */
  33. CK_RV scute_locking_initialize (CK_C_INITIALIZE_ARGS_PTR args);
  34. /* Finalize the locking support. ARGS is as provided to
  35. C_Initialize. */
  36. void scute_locking_finalize (void);
  37. /* Create a new mutex object. */
  38. CK_RV scute_mutex_create (mutex_t *mutexp);
  39. /* Destroy an existing mutex object. */
  40. CK_RV scute_mutex_destroy (mutex_t mutex);
  41. /* Lock a mutex object. */
  42. CK_RV scute_mutex_lock (mutex_t mutex);
  43. /* Unlock a mutex object. */
  44. CK_RV scute_mutex_unlock (mutex_t mutex);
  45. /* Scute is single-threaded, thus there is a single global lock taken
  46. at all entry points except for C_GetFunctionList, C_Initialize,
  47. C_Finalize and stubs. */
  48. /* The global lock. */
  49. extern mutex_t scute_lock;
  50. /* Take the global lock. */
  51. static inline CK_RV
  52. scute_global_lock (void)
  53. {
  54. return scute_mutex_lock (scute_lock);
  55. }
  56. /* Release the global lock. */
  57. static inline void
  58. scute_global_unlock (void)
  59. {
  60. (void) scute_mutex_unlock (scute_lock);
  61. }
  62. #endif /* !LOCKING_H */