public static void Write(UnsafeWriter writer, InjectedHlslLocationInfo value) { UnsafeMarshallers.FileSystemPathMarshaller.Marshal(writer, value.FileSystemPath); writer.Write(value.Range.StartOffset); writer.Write(value.Range.EndOffset); writer.WriteEnum(value.ProgramType); }
public void Test1() { while (NativeMemoryPool.TryFreeMemory()) { } var th = new Thread(() => { using (var cookie = UnsafeWriter.NewThreadLocalWriter()) { cookie.Writer.Write(false); Assert.AreEqual(1, NativeMemoryPool.SampleUsed()); } Assert.AreEqual(1, NativeMemoryPool.SampleCount()); }); th.Start(); th.Join(); Assert.AreEqual(0, NativeMemoryPool.SampleUsed()); SpinWait.SpinUntil(() => { if (NativeMemoryPool.SampleCount() > 0) { GC.Collect(); } else { return(true); } return(false); }, 1000); Assert.AreEqual(0, NativeMemoryPool.SampleCount()); }
public void M() { using (var y = UnsafeWriter.NewThreadLocalWriter()) { y.Writer.Write("hhhhdd"); } }
private static void WriteTestAnchorToUsageEntry([NotNull] UnsafeWriter writer, long anchor, [NotNull] IAnimatorScriptUsage usage) { writer.Write(anchor); usage.WriteTo(writer); }
private void Ping() { try { Log.Trace()?.Log($"{Id}: send PING " + $"currentTimeStamp: {myCurrentTimeStamp}, " + $"counterpartTimestamp: {myCounterpartTimestamp}, " + $"counterpartNotionTimestamp: {myCounterpartNotionTimestamp}"); if (!ConnectionEstablished(myCurrentTimeStamp, myCounterpartNotionTimestamp)) { HeartbeatAlive.Value = false; } using (var cookie = UnsafeWriter.NewThreadLocalWriter()) { cookie.Writer.Write(PING_LEN); cookie.Writer.Write(myCurrentTimeStamp); cookie.Writer.Write(myCounterpartTimestamp); cookie.CopyTo(myPingPkgHeader); } lock (mySocketSendLock) Socket.Send(myPingPkgHeader); ++myCurrentTimeStamp; } catch (ObjectDisposedException) { Log.Verbose($"{Id}: Socket was disposed during PING"); } catch (Exception e) { Log.Warn(e, $"{Id}: {e.GetType()} raised during PING"); } }
private void SendAck(long seqN) { try { using (var cookie = UnsafeWriter.NewThreadLocalWriter()) { cookie.Writer.Write(ACK_MSG_LEN); cookie.Writer.Write(seqN); cookie.CopyTo(myAckPkgHeader); } lock (mySocketSendLock) Socket.Send(myAckPkgHeader); } catch (ObjectDisposedException) { Log.Verbose($"{Id}: Socket was disposed during ACK, seqn = {seqN}"); } catch (SocketException e) { // looks like this does not deserve a warn, as the only thing that can happen is a fatal socket failure anyway, and that will likely be reported properly from other threads Log.Verbose(e, $"{Id}: ${e.GetType()} raised during ACK, seqn = {seqN}"); } catch (Exception e) { Log.Warn(e, $"{Id}: {e.GetType()} raised during ACK, seqn = {seqN}"); } }
public void WriteValue(SerializationCtx context, UnsafeWriter writer) { Assertion.Assert(!myHandler.IsSendWithoutContexts, "!myHandler.IsWritingOwnMessages"); var value = Context.Value; if (value == null) { InternId.Write(writer, InternId.Invalid); writer.Write(false); } else { using (myHandler.CreateSendWithoutContextsCookie()) { AddValueToProtocolValueSetImpl(value); var internedId = myInternRoot.Intern(value); InternId.Write(writer, internedId); if (!internedId.IsValid) { writer.Write(true); Context.WriteDelegate(context, writer, value); } } } }
public void TestWriterIsReused02() { UnsafeWriter firstWriter = null, secondWriter = null; var thread = new Thread(() => { UnsafeWriter.AllowUnsafeWriterCaching = true; try { using (var cookie = UnsafeWriter.NewThreadLocalWriter()) { firstWriter = cookie.Writer; } using (var cookie = UnsafeWriter.NewThreadLocalWriterNoCaching()) { secondWriter = cookie.Writer; } } finally { UnsafeWriter.AllowUnsafeWriterCaching = false; } }); thread.Start(); thread.Join(); Assert.IsNotNull(firstWriter, "firstWriter != null"); Assert.IsNotNull(secondWriter, "secondWriter != null"); Assert.IsTrue(ReferenceEquals(firstWriter, secondWriter), "object.ReferenceEquals(firstWriter, secondWriter)"); }
public static void WriteNullableStruct <T>(this UnsafeWriter writer, CtxWriteDelegate <T> itemWriter, SerializationCtx ctx, T?value) where T : struct { if (writer.WriteNullness(value)) { itemWriter(ctx, writer, value.Value); } }
public void ReportReentrancy02() { var thread = new Thread(() => { UnsafeWriter.AllowUnsafeWriterCaching = true; UnsafeWriterStatistics.ClearEvents(); UnsafeWriterStatistics.ReportReentrancy = true; try { using (var cookie = UnsafeWriter.NewThreadLocalWriter()) { using (var nestedCookie = UnsafeWriter.NewThreadLocalWriter()) cookie.Writer.Write(0); } } finally { UnsafeWriterStatistics.ReportReentrancy = false; } }); thread.Start(); thread.Join(); var reentrancyEvent = UnsafeWriterStatistics.GetEvents().First(@event => @event.Type == UnsafeWriterStatistics.EventType.REENTRANCY); Assert.IsTrue(reentrancyEvent.Stacktraces.Count == 2, "reentrancyEvent.Stacktraces.Count == 2"); }
public static void Write(UnsafeWriter writer, TransformHierarchy transformHierarchy) { transformHierarchy.Location.WriteTo(writer); transformHierarchy.OwningGameObject.WriteTo(writer); transformHierarchy.ParentTransform.WriteTo(writer); writer.Write(transformHierarchy.myRootIndex); }
public void WriteValue(SerializationCtx context, UnsafeWriter writer) { Assertion.Assert(!myHandler.IsSendWithoutContexts, "!myHandler.IsWritingOwnMessages"); var value = Context.Value; if (value == null) { InternId.Write(writer, InternId.Invalid); writer.Write(false); } else { using (myHandler.CreateSendWithoutContextsCookie()) { if (!myProtocolValueSet.Contains(value)) { Assertion.Require(Proto.Scheduler.IsActive, "Attempting to use previously unused context value {0} on a background thread for key {1}", value, Context.Key); myProtocolValueSet.Add(Context.Value); } var internedId = myInternRoot.Intern(value); InternId.Write(writer, internedId); if (!internedId.IsValid) { writer.Write(true); Context.WriteDelegate(context, writer, value); } } } }
public void TestFreeMemoryStress() { bool run = true; var thread = new Thread(() => { while (run) { NativeMemoryPool.TryFreeMemory(); } }); thread.Start(); var sw = Stopwatch.StartNew(); while (sw.ElapsedMilliseconds < 500) { using (var cookie = UnsafeWriter.NewThreadLocalWriter()) { cookie.Writer.Write(1); } using (var cookie = UnsafeWriter.NewThreadLocalWriter()) { cookie.Writer.Write(1); } } run = false; thread.Join(); }
private static void Write(UnsafeWriter writer, UnitySceneData value) { PropertiesDataMarshaller.Marshal(writer, value.PropertiesData); EventHandlersMarshaller.Marshal(writer, value.ShortNameToScriptFileId); ScriptToGuidMarshaller.Marshal(writer, value.ScriptMapping); value.SceneHierarchy.WriteTo(writer); }
public void Write <T>(SerializationCtx ctx, UnsafeWriter writer, T value) { #if !NET35 myBackgroundRegistrar.WaitForEmpty(); #endif if (value == null) { // ReSharper disable once ImpureMethodCallOnReadonlyValueField RdId.Nil.Write(writer); return; } RdId typeId; var type = value.GetType(); if (!myTypeMapping.TryGetValue(type, out typeId)) { myPolymorphicCatalog?.TryDiscoverRegister(type, this); if (!myTypeMapping.TryGetValue(type, out typeId)) { throw new KeyNotFoundException($"Type {type.FullName} have not registered"); } } typeId.Write(writer); // Don't dispose this cookie, otherwise it will delete all written data var cookie = new UnsafeWriter.Cookie(writer); writer.Write(0); var writerDelegate = myWriters[typeId]; writerDelegate(ctx, writer, value); cookie.WriteIntLengthToCookieStart(); }
private static void Write(UnsafeWriter writer, ProjectSettingsCacheItem value) { value.Scenes.Write(writer); WriteSet(writer, value.Inputs); WriteSet(writer, value.Tags); WriteSet(writer, value.Layers); }
private static void Write(UnsafeWriter writer, AssetDocumentHierarchyElement value) { writer.Write(value.myOtherBoxedElements.Count); writer.Write(value.myGameObjectHierarchies.Count); writer.Write(value.myTransformElements.Count); writer.Write(value.myScriptComponentElements.Count); writer.Write(value.myComponentElements.Count); foreach (var v in value.myOtherBoxedElements) { WriteHierarchyElement(writer, v); } foreach (var v in value.myGameObjectHierarchies) { GameObjectHierarchy.Write(writer, v); } foreach (var v in value.myTransformElements) { TransformHierarchy.Write(writer, v); } foreach (var v in value.myScriptComponentElements) { ScriptComponentHierarchy.Write(writer, v); } foreach (var v in value.myComponentElements) { ComponentHierarchy.Write(writer, v); } }
private static void Write(UnsafeWriter writer, InspectorVariableUsage value) { value.Location.WriteTo(writer); value.ScriptReference.WriteTo(writer); writer.Write(value.Name); writer.WritePolymorphic(value.Value); }
public static void WriteNullableClass <T>(this UnsafeWriter writer, CtxWriteDelegate <T> itemWriter, SerializationCtx ctx, T value) where T : class { if (writer.WriteNullness(value)) { itemWriter(ctx, writer, value); } }
public static void WriteDelegate(UnsafeWriter writer, UnityAssetData value) { writer.Write(value.UnityAssetDataElements.Count); foreach (var v in value.UnityAssetDataElements.Values) { writer.WritePolymorphic(v); } }
private static void Write(UnsafeWriter writer, AssetInspectorValuesDataElement value) { writer.Write(value.VariableUsages.Count); foreach (var v in value.VariableUsages) { writer.WritePolymorphic(v); } }
private static void Write(UnsafeWriter writer, AssetMethodsDataElement value) { writer.Write(value.Methods.Count); foreach (var v in value.Methods) { v.WriteTo(writer); } }
public void Write(UnsafeWriter writer) { writer.Write(Name); writer.Write(Type); writer.Write(IsOptional); writer.Write(Description); writer.Write(DefaultValue); }
private static void Write(UnsafeWriter writer, AssetUsagesDataElement value) { writer.Write(value.myAssetUsages.Count); foreach (var v in value.myAssetUsages) { v.WriteTo(writer); } }
public static void WriteEnum <T>(SerializationCtx ctx, UnsafeWriter writer, T value) where T : #if !NET35 unmanaged, #endif Enum { writer.Write(Cast32BitEnum <T> .ToInt(value)); }
private static void Write(UnsafeWriter writer, GameObjectHierarchy value) { writer.WritePolymorphic(value.Location); writer.Write(value.Name); writer.WritePolymorphic(value.PrefabInstance); writer.WritePolymorphic(value.CorrespondingSourceObject); writer.Write(value.IsStripped); }
private static void WriteSet(UnsafeWriter writer, JetHashSet <string> list) { writer.Write(list.Count); foreach (var value in list) { writer.Write(value); } }
private static void WriteAnchors([NotNull] UnsafeWriter writer, LocalList <long> anchors) { writer.Write(anchors.Count); foreach (var anchor in anchors) { writer.Write(anchor); } }
public void Write(UnsafeWriter writer) { writer.Write(Name); writer.Write(Type); writer.Write(IsOptional); writer.Write(Description); writer.Write(DefaultValue); }
public void WriteTo(UnsafeWriter writer) { Location.WriteTo(writer); writer.Write(Name); WriteAnchors(writer, ScriptsAnchors); WriteAnchors(writer, ChildStateMachinesAnchors); WriteAnchors(writer, ChildStatesAnchors); }
private void PutLong(ByteBufferAsyncProcessor buffer, long l) { using (var cookie = UnsafeWriter.NewThreadLocalWriter()) { cookie.Writer.Write(l); buffer.Put(cookie); } }
public void Write(UnsafeWriter writer) { writer.Write(OriginalName); writer.Write(Name); writer.Write(Restrictions); writer.Write(UnsafeWriter.StringDelegate, Tags); writer.Write(Offset); writer.Write<Parameter, ICollection<Parameter>>((w, parameter) => parameter.Write(w), Parameters.ToList()); }
private static void Write(UnsafeWriter writer, AngularJsCacheItems value) { writer.Write<Directive, ICollection<Directive>>((w, directive) => directive.Write(w), value.Directives.ToList()); writer.Write<Filter, ICollection<Filter>>((w, filter) => filter.Write(w), value.Filters.ToList()); }
public void Write(UnsafeWriter writer) { writer.Write(Name); writer.Write(Offset); }