From ea2ee85202f7b16d7b713bc7a7dcd1fa63bc6213 Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期五, 26 三月 2021 11:54:50 +0800
Subject: [PATCH] change refcount to AddRef,Release interface.

---
 utest/utest.cpp |   34 ++++++++++++++++++++++------------
 1 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/utest/utest.cpp b/utest/utest.cpp
index 6994cbd..2462ecc 100644
--- a/utest/utest.cpp
+++ b/utest/utest.cpp
@@ -10,6 +10,7 @@
 #include <boost/date_time/posix_time/posix_time.hpp>
 #include <boost/date_time/microsec_time_clock.hpp>
 #include <boost/uuid/uuid_generators.hpp>
+#include <boost/uuid/uuid_io.hpp>
 #include "shm_queue.h"
 #include "bh_util.h"
 
@@ -151,10 +152,10 @@
     BOOST_CHECK(m1.IsCounted());
     BOOST_CHECK_EQUAL(m1.AddRef(), 2);
     BOOST_CHECK_EQUAL(m0.AddRef(), 3);
-    BOOST_CHECK_EQUAL(m0.RemoveRef(), 2);
-    BOOST_CHECK_EQUAL(m0.RemoveRef(), 1);
-    BOOST_CHECK_EQUAL(m1.RemoveRef(), 0);
-    BOOST_CHECK_EQUAL(m1.Count(), 0);
+    BOOST_CHECK_EQUAL(m0.Release(shm), 2);
+    BOOST_CHECK_EQUAL(m0.Release(shm), 1);
+    BOOST_CHECK_EQUAL(m1.Release(shm), 0);
+    BOOST_CHECK_THROW(m1.Count(), std::exception);
 }
 
 BOOST_AUTO_TEST_CASE(MsgHeaderTest)
@@ -209,7 +210,7 @@
     auto Client = [&](int tid, int nmsg){
         for (int i = 0; i < nmsg; ++i) {
             auto Send = [&]() { return cli.Send(srv.Id(), msg_content.data(), msg_content.size(), 1000); };
-            auto SendRefCounted = [&]() { return cli.Send(srv.Id(), request, 1000); };
+            // auto SendRefCounted = [&]() { return cli.Send(srv.Id(), request, 1000); };
 
             if (!Send()) {
                 printf("********** client send error.\n");
@@ -246,9 +247,9 @@
             if (srv.Recv(src_id, data, size, 100)) {
                 DEFER1(free(data));
                 auto Send = [&](){ return srv.Send(src_id, data, size, 100); };
-                auto SendRefCounted = [&](){ return srv.Send(src_id, reply, 100); };
+                // auto SendRefCounted = [&](){ return srv.Send(src_id, reply, 100); };
 
-                if (SendRefCounted()) {
+                if (Send()) {
                     if (size != msg_content.size()) {
                         BOOST_TEST(false, "server msg size error");
                     }
@@ -263,7 +264,7 @@
     ThreadManager clients, servers;
     for (int i = 0; i < qlen; ++i) { servers.Launch(Server); }
     int ncli = 100*1;
-    uint64_t nmsg = 100*100;
+    uint64_t nmsg = 100*100*10;
     printf("client threads: %d, msgs : %ld, total msg: %ld\n", ncli, nmsg, ncli * nmsg);
     for (int i = 0; i < ncli; ++i) { clients.Launch(Client, i, nmsg); }
     clients.WaitAll();
@@ -274,18 +275,27 @@
     BOOST_CHECK_EQUAL(request.Count(), 1);
     BOOST_CHECK(reply.IsCounted());
     BOOST_CHECK_EQUAL(reply.Count(), 1);
-    if (request.RemoveRef() == 0) {
-        BOOST_CHECK_EQUAL(reply.Count(), 0);
-        request.FreeFrom(shm);
-    }
+    request.Release(shm);
+    BOOST_CHECK_THROW(request.Count(), std::exception);
+    BOOST_CHECK_THROW(reply.Count(), std::exception);
+    // BOOST_CHECK_THROW(reply.Count(), int);
 }
 
+inline int MyMin(int a, int b) {
+    printf("MyMin\n");
+    return a < b ? a : b;
+}
 int test_main(int argc, char *argv[])
 {
     printf("test main\n");
     int a = 0;
     int b = 0;
     BOOST_CHECK_EQUAL(a, b);
+    int n = MyMin(4,6);
+    for (int i = 0; i < n; ++i) {
+        printf("i = %d\n", i);
+    }
+
     return 0;
 }
 

--
Gitblit v1.8.0