mutex.lua 626 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. -- mutex.lua
  2. local mutex = {}
  3. mutex.__index = mutex
  4. --[[
  5. 构造函数,创建一个新的 fw_mutex 对象
  6. @return 返回一个新的 fw_mutex 对象
  7. ]]
  8. function mutex.new()
  9. local instance = setmetatable({}, mutex)
  10. instance.module = fw_mutex.new()
  11. return instance
  12. end
  13. --[[
  14. 加锁
  15. ]]
  16. function mutex:lock()
  17. self.module:lock()
  18. end
  19. --[[
  20. 释放锁
  21. ]]
  22. function mutex:unlock()
  23. self.module:unlock()
  24. end
  25. --[[
  26. 尝试加锁
  27. @return 是否成功加锁
  28. ]]
  29. function mutex:try_lock()
  30. return self.module:try_lock()
  31. end
  32. function mutex:self()
  33. return self.module:self()
  34. end
  35. return mutex