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/itoqueue1.cpp | 110 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/tests/itoqueue1.cpp (limited to 'src/tests/itoqueue1.cpp') diff --git a/src/tests/itoqueue1.cpp b/src/tests/itoqueue1.cpp new file mode 100644 index 0000000..f73f4d3 --- /dev/null +++ b/src/tests/itoqueue1.cpp @@ -0,0 +1,110 @@ +#include +#include "bu/ito.h" +#include "bu/itoqueue.h" + +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( true ); + if( pStr == NULL ) + { + printf("Null received...\n"); + } + else + { + printf("[%d] read: %s\n", id, pStr->c_str() ); + delete pStr; + } + usleep( (int)(((double)rand())/((double)RAND_MAX)*2000000.0) ); + } + + 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++ ) + { + usleep( (int)(((double)rand())/((double)RAND_MAX)*2000000.0) ); + q.enqueue( new std::string( strbase ) ); + printf("[%d] write: %s\n", id, strbase ); + } + + return NULL; + } + +private: + Bu::ItoQueue &q; + const char *strbase; + int id; +}; + +int main() +{ + Writer *wr[5]; + Reader *rd[5]; + const char bob[][7]={ + {"Test 1"}, + {"Test 2"}, + {"Test 3"}, + {"Test 4"}, + {"Test 5"} + }; + + Bu::ItoQueue q; + + for( int j = 0; j < 5; j++ ) + { + wr[j] = new Writer( q, j, bob[j] ); + rd[j] = new Reader( q, j ); + } + + for( int j = 0; j < 5; j++ ) + { + rd[j]->start(); + } + + for( int j = 0; j < 5; j++ ) + { + wr[j]->start(); + } + + for( int j = 0; j < 5; j++ ) + { + rd[j]->join(); + } + + for( int j = 0; j < 5; j++ ) + { + delete wr[j]; + delete rd[j]; + } + + return 0; +} + -- cgit v1.2.3