Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TryWrite()

override bool System.Threading.Channels.BoundedChannel< T >.BoundedChannelWriter.TryWrite ( T item)
inline

Definition at line 221 of file BoundedChannel.cs.

222 {
225 BoundedChannel<T> parent = _parent;
226 bool lockTaken = false;
227 try
228 {
229 Monitor.Enter(parent.SyncObj, ref lockTaken);
230 if (parent._doneWriting != null)
231 {
232 return false;
233 }
234 int count = parent._items.Count;
235 if (count != 0)
236 {
237 if (count < parent._bufferedCapacity)
238 {
239 parent._items.EnqueueTail(item);
240 return true;
241 }
242 if (parent._mode == BoundedChannelFullMode.Wait)
243 {
244 return false;
245 }
246 if (parent._mode == BoundedChannelFullMode.DropWrite)
247 {
248 Monitor.Exit(parent.SyncObj);
249 lockTaken = false;
250 parent._itemDropped?.Invoke(item);
251 return true;
252 }
253 T obj = ((parent._mode == BoundedChannelFullMode.DropNewest) ? parent._items.DequeueTail() : parent._items.DequeueHead());
254 parent._items.EnqueueTail(item);
255 Monitor.Exit(parent.SyncObj);
256 lockTaken = false;
257 parent._itemDropped?.Invoke(obj);
258 return true;
259 }
260 while (!parent._blockedReaders.IsEmpty)
261 {
262 AsyncOperation<T> asyncOperation2 = parent._blockedReaders.DequeueHead();
263 if (asyncOperation2.UnregisterCancellation())
264 {
266 break;
267 }
268 }
269 if (asyncOperation == null)
270 {
271 parent._items.EnqueueTail(item);
272 listTail = parent._waitingReadersTail;
273 if (listTail == null)
274 {
275 return true;
276 }
277 parent._waitingReadersTail = null;
278 }
279 }
280 finally
281 {
282 if (lockTaken)
283 {
284 Monitor.Exit(parent.SyncObj);
285 }
286 }
287 if (asyncOperation != null)
288 {
289 bool flag = asyncOperation.TrySetResult(item);
290 }
291 else
292 {
293 ChannelUtilities.WakeUpWaiters(ref listTail, result: true);
294 }
295 return true;
296 }

References System.Threading.Channels.BoundedChannel< T >.BoundedChannelWriter._parent, System.count, System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Threading.Monitor.Enter(), System.Threading.Monitor.Exit(), System.item, System.obj, and System.Threading.Channels.ChannelUtilities.WakeUpWaiters().