1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- ;;; Hoot finalization
- ;;; Copyright (C) 2024 David Thompson <dave@spritely.institute>
- ;;;
- ;;; Licensed under the Apache License, Version 2.0 (the "License");
- ;;; you may not use this file except in compliance with the License.
- ;;; You may obtain a copy of the License at
- ;;;
- ;;; http://www.apache.org/licenses/LICENSE-2.0
- ;;;
- ;;; Unless required by applicable law or agreed to in writing, software
- ;;; distributed under the License is distributed on an "AS IS" BASIS,
- ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ;;; See the License for the specific language governing permissions and
- ;;; limitations under the License.
- ;;; Commentary:
- ;;;
- ;;; Host finalization registry bindings.
- ;;;
- ;;; Code:
- (library (hoot finalization)
- (export make-finalization-registry
- finalization-registry?
- finalization-registry-register!
- finalization-registry-unregister!)
- (import (hoot eq)
- (hoot ffi)
- (hoot primitives))
- (define-foreign %make-finalization-registry
- "finalization" "make_finalization_registry"
- (ref extern) -> (ref extern))
- (define-foreign %finalization-registry-register
- "finalization" "finalization_registry_register"
- (ref extern) (ref eq) (ref eq) -> none)
- (define-foreign %finalization-registry-register/token
- "finalization" "finalization_registry_register_with_token"
- (ref extern) (ref eq) (ref eq) (ref eq) -> none)
- (define-foreign %finalization-registry-unregister
- "finalization" "finalization_registry_unregister"
- (ref extern) (ref eq) -> i32)
- (define-external-type <finalization-registry>
- finalization-registry?
- wrap-finalization-registry
- unwrap-finalization-registry)
- (define (make-finalization-registry cleanup)
- (wrap-finalization-registry
- (%make-finalization-registry (procedure->external cleanup))))
- (define* (finalization-registry-register! registry target held-value
- #:optional unregister-token)
- (if unregister-token
- (%finalization-registry-register/token (unwrap-finalization-registry registry)
- target
- held-value
- unregister-token)
- (%finalization-registry-register (unwrap-finalization-registry registry)
- target
- held-value)))
- (define (finalization-registry-unregister! registry unregister-token)
- (eq? (%finalization-registry-unregister (unwrap-finalization-registry registry)
- unregister-token)
- 1)))
|