worked more on testing/commenting/etc
I added some more tests, some more prints to verify test coverage, and
some more asserts to make sure things aren't broken.
diff --git a/aos/linux_code/ipc_lib/queue.h b/aos/linux_code/ipc_lib/queue.h
index 937cb07..e7737e1 100644
--- a/aos/linux_code/ipc_lib/queue.h
+++ b/aos/linux_code/ipc_lib/queue.h
@@ -55,22 +55,22 @@
// Constants for passing to options arguments.
// The non-conflicting ones can be combined with bitwise-or.
- // Causes the returned message to be left in the queue.
- // NOTE: When used with ReadMessageIndex, this means the index will not be
- // updated.
+ // Doesn't update the currently read index (the read messages in the queue or
+ // the index). This means the returned message (and any others skipped with
+ // kFromEnd) will be left in the queue.
// For reading only.
static const int kPeek = 0x0001;
// Reads the last message in the queue instead of just the next one.
// NOTE: This removes all of the messages until the last one from the queue
- // (which means that nobody else will read them). However, PEEK means to not
- // remove any from the queue, including the ones that are skipped.
+ // (which means that nobody else will read them).
// For reading only.
static const int kFromEnd = 0x0002;
// Causes reads to return NULL and writes to fail instead of waiting.
// For reading and writing.
static const int kNonBlock = 0x0004;
// Causes things to block.
- // IMPORTANT: Has a value of 0 so that it is the default. This has to stay.
+ // IMPORTANT: Has a value of 0 so that it is the default. This has to stay
+ // this way.
// For reading and writing.
static const int kBlock = 0x0000;
// Causes writes to overwrite the oldest message in the queue instead of
@@ -113,6 +113,10 @@
if (msg != NULL) DecrementMessageReferenceCount(msg);
}
+ // Returns the number of messages from this queue that are currently used (in
+ // the queue and/or given out as references).
+ int messages_used() const { return messages_used_; }
+
private:
struct MessageHeader;
struct ReadData;
@@ -153,16 +157,17 @@
// Calls DoFreeMessage if appropriate.
void DecrementMessageReferenceCount(const void *msg);
- // Should be called with data_lock_ locked.
+ // Must be called with data_lock_ locked.
// *read_data will be initialized.
// Returns with a readable message in data_ or false.
bool ReadCommonStart(int options, int *index, ReadData *read_data);
// Deals with setting/unsetting readable_ and writable_.
- // Should be called after data_lock_ has been unlocked.
+ // Must be called after data_lock_ has been unlocked.
// read_data should be the same thing that was passed in to ReadCommonStart.
void ReadCommonEnd(ReadData *read_data);
// Handles reading with kPeek.
- void *ReadPeek(int options, int start);
+ // start can be -1 if options has kFromEnd set.
+ void *ReadPeek(int options, int start) const;
// Gets called by Fetch when necessary (with placement new).
RawQueue(const char *name, size_t length, int hash, int queue_length);