merging in the rewritten queue code and cleaned up linux IPC stuff
This change has been around for over a year now, and it's time to merge
it in, because it makes that code much easier to deal with.
diff --git a/aos/linux_code/camera/Buffers.cpp b/aos/linux_code/camera/Buffers.cpp
index e1d22b6..19c1d45 100644
--- a/aos/linux_code/camera/Buffers.cpp
+++ b/aos/linux_code/camera/Buffers.cpp
@@ -61,24 +61,21 @@
}
void Buffers::Release() {
- if (message_ != NULL) {
- queue_->FreeMessage(message_);
- message_ = NULL;
- }
+ message_.reset();
}
-const void *Buffers::GetNext(bool block,
- uint32_t *bytesused, timeval *timestamp, uint32_t *sequence) {
+const void *Buffers::GetNext(bool block, uint32_t *bytesused,
+ timeval *timestamp, uint32_t *sequence) {
Release();
// TODO(brians) make sure the camera reader process hasn't died
do {
if (block) {
- message_ = static_cast<const Message *>(queue_->ReadMessage(
- RawQueue::kPeek | RawQueue::kBlock));
+ message_.reset(static_cast<const Message *>(
+ queue_->ReadMessage(RawQueue::kPeek | RawQueue::kBlock)));
} else {
static int index = 0;
- message_ = static_cast<const Message *>(queue_->ReadMessageIndex(
- RawQueue::kBlock, &index));
+ message_.reset(static_cast<const Message *>(
+ queue_->ReadMessageIndex(RawQueue::kBlock, &index)));
}
} while (block && message_ == NULL);
if (message_ != NULL) {
@@ -132,9 +129,12 @@
return myfds[0];
}
-Buffers::Buffers() : server_(CreateSocket(connect)), fd_(FetchFD()), message_(NULL) {
+Buffers::Buffers()
+ : server_(CreateSocket(connect)),
+ fd_(FetchFD()),
+ queue_(RawQueue::Fetch(kQueueName.c_str(), sizeof(Message), 971, 1)),
+ message_(queue_) {
MMap();
- queue_ = RawQueue::Fetch(kQueueName.c_str(), sizeof(Message), 971, 1);
}
Buffers::~Buffers() {
diff --git a/aos/linux_code/camera/Buffers.h b/aos/linux_code/camera/Buffers.h
index b447468..aedd79f 100644
--- a/aos/linux_code/camera/Buffers.h
+++ b/aos/linux_code/camera/Buffers.h
@@ -8,6 +8,7 @@
#include "aos/linux_code/ipc_lib/queue.h"
#include "aos/common/type_traits.h"
+#include "aos/atom_code/ipc_lib/unique_message_ptr.h"
namespace aos {
namespace camera {
@@ -17,6 +18,7 @@
// It has to do a lot of the same things as all the other ones, but it gets
// the information from different places (some of it gets sent out by it).
friend class Reader;
+
// Not an abstract name so that an existing one can just be unlinked without
// disturbing it if necessary (like with shm_link).
static const std::string kFDServerName;
@@ -50,14 +52,17 @@
uint32_t sequence;
};
static_assert(shm_ok<Message>::value, "it's going through queues");
- // The current one. Sometimes NULL.
- const Message *message_;
- static const std::string kQueueName;
+
// NULL for the Reader one.
- RawQueue *queue_;
+ RawQueue *const queue_;
+ // The current one. Sometimes NULL.
+ unique_message_ptr<const Message> message_;
+
+ static const std::string kQueueName;
// Make the actual mmap calls.
// Called by Buffers() automatically.
void MMap();
+
public:
Buffers();
// Will clean everything up.
@@ -89,4 +94,3 @@
} // namespace aos
#endif
-
diff --git a/aos/linux_code/camera/camera.gyp b/aos/linux_code/camera/camera.gyp
index e4f1e04..fabd52f 100644
--- a/aos/linux_code/camera/camera.gyp
+++ b/aos/linux_code/camera/camera.gyp
@@ -47,9 +47,11 @@
'dependencies': [
'<(AOS)/linux_code/ipc_lib/ipc_lib.gyp:queue',
'<(AOS)/build/aos.gyp:logging',
+ '<(AOS)/atom_code/ipc_lib/ipc_lib.gyp:scoped_message_ptr',
],
'export_dependent_settings': [
'<(AOS)/linux_code/ipc_lib/ipc_lib.gyp:queue',
+ '<(AOS)/linux_code/ipc_lib/ipc_lib.gyp:scoped_message_ptr',
],
},
{