1 // Copyright 2006 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // queue.h : simple queue api
17 // This is an interface to a simple thread safe queue,
18 // used to hold data blocks and patterns.
19 // The order in which the blocks are returned is random.
21 #ifndef STRESSAPPTEST_QUEUE_H_ // NOLINT
22 #define STRESSAPPTEST_QUEUE_H_
24 #include <sys/types.h>
27 // This file must work with autoconf on its public version,
28 // so these includes are correct.
29 #include "sattypes.h" // NOLINT
30 #include "pattern.h" // NOLINT
32 // Tag indicating no preference.
33 static const int kDontCareTag = -1;
34 // Tag indicating no preference.
35 static const int kInvalidTag = 0xf001;
38 // This describes a block of memory, and the expected fill pattern.
43 class Pattern *pattern;
44 int32 tag; // These are tags for use in NUMA affinity or other uses.
45 uint32 touch; // Counter of the number of reads from this page.
46 uint64 ts; // Timestamp of the last read from this page.
47 class Pattern *lastpattern; // Expected Pattern at last read.
50 static inline void init_pe(struct page_entry *pe) {
54 pe->tag = kInvalidTag;
57 pe->lastpattern = NULL;
60 // This is a threadsafe randomized queue of pages for
61 // worker threads to use.
62 class PageEntryQueue {
64 explicit PageEntryQueue(uint64 queuesize);
67 // Push a page onto the list.
68 int Push(struct page_entry *pe);
69 // Pop a random page off of the list.
70 int PopRandom(struct page_entry *pe);
73 struct page_entry *pages_; // Where the pages are held.
76 int64 q_size_; // Size of the queue.
77 int64 pushed_; // Number of pages pushed, total.
78 int64 popped_; // Number of pages popped, total.
79 pthread_mutex_t q_mutex_;
81 DISALLOW_COPY_AND_ASSIGN(PageEntryQueue);
85 #endif // MILES_TESTS_SAT_QUEUE_H_ NOLINT