Home | History | Annotate | Download | only in source
      1 //===-- PThreadEvent.h ------------------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 //  Created by Greg Clayton on 6/16/07.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef __PThreadEvent_h__
     15 #define __PThreadEvent_h__
     16 #include "PThreadMutex.h"
     17 #include "PThreadCondition.h"
     18 #include <stdint.h>
     19 #include <time.h>
     20 
     21 class PThreadEvent
     22 {
     23 public:
     24                 PThreadEvent        (uint32_t bits = 0, uint32_t validBits = 0);
     25                 ~PThreadEvent       ();
     26 
     27     uint32_t    NewEventBit         ();
     28     void        FreeEventBits       (const uint32_t mask);
     29 
     30     void        ReplaceEventBits    (const uint32_t bits);
     31     uint32_t    GetEventBits        () const;
     32     void        SetEvents           (const uint32_t mask);
     33     void        ResetEvents         (const uint32_t mask);
     34     // Wait for events to be set or reset. These functions take an optional
     35     // timeout value. If timeout is NULL an infinite timeout will be used.
     36     uint32_t    WaitForSetEvents    (const uint32_t mask, const struct timespec *timeout_abstime = NULL) const;
     37     uint32_t    WaitForEventsToReset(const uint32_t mask, const struct timespec *timeout_abstime = NULL) const;
     38 
     39     uint32_t    GetResetAckMask () const { return m_reset_ack_mask; }
     40     uint32_t    SetResetAckMask (uint32_t mask) { return m_reset_ack_mask = mask; }
     41     uint32_t    WaitForResetAck (const uint32_t mask, const struct timespec *timeout_abstime = NULL) const;
     42 protected:
     43     //----------------------------------------------------------------------
     44     // pthread condition and mutex variable to controll access and allow
     45     // blocking between the main thread and the spotlight index thread.
     46     //----------------------------------------------------------------------
     47     mutable PThreadMutex        m_mutex;
     48     mutable PThreadCondition    m_set_condition;
     49     mutable PThreadCondition    m_reset_condition;
     50     uint32_t            m_bits;
     51     uint32_t            m_validBits;
     52     uint32_t            m_reset_ack_mask;
     53 private:
     54     PThreadEvent(const PThreadEvent&);  // Outlaw copy contructor
     55     PThreadEvent& operator=(const PThreadEvent& rhs);
     56 
     57 };
     58 
     59 #endif // #ifndef __PThreadEvent_h__
     60