1
subroutine addref_scalar_field(object)
2
!!< Increment the reference count of object creating a new reference
4
type(scalar_field), intent(inout), target :: object
5
integer, save :: id = 0
7
if (associated(object%refcount)) then
8
! Reference count already exists, just increment it.
9
object%refcount%count=object%refcount%count+1
13
object%refcount=>new_refcount("&
14
&scalar_field", object%name)
15
object%refcount%id = id
18
end subroutine addref_scalar_field
20
subroutine incref_scalar_field(object)
21
!!< Increment the reference count of object. If there are no references
23
type(scalar_field), intent(in), target :: object
24
integer, pointer :: ptr !! Dummy pointer to evade compilers which
25
!! don't understand the rules for intent.
27
if (.not.associated(object%refcount)) then
28
FLAbort ("Attempt to incref scalar_field "//trim(object%name)//" which has no references")
31
! Reference count already exists, just increment it.
32
ptr=>object%refcount%count
35
end subroutine incref_scalar_field
37
subroutine decref_scalar_field(object)
38
!!< Decrement the reference count on object. If the reference count drops
39
!!< to 0 deallocate the refcount as a hint to the calling routine that
40
!!< the object can safely be deallocated.
41
type(scalar_field), intent(inout) :: object
43
if (.not.associated(object%refcount)) then
44
! No refcount. Just exit
48
object%refcount%count=object%refcount%count-1
50
if (object%refcount%count<=0) then
52
if (object%refcount%count<0) then
53
! Warn for negative reference count
54
ewrite(0,'(a, i0)') "Reference count of &
55
&scalar_field "//trim(object%name)//&
56
" is ", object%refcount%count
57
FLAbort("that should never happen.")
60
object%refcount%prev%next=>object%refcount%next
61
if (associated(object%refcount%next)) then
62
object%refcount%next%prev=>object%refcount%prev
65
deallocate(object%refcount)
69
end subroutine decref_scalar_field
71
pure function has_references_scalar_field(object) result (has_references)
72
!!< Return true if there are any references to object
73
type(scalar_field), intent(in) :: object
74
logical :: has_references
76
has_references=associated(object%refcount)
78
end function has_references_scalar_field