| 75 | } |
| 76 | |
| 77 | void MemoryBridge::Commit() { |
| 78 | MutexGuard guard(mutex); |
| 79 | |
| 80 | // Get the number of streams |
| 81 | uint32_t streamCount; |
| 82 | sharedStorage.ConsumeStreams(&streamCount, nullptr); |
| 83 | |
| 84 | // Consume all streams |
| 85 | storageConsumeCache.clear(); |
| 86 | storageConsumeCache.resize(streamCount); |
| 87 | sharedStorage.ConsumeStreams(&streamCount, storageConsumeCache.data()); |
| 88 | |
| 89 | // Invoke streams in-order |
| 90 | // TODO: This can be bucketed pretty easily if performance becomes a problem |
| 91 | for (uint32_t i = 0; i < streamCount; i++) { |
| 92 | const MessageStream &stream = storageConsumeCache[i]; |
| 93 | |
| 94 | if (stream.GetSchema().type == MessageSchemaType::Ordered) { |
| 95 | for (const ComRef<IBridgeListener>& listener : orderedListeners) { |
| 96 | listener->Handle(&stream, 1u); |
| 97 | } |
| 98 | } else { |
| 99 | // No listener? |
| 100 | auto bucketIt = buckets.find(stream.GetSchema().id); |
| 101 | if (bucketIt == buckets.end()) { |
| 102 | // TODO: Log warning |
| 103 | continue; |
| 104 | } |
| 105 | |
| 106 | // Get the bucket |
| 107 | MessageBucket& bucket = bucketIt->second; |
| 108 | |
| 109 | // Pass through all listeners |
| 110 | for (const ComRef<IBridgeListener>& listener : bucket.listeners) { |
| 111 | listener->Handle(&stream, 1); |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | } |