[sgen] Move the mono_gchandle_ functions to sgen-mono.c for consistency, add sgen_gch...
authorZoltan Varga <vargaz@gmail.com>
Tue, 29 Aug 2017 01:37:08 +0000 (21:37 -0400)
committerGitHub <noreply@github.com>
Tue, 29 Aug 2017 01:37:08 +0000 (21:37 -0400)
mono/metadata/sgen-mono.c
mono/sgen/sgen-gc.h
mono/sgen/sgen-gchandles.c

index 8604d9321a0aa47e35178ebb6013b3e48fb5cd6c..7f2a233401d7da565051c04dbd08f7faf851c95d 100644 (file)
@@ -2665,6 +2665,54 @@ sgen_client_metadata_for_object (GCObject *obj)
        return mono_object_domain (obj);
 }
 
+/**
+ * mono_gchandle_new:
+ * \param obj managed object to get a handle for
+ * \param pinned whether the object should be pinned
+ * This returns a handle that wraps the object, this is used to keep a
+ * reference to a managed object from the unmanaged world and preventing the
+ * object from being disposed.
+ * 
+ * If \p pinned is false the address of the object can not be obtained, if it is
+ * true the address of the object can be obtained.  This will also pin the
+ * object so it will not be possible by a moving garbage collector to move the
+ * object. 
+ * 
+ * \returns a handle that can be used to access the object from unmanaged code.
+ */
+guint32
+mono_gchandle_new (MonoObject *obj, gboolean pinned)
+{
+       return sgen_gchandle_new (obj, pinned);
+}
+
+/**
+ * mono_gchandle_new_weakref:
+ * \param obj managed object to get a handle for
+ * \param track_resurrection Determines how long to track the object, if this is set to TRUE, the object is tracked after finalization, if FALSE, the object is only tracked up until the point of finalization.
+ *
+ * This returns a weak handle that wraps the object, this is used to
+ * keep a reference to a managed object from the unmanaged world.
+ * Unlike the \c mono_gchandle_new the object can be reclaimed by the
+ * garbage collector.  In this case the value of the GCHandle will be
+ * set to zero.
+ * 
+ * If \p track_resurrection is TRUE the object will be tracked through
+ * finalization and if the object is resurrected during the execution
+ * of the finalizer, then the returned weakref will continue to hold
+ * a reference to the object.   If \p track_resurrection is FALSE, then
+ * the weak reference's target will become NULL as soon as the object
+ * is passed on to the finalizer.
+ * 
+ * \returns a handle that can be used to access the object from
+ * unmanaged code.
+ */
+guint32
+mono_gchandle_new_weakref (GCObject *obj, gboolean track_resurrection)
+{
+       return sgen_gchandle_new_weakref (obj, track_resurrection);
+}
+
 /**
  * mono_gchandle_is_in_domain:
  * \param gchandle a GCHandle's handle.
@@ -2678,6 +2726,20 @@ mono_gchandle_is_in_domain (guint32 gchandle, MonoDomain *domain)
        return domain->domain_id == gchandle_domain->domain_id;
 }
 
+/**
+ * mono_gchandle_free:
+ * \param gchandle a GCHandle's handle.
+ *
+ * Frees the \p gchandle handle.  If there are no outstanding
+ * references, the garbage collector can reclaim the memory of the
+ * object wrapped. 
+ */
+void
+mono_gchandle_free (guint32 gchandle)
+{
+       sgen_gchandle_free (gchandle);
+}
+
 /**
  * mono_gchandle_free_domain:
  * \param unloading domain that is unloading
@@ -2690,6 +2752,22 @@ mono_gchandle_free_domain (MonoDomain *unloading)
 {
 }
 
+/**
+ * mono_gchandle_get_target:
+ * \param gchandle a GCHandle's handle.
+ *
+ * The handle was previously created by calling \c mono_gchandle_new or
+ * \c mono_gchandle_new_weakref. 
+ *
+ * \returns a pointer to the \c MonoObject* represented by the handle or
+ * NULL for a collected object if using a weakref handle.
+ */
+MonoObject*
+mono_gchandle_get_target (guint32 gchandle)
+{
+       return sgen_gchandle_get_target (gchandle);
+}
+
 static gpointer
 null_link_if_in_domain (gpointer hidden, GCHandleType handle_type, int max_generation, gpointer user)
 {
index 3e2620b219fdfca712a8afec98468c49b63945b7..4ed1ec495f98cd7ba2d87e689458aab47ecbd979 100644 (file)
@@ -968,10 +968,14 @@ void sgen_null_links_if (SgenObjectPredicateFunc predicate, void *data, int gene
 
 typedef gpointer (*SgenGCHandleIterateCallback) (gpointer hidden, GCHandleType handle_type, int max_generation, gpointer user);
 
+guint32 sgen_gchandle_new (GCObject *obj, gboolean pinned);
+guint32 sgen_gchandle_new_weakref (GCObject *obj, gboolean track_resurrection);
 void sgen_gchandle_iterate (GCHandleType handle_type, int max_generation, SgenGCHandleIterateCallback callback, gpointer user);
 void sgen_gchandle_set_target (guint32 gchandle, GCObject *obj);
 void sgen_mark_normal_gc_handles (void *addr, SgenUserMarkFunc mark_func, void *gc_data);
 gpointer sgen_gchandle_get_metadata (guint32 gchandle);
+GCObject *sgen_gchandle_get_target (guint32 gchandle);
+void sgen_gchandle_free (guint32 gchandle);
 
 /* Other globals */
 
index 555d5bf483f68db8dc8f02f59fec6d389f129f5b..ba7259f50f9bd9a77e3317ff4d3090ec6f21011b 100644 (file)
@@ -202,50 +202,14 @@ sgen_gchandle_iterate (GCHandleType handle_type, int max_generation, SgenGCHandl
        } SGEN_ARRAY_LIST_END_FOREACH_SLOT;
 }
 
-/**
- * mono_gchandle_new:
- * \param obj managed object to get a handle for
- * \param pinned whether the object should be pinned
- * This returns a handle that wraps the object, this is used to keep a
- * reference to a managed object from the unmanaged world and preventing the
- * object from being disposed.
- * 
- * If \p pinned is false the address of the object can not be obtained, if it is
- * true the address of the object can be obtained.  This will also pin the
- * object so it will not be possible by a moving garbage collector to move the
- * object. 
- * 
- * \returns a handle that can be used to access the object from unmanaged code.
- */
 guint32
-mono_gchandle_new (GCObject *obj, gboolean pinned)
+sgen_gchandle_new (GCObject *obj, gboolean pinned)
 {
        return alloc_handle (gc_handles_for_type (pinned ? HANDLE_PINNED : HANDLE_NORMAL), obj, FALSE);
 }
 
-/**
- * mono_gchandle_new_weakref:
- * \param obj managed object to get a handle for
- * \param track_resurrection Determines how long to track the object, if this is set to TRUE, the object is tracked after finalization, if FALSE, the object is only tracked up until the point of finalization.
- *
- * This returns a weak handle that wraps the object, this is used to
- * keep a reference to a managed object from the unmanaged world.
- * Unlike the \c mono_gchandle_new the object can be reclaimed by the
- * garbage collector.  In this case the value of the GCHandle will be
- * set to zero.
- * 
- * If \p track_resurrection is TRUE the object will be tracked through
- * finalization and if the object is resurrected during the execution
- * of the finalizer, then the returned weakref will continue to hold
- * a reference to the object.   If \p track_resurrection is FALSE, then
- * the weak reference's target will become NULL as soon as the object
- * is passed on to the finalizer.
- * 
- * \returns a handle that can be used to access the object from
- * unmanaged code.
- */
 guint32
-mono_gchandle_new_weakref (GCObject *obj, gboolean track_resurrection)
+sgen_gchandle_new_weakref (GCObject *obj, gboolean track_resurrection)
 {
        return alloc_handle (gc_handles_for_type (track_resurrection ? HANDLE_WEAK_TRACK : HANDLE_WEAK), obj, track_resurrection);
 }
@@ -292,18 +256,8 @@ retry:
        return obj;
 }
 
-/**
- * mono_gchandle_get_target:
- * \param gchandle a GCHandle's handle.
- *
- * The handle was previously created by calling \c mono_gchandle_new or
- * \c mono_gchandle_new_weakref. 
- *
- * \returns a pointer to the \c MonoObject* represented by the handle or
- * NULL for a collected object if using a weakref handle.
- */
 GCObject*
-mono_gchandle_get_target (guint32 gchandle)
+sgen_gchandle_get_target (guint32 gchandle)
 {
        guint index = MONO_GC_HANDLE_SLOT (gchandle);
        GCHandleType type = MONO_GC_HANDLE_TYPE (gchandle);
@@ -382,16 +336,8 @@ sgen_gchandle_get_metadata (guint32 gchandle)
        return mono_gchandle_slot_metadata (slot, MONO_GC_HANDLE_TYPE_IS_WEAK (type));
 }
 
-/**
- * mono_gchandle_free:
- * \param gchandle a GCHandle's handle.
- *
- * Frees the \p gchandle handle.  If there are no outstanding
- * references, the garbage collector can reclaim the memory of the
- * object wrapped. 
- */
 void
-mono_gchandle_free (guint32 gchandle)
+sgen_gchandle_free (guint32 gchandle)
 {
        guint32 index = MONO_GC_HANDLE_SLOT (gchandle);
        GCHandleType type = MONO_GC_HANDLE_TYPE (gchandle);