#ifndef SchedulePair_h
#define SchedulePair_h
#include <wtf/HashSet.h>
#include <wtf/RetainPtr.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/text/StringHash.h>
#include <wtf/text/WTFString.h>
#if PLATFORM(COCOA) && !USE(CFNETWORK)
OBJC_CLASS NSRunLoop;
#endif
namespace WTF {
class SchedulePair : public ThreadSafeRefCounted<SchedulePair> {
public:
static Ref<SchedulePair> create(CFRunLoopRef runLoop, CFStringRef mode) { return adoptRef(*new SchedulePair(runLoop, mode)); }
#if PLATFORM(COCOA) && !USE(CFNETWORK)
static Ref<SchedulePair> create(NSRunLoop* runLoop, CFStringRef mode) { return adoptRef(*new SchedulePair(runLoop, mode)); }
NSRunLoop* nsRunLoop() const { return m_nsRunLoop.get(); }
#endif
CFRunLoopRef runLoop() const { return m_runLoop.get(); }
CFStringRef mode() const { return m_mode.get(); }
WTF_EXPORT_PRIVATE bool operator==(const SchedulePair& other) const;
private:
SchedulePair(CFRunLoopRef runLoop, CFStringRef mode)
: m_runLoop(runLoop)
{
if (mode)
m_mode = adoptCF(CFStringCreateCopy(0, mode));
}
#if PLATFORM(COCOA) && !USE(CFNETWORK)
WTF_EXPORT_PRIVATE SchedulePair(NSRunLoop*, CFStringRef);
RetainPtr<NSRunLoop*> m_nsRunLoop;
#endif
RetainPtr<CFRunLoopRef> m_runLoop;
RetainPtr<CFStringRef> m_mode;
};
struct SchedulePairHash {
static unsigned hash(const RefPtr<SchedulePair>& pair)
{
uintptr_t hashCodes[2] = { reinterpret_cast<uintptr_t>(pair->runLoop()), pair->mode() ? CFHash(pair->mode()) : 0 };
return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
}
static bool equal(const RefPtr<SchedulePair>& a, const RefPtr<SchedulePair>& b) { return a == b; }
static const bool safeToCompareToEmptyOrDeleted = true;
};
typedef HashSet<RefPtr<SchedulePair>, SchedulePairHash> SchedulePairHashSet;
}
using WTF::SchedulePair;
using WTF::SchedulePairHashSet;
#endif