1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_netwerk_socket_nsNamedPipeService_h
7 #define mozilla_netwerk_socket_nsNamedPipeService_h
10 #include "mozilla/Atomics.h"
11 #include "mozilla/Mutex.h"
12 #include "nsINamedPipeService.h"
13 #include "nsIObserver.h"
14 #include "nsIRunnable.h"
15 #include "nsIThread.h"
17 #include "mozilla/StaticPtr.h"
22 class NamedPipeService final
: public nsINamedPipeService
,
26 NS_DECL_THREADSAFE_ISUPPORTS
27 NS_DECL_NSINAMEDPIPESERVICE
31 static already_AddRefed
<nsINamedPipeService
> GetOrCreate();
34 explicit NamedPipeService();
35 virtual ~NamedPipeService() = default;
40 void RemoveRetiredObjects();
42 HANDLE mIocp
; // native handle to the I/O completion port.
44 mIsShutdown
; // set to true to stop the event loop running by mThread.
45 nsCOMPtr
<nsIThread
> mThread
; // worker thread to get I/O events.
48 * The observers is maintained in |mObservers| to ensure valid life-cycle.
49 * We don't remove the handle and corresponding observer directly, instead
50 * the handle and observer into a "retired" list and close/remove them in
51 * the worker thread to avoid a race condition that might happen between
52 * |CloseHandle()| and |GetQueuedCompletionStatus()|.
54 Mutex mLock MOZ_UNANNOTATED
;
55 nsTArray
<nsCOMPtr
<nsINamedPipeDataObserver
>>
56 mObservers
; // protected by mLock
57 nsTArray
<nsCOMPtr
<nsINamedPipeDataObserver
>>
58 mRetiredObservers
; // protected by mLock
59 nsTArray
<HANDLE
> mRetiredHandles
; // protected by mLock
61 static StaticRefPtr
<NamedPipeService
> gSingleton
;
65 } // namespace mozilla
67 #endif // mozilla_netwerk_socket_nsNamedPipeService_h