port.lisp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. (in-package :hurd)
  2. ;;
  3. ;; This file implements a port abstraction like port_info from libports.
  4. ;; A port-info has send count and a receive right, we can also get new rights from it.
  5. ;;
  6. (defclass port-info ()
  7. ((right :initform (port-allocate :right-receive)
  8. :accessor port-right
  9. :documentation "Right for this port")
  10. (mscount :initform 0
  11. :accessor mscount
  12. :documentation "Send rights count")))
  13. (defmethod deallocate-send-right ((port port-info))
  14. "Deallocates the port's send right."
  15. (port-deallocate (port-right port)))
  16. (defmethod get-right ((port port-info))
  17. "Gives the port right, incrementing the send count and requesting a notification when it goes away."
  18. (when (zerop (mscount port))
  19. (port-request-notification (port-right port)
  20. :notify-no-senders
  21. (1+ (mscount port))
  22. (port-right port)
  23. :make-send-once))
  24. (incf (mscount port))
  25. (port-right port))
  26. (defmethod get-send-right ((port port-info))
  27. "Gets a send right for 'port'."
  28. (let ((right (get-right port)))
  29. (port-insert-right right right :make-send)
  30. right))
  31. (defmethod port-cleanup ((port port-info))
  32. "Cleanup routine for ports."
  33. (when (port-right port)
  34. (setf (mscount port) 0)
  35. (port-mod-refs (port-right port) :right-receive -1)
  36. (setf (port-right port) nil))
  37. t)