libvideorender: CB1 fix poll error on weston [1/1]

PD#TV-123766

Problem:
after invoked render_disconnect, invoking render_connect,poll
error happened

Solution:
1.reset poll object flushing event
2.reset wayland params in openDisplay api
3.modify some logs
4.set log level via rlib_plugin_level node
5.sync trunk Thread implement

Verify:
ap222

Change-Id: I2f4ff525ab182572c91105133f2262af99a1d9c5
Signed-off-by: fei.deng <fei.deng@amlogic.com>
diff --git a/tools/Poll.cpp b/tools/Poll.cpp
index 46d306f..3bab65c 100644
--- a/tools/Poll.cpp
+++ b/tools/Poll.cpp
@@ -97,7 +97,10 @@
     mFds[mFdsCnt].revents = 0;
     mFdsCnt++;
 
-    //DEBUG("mFds:%p,maxcnt:%d,cnt:%d",mFds,mFdsMaxCnt,mFdsCnt);
+    // DEBUG(NO_CAT,"fd:%d,maxcnt:%d,cnt:%d",fd,mFdsMaxCnt,mFdsCnt);
+    // for (int i = 0; i < mFdsCnt; i++) {
+    //     DEBUG(NO_CAT,"mFds[%d]:%d",i,mFds[i]);
+    // }
     return 0;
 }
 
@@ -107,11 +110,24 @@
     for (int i = 0; i < mFdsCnt; i++) {
         struct pollfd *pfd = &mFds[i];
         if (pfd->fd == fd) {
-            memmove(mFds+i*sizeof(struct pollfd),mFds+(i+1)*sizeof(struct pollfd), 1);
-            mFdsCnt--;
-            return 0;
+            if (i == (mFdsCnt - 1)) {
+                mFds[i].fd = -1;
+                mFds[i].events = 0;
+                mFds[i].revents = 0;
+            } else {
+                for (int j = i; j+1 < mFdsCnt; j++) {
+                    mFds[j].fd = mFds[j+1].fd;
+                    mFds[j].events = mFds[j+1].events;
+                    mFds[j].revents = mFds[j+1].revents;
+                }
+            }
+            mFdsCnt -= 1;
         }
     }
+    // DEBUG(NO_CAT,"fd:%d,maxcnt:%d,cnt:%d",fd,mFdsMaxCnt,mFdsCnt);
+    // for (int i = 0; i < mFdsCnt; i++) {
+    //     DEBUG(NO_CAT,"mFds[%d]:%d",i,mFds[i]);
+    // }
     return 0;
 }
 
@@ -169,10 +185,10 @@
         if (timeoutMs >= 0) {
             t = timeoutMs;
         }
-        //DEBUG("waiting");
         activecnt = poll(mFds, mFdsCnt, t);
         //DEBUG("waiting end");
         if (mFlushing.load()) {
+            releaseWakeup();
             goto tag_flushing;
         }
     } while(0);