Wraps the async_queue class
| 89 | |
| 90 | /// Wraps the async_queue class |
| 91 | class queue { |
| 92 | public: |
| 93 | queue() |
| 94 | : count(0) |
| 95 | , sync_calls(__SYNCHRONOUS_ARCH == 1 || |
| 96 | common::getEnvVar("AF_SYNCHRONOUS_CALLS") == "1") {} |
| 97 | |
| 98 | template<typename F, typename... Args> |
| 99 | void enqueue(const F func, Args &&...args) { |
| 100 | count++; |
| 101 | if (sync_calls) { |
| 102 | func(toParam(std::forward<Args>(args))...); |
| 103 | } else { |
| 104 | aQueue.enqueue(func, toParam(std::forward<Args>(args))...); |
| 105 | } |
| 106 | #ifndef NDEBUG |
| 107 | sync(); |
| 108 | #else |
| 109 | if (getMemoryPressure() >= getMemoryPressureThreshold() || |
| 110 | count >= 25) { |
| 111 | sync(); |
| 112 | } |
| 113 | #endif |
| 114 | } |
| 115 | |
| 116 | void sync() { |
| 117 | count = 0; |
| 118 | if (!sync_calls) aQueue.sync(); |
| 119 | } |
| 120 | |
| 121 | bool is_worker() const { |
| 122 | return (!sync_calls) ? aQueue.is_worker() : false; |
| 123 | } |
| 124 | |
| 125 | friend class queue_event; |
| 126 | |
| 127 | private: |
| 128 | int count; |
| 129 | const bool sync_calls; |
| 130 | queue_impl aQueue; |
| 131 | }; |
| 132 | |
| 133 | class queue_event { |
| 134 | event_impl event_; |