Qt 4.8
Macros | Enumerations | Functions | Variables
qabstracteventdispatcher.cpp File Reference
#include "qabstracteventdispatcher.h"
#include "qabstracteventdispatcher_p.h"
#include "qthread.h"
#include <private/qthread_p.h>
#include <private/qcoreapplication_p.h>

Go to the source code of this file.

Macros

#define q_static_assert(expr)   (void)QStaticAssertType<expr>::Value
 

Enumerations

enum  {
  FirstBucketOffset = 0, SecondBucketOffset = sizeof(FirstBucket) / sizeof(FirstBucket[0]), ThirdBucketOffset = 0x100, FourthBucketOffset = 0x1000,
  FifthBucketOffset = 0x10000, SixthBucketOffset = 0x100000
}
 
enum  {
  FirstBucketSize = SecondBucketOffset, SecondBucketSize = ThirdBucketOffset - SecondBucketOffset, ThirdBucketSize = FourthBucketOffset - ThirdBucketOffset, FourthBucketSize = FifthBucketOffset - FourthBucketOffset,
  FifthBucketSize = SixthBucketOffset - FifthBucketOffset, SixthBucketSize = MaxTimerId - SixthBucketOffset
}
 
enum  { NumberOfBuckets = sizeof(BucketSize) / sizeof(BucketSize[0]) }
 

Functions

static int * allocateBucket (int bucket)
 
static int bucketIndex (int bucket, int timerId)
 
static int bucketOffset (int timerId)
 
static int prepareNewValueWithSerialNumber (int oldId, int newId)
 
static void timerIdsDestructorFunction ()
 

Variables

static const int BucketOffset []
 
static const int BucketSize []
 
static int FirstBucket []
 
static const int MaxTimerId = TimerIdMask
 
static QBasicAtomicInt nextFreeTimerId = Q_BASIC_ATOMIC_INITIALIZER(1)
 
static const int TimerIdMask = 0x00ffffff
 
static QBasicAtomicPointer< int > timerIds []
 
static const int TimerSerialCounter = TimerIdMask + 1
 
static const int TimerSerialMask = ~TimerIdMask & ~0x80000000
 

Macro Definition Documentation

◆ q_static_assert

#define q_static_assert (   expr)    (void)QStaticAssertType<expr>::Value

Definition at line 119 of file qabstracteventdispatcher.cpp.

Referenced by bucketOffset().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
FirstBucketOffset 
SecondBucketOffset 
ThirdBucketOffset 
FourthBucketOffset 
FifthBucketOffset 
SixthBucketOffset 

Definition at line 62 of file qabstracteventdispatcher.cpp.

◆ anonymous enum

anonymous enum

◆ anonymous enum

anonymous enum
Enumerator
NumberOfBuckets 

Definition at line 84 of file qabstracteventdispatcher.cpp.

84 { NumberOfBuckets = sizeof(BucketSize) / sizeof(BucketSize[0]) };
static const int BucketSize[]

Function Documentation

◆ allocateBucket()

static int* allocateBucket ( int  bucket)
inlinestatic

Definition at line 140 of file qabstracteventdispatcher.cpp.

Referenced by QAbstractEventDispatcherPrivate::allocateTimerId().

141 {
142  // allocate a new bucket
143  const int size = BucketSize[bucket];
144  const int offset = BucketOffset[bucket];
145  int *b = new int[size];
146  for (int i = 0; i != size; ++i)
147  b[i] = offset + i + 1;
148  return b;
149 }
static const int BucketOffset[]
static const int BucketSize[]

◆ bucketIndex()

static int bucketIndex ( int  bucket,
int  timerId 
)
inlinestatic

Definition at line 135 of file qabstracteventdispatcher.cpp.

Referenced by QAbstractEventDispatcherPrivate::allocateTimerId(), and QAbstractEventDispatcherPrivate::releaseTimerId().

136 {
137  return timerId - BucketOffset[bucket];
138 }
static const int BucketOffset[]

◆ bucketOffset()

static int bucketOffset ( int  timerId)
inlinestatic

Definition at line 121 of file qabstracteventdispatcher.cpp.

Referenced by QAbstractEventDispatcherPrivate::allocateTimerId(), and QAbstractEventDispatcherPrivate::releaseTimerId().

122 {
123  q_static_assert(sizeof BucketSize == sizeof BucketOffset);
124  q_static_assert(sizeof(timerIds) / sizeof(timerIds[0]) == NumberOfBuckets);
125 
126  for (int i = 0; i < NumberOfBuckets; ++i) {
127  if (timerId < BucketSize[i])
128  return i;
129  timerId -= BucketSize[i];
130  }
131  qFatal("QAbstractEventDispatcher: INTERNAL ERROR, timer ID %d is too large", timerId);
132  return -1;
133 }
static QBasicAtomicPointer< int > timerIds[]
#define q_static_assert(expr)
Q_CORE_EXPORT void qFatal(const char *,...)
static const int BucketOffset[]
static const int BucketSize[]

◆ prepareNewValueWithSerialNumber()

static int prepareNewValueWithSerialNumber ( int  oldId,
int  newId 
)
inlinestatic

Definition at line 110 of file qabstracteventdispatcher.cpp.

Referenced by QAbstractEventDispatcherPrivate::allocateTimerId(), and QAbstractEventDispatcherPrivate::releaseTimerId().

111 {
112  return (newId & TimerIdMask) | ((oldId + TimerSerialCounter) & TimerSerialMask);
113 }
static const int TimerIdMask
static const int TimerSerialMask
static const int TimerSerialCounter

◆ timerIdsDestructorFunction()

static void timerIdsDestructorFunction ( )
static

Definition at line 99 of file qabstracteventdispatcher.cpp.

100 {
101  // start at one, the first bucket is pre-allocated
102  for (int i = 1; i < NumberOfBuckets; ++i)
103  delete [] static_cast<int *>(timerIds[i]);
104 }
static QBasicAtomicPointer< int > timerIds[]

Variable Documentation

◆ BucketOffset

const int BucketOffset[]
static

◆ BucketSize

const int BucketSize[]
static

◆ FirstBucket

int FirstBucket[]
static
Initial value:
= {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
}

Definition at line 57 of file qabstracteventdispatcher.cpp.

◆ MaxTimerId

const int MaxTimerId = TimerIdMask
static

Definition at line 55 of file qabstracteventdispatcher.cpp.

◆ nextFreeTimerId

QBasicAtomicInt nextFreeTimerId = Q_BASIC_ATOMIC_INITIALIZER(1)
static

◆ TimerIdMask

const int TimerIdMask = 0x00ffffff
static

◆ timerIds

QBasicAtomicPointer<int> timerIds[]
static

◆ TimerSerialCounter

const int TimerSerialCounter = TimerIdMask + 1
static

Definition at line 54 of file qabstracteventdispatcher.cpp.

Referenced by prepareNewValueWithSerialNumber().

◆ TimerSerialMask

const int TimerSerialMask = ~TimerIdMask & ~0x80000000
static

Definition at line 53 of file qabstracteventdispatcher.cpp.

Referenced by prepareNewValueWithSerialNumber().