1//===-- PThreadEvent.h ------------------------------------------*- C++ -*-===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8// 9// Created by Greg Clayton on 6/16/07. 10// 11//===----------------------------------------------------------------------===// 12 13#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_PTHREADEVENT_H 14#define LLDB_TOOLS_DEBUGSERVER_SOURCE_PTHREADEVENT_H 15#include "PThreadCondition.h" 16#include "PThreadMutex.h" 17#include <cstdint> 18#include <ctime> 19 20class PThreadEvent { 21public: 22 PThreadEvent(uint32_t bits = 0, uint32_t validBits = 0); 23 ~PThreadEvent(); 24 25 uint32_t NewEventBit(); 26 void FreeEventBits(const uint32_t mask); 27 28 void ReplaceEventBits(const uint32_t bits); 29 uint32_t GetEventBits() const; 30 void SetEvents(const uint32_t mask); 31 void ResetEvents(const uint32_t mask); 32 // Wait for events to be set or reset. These functions take an optional 33 // timeout value. If timeout is NULL an infinite timeout will be used. 34 uint32_t 35 WaitForSetEvents(const uint32_t mask, 36 const struct timespec *timeout_abstime = NULL) const; 37 uint32_t 38 WaitForEventsToReset(const uint32_t mask, 39 const struct timespec *timeout_abstime = NULL) const; 40 41 uint32_t GetResetAckMask() const { return m_reset_ack_mask; } 42 uint32_t SetResetAckMask(uint32_t mask) { return m_reset_ack_mask = mask; } 43 uint32_t WaitForResetAck(const uint32_t mask, 44 const struct timespec *timeout_abstime = NULL) const; 45 46protected: 47 // pthread condition and mutex variable to control access and allow 48 // blocking between the main thread and the spotlight index thread. 49 mutable PThreadMutex m_mutex; 50 mutable PThreadCondition m_set_condition; 51 mutable PThreadCondition m_reset_condition; 52 uint32_t m_bits; 53 uint32_t m_validBits; 54 uint32_t m_reset_ack_mask; 55 56private: 57 PThreadEvent(const PThreadEvent &) = delete; 58 PThreadEvent &operator=(const PThreadEvent &rhs) = delete; 59}; 60 61#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_PTHREADEVENT_H 62