From 530014a3cce53e86dce8917e98a4e86d02f176aa Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 26 Apr 2007 15:06:49 +0000 Subject: Merged Ito and put it in the BU namespace. I should probably clean up the formatting on the comments, some of the lines wrap, but I'm not too worried about it right now. I also fixed up the doxygen config and build.conf files so that everything is building nice and smooth now. --- src/tests/itoqueue2.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/tests/itoqueue2.cpp (limited to 'src/tests/itoqueue2.cpp') diff --git a/src/tests/itoqueue2.cpp b/src/tests/itoqueue2.cpp new file mode 100644 index 0000000..f4b5e19 --- /dev/null +++ b/src/tests/itoqueue2.cpp @@ -0,0 +1,83 @@ +#include +#include "bu/ito.h" +#include "bu/itoqueue.h" +#include + +class Reader : public Bu::Ito +{ +public: + Reader( Bu::ItoQueue &q, int id ) : + q( q ), + id( id ) + { + } + + void *run() + { + for( int i = 0; i < 10; i++ ) + { + std::string *pStr = q.dequeue( 0, 500000 ); + if( pStr == NULL ) + { + printf("Null received...\n"); + i--; + } + else + { + printf("[%d] read: %s\n", id, pStr->c_str() ); + delete pStr; + } + } + + return NULL; + } + +private: + Bu::ItoQueue &q; + int id; +}; + +class Writer : public Bu::Ito +{ +public: + Writer( Bu::ItoQueue &q, int id, const char *strbase ) : + q( q ), + strbase( strbase ), + id( id ) + { + } + + void *run() + { + for( int i = 0; i < 11; i++ ) + { + sleep( 2 ); + printf("[%d] write: %s\n", id, strbase ); + q.enqueue( new std::string( strbase ) ); + } + + return NULL; + } + +private: + Bu::ItoQueue &q; + const char *strbase; + int id; +}; + +int main() +{ + printf("ETIMEDOUT: %d\n", ETIMEDOUT ); + Bu::ItoQueue q; + Writer wr( q, 0, "writer" ); + Reader rd( q, 0 ); + + rd.start(); + wr.start(); + + rd.join(); + wr.join(); + + return 0; +} + -- cgit v1.2.3