lock_pthread.c 805 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <stdlib.h>
  2. #include "mallocvar.h"
  3. #include "pthreadx.h"
  4. #include "lock.h"
  5. #include "lock_pthread.h"
  6. static lockAcquireFn acquire;
  7. static void
  8. acquire(struct lock * const lockP) {
  9. pthread_mutex_lock(&lockP->theLock);
  10. }
  11. static lockReleaseFn release;
  12. static void
  13. release(struct lock * const lockP) {
  14. pthread_mutex_unlock(&lockP->theLock);
  15. }
  16. static lockDestroyFn destroy;
  17. static void
  18. destroy(struct lock * const lockP) {
  19. pthread_mutex_destroy(&lockP->theLock);
  20. free(lockP);
  21. }
  22. struct lock *
  23. curlLock_create_pthread(void) {
  24. struct lock * lockP;
  25. MALLOCVAR(lockP);
  26. if (lockP) {
  27. pthread_mutex_init(&lockP->theLock, NULL);
  28. lockP->acquire = &acquire;
  29. lockP->release = &release;
  30. lockP->destroy = &destroy;
  31. }
  32. return lockP;
  33. }