| Index: ui/gfx/shared_event.h
|
| diff --git a/ui/gfx/shared_event.h b/ui/gfx/shared_event.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1c93a033d41ca4575f5a463eb9ea110f035c2755
|
| --- /dev/null
|
| +++ b/ui/gfx/shared_event.h
|
| @@ -0,0 +1,72 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef UI_GFX_SHARED_EVENT_H_
|
| +#define UI_GFX_SHARED_EVENT_H_
|
| +
|
| +#include "base/memory/shared_memory.h"
|
| +#include "base/process/process_handle.h"
|
| +#include "base/time/time.h"
|
| +#include "ui/gfx/gfx_export.h"
|
| +
|
| +namespace gfx {
|
| +
|
| +typedef base::SharedMemoryHandle SharedEventHandle;
|
| +
|
| +// SharedEvent is a useful synchronization tool when you want to allow one
|
| +// thread in one process to wait for a thread in another process to finish
|
| +// some work. All functions except Wait are guaranteed to never block.
|
| +class GFX_EXPORT SharedEvent {
|
| + public:
|
| + SharedEvent();
|
| +
|
| + // Create a new SharedEvent object from an existing, platform-specific
|
| + // OS primitive.
|
| + explicit SharedEvent(const SharedEventHandle& handle);
|
| +
|
| + // Creates a new event which can be used in a remote process. Returns a
|
| + // platform-specific OS primitive for the new event. The caller is
|
| + // responsible for destroying the OS primitive.
|
| + static SharedEventHandle CreateForProcess(base::ProcessHandle process);
|
| +
|
| + // Duplicates the underlying OS primitive. The caller is responsible for
|
| + // destroying the duplicated OS primitive.
|
| + static SharedEventHandle DuplicateHandle(const SharedEventHandle& handle);
|
| +
|
| + // Put the event in the un-signaled state.
|
| + void Reset();
|
| +
|
| + // Put the event in the signaled state. Causing any thread blocked on Wait
|
| + // to be woken up.
|
| + void Signal();
|
| +
|
| + // Returns true if the event is in the signaled state, else false.
|
| + bool IsSignaled();
|
| +
|
| + // Wait up until |max_time| has passed for the event to be signaled. Returns
|
| + // true if the event was signaled. If this method returns false, then it
|
| + // does not necessarily mean that |max_time| was exceeded.
|
| + //
|
| + // WARNING: This may block and should NOT be used to wait on an event shared
|
| + // with an untrusted process to signal.
|
| + bool Wait(const base::TimeDelta& max_time);
|
| +
|
| + // Returns the underlying OS primitive for this event.
|
| + SharedEventHandle GetHandle() const;
|
| +
|
| + // Closes the open shared memory backing. The memory will remain mapped.
|
| + void Close();
|
| +
|
| + private:
|
| + inline int32_t* uaddr() const {
|
| + return reinterpret_cast<int32_t*>(shared_memory_.memory());
|
| + }
|
| + base::SharedMemory shared_memory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(SharedEvent);
|
| +};
|
| +
|
| +} // namespace gfx
|
| +
|
| +#endif // UI_GFX_SHARED_EVENT_H_
|
|
|