summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2014-08-07 10:16:52 -0500
committerMark Salyzyn2014-08-12 13:59:35 -0500
commita16f761faa258415b521aa6c9376c58d6c865529 (patch)
tree7ddce79b1cd7fb66862d35f068a669fb4cc565bd /logd/LogTimes.cpp
parent8750fa76090ee735677022f5e2d73419dd7faa93 (diff)
downloadplatform-system-core-a16f761faa258415b521aa6c9376c58d6c865529.tar.gz
platform-system-core-a16f761faa258415b521aa6c9376c58d6c865529.tar.xz
platform-system-core-a16f761faa258415b521aa6c9376c58d6c865529.zip
logd: persistent reader threads
(cherry picked from commit c113c5813ebd620e0bc60ece9a32ea14c08ea237) Bug: 16822776 Change-Id: I5bea468a41089b51108880044f32e2b2df1278e7
Diffstat (limited to 'logd/LogTimes.cpp')
-rw-r--r--logd/LogTimes.cpp29
1 files changed, 11 insertions, 18 deletions
diff --git a/logd/LogTimes.cpp b/logd/LogTimes.cpp
index e7e3ec218..ea4e8c83d 100644
--- a/logd/LogTimes.cpp
+++ b/logd/LogTimes.cpp
@@ -33,7 +33,6 @@ LogTimeEntry::LogTimeEntry(LogReader &reader, SocketClient *client,
33 , mRelease(false) 33 , mRelease(false)
34 , mError(false) 34 , mError(false)
35 , threadRunning(false) 35 , threadRunning(false)
36 , threadTriggered(true)
37 , mReader(reader) 36 , mReader(reader)
38 , mLogMask(logMask) 37 , mLogMask(logMask)
39 , mPid(pid) 38 , mPid(pid)
@@ -45,7 +44,9 @@ LogTimeEntry::LogTimeEntry(LogReader &reader, SocketClient *client,
45 , mStart(start) 44 , mStart(start)
46 , mNonBlock(nonBlock) 45 , mNonBlock(nonBlock)
47 , mEnd(CLOCK_MONOTONIC) 46 , mEnd(CLOCK_MONOTONIC)
48{ } 47{
48 pthread_cond_init(&threadTriggeredCondition, NULL);
49}
49 50
50void LogTimeEntry::startReader_Locked(void) { 51void LogTimeEntry::startReader_Locked(void) {
51 pthread_attr_t attr; 52 pthread_attr_t attr;
@@ -74,7 +75,6 @@ void LogTimeEntry::threadStop(void *obj) {
74 75
75 lock(); 76 lock();
76 77
77 me->threadRunning = false;
78 if (me->mNonBlock) { 78 if (me->mNonBlock) {
79 me->error_Locked(); 79 me->error_Locked();
80 } 80 }
@@ -103,6 +103,7 @@ void LogTimeEntry::threadStop(void *obj) {
103 client->decRef(); 103 client->decRef();
104 } 104 }
105 105
106 me->threadRunning = false;
106 me->decRef_Locked(); 107 me->decRef_Locked();
107 108
108 unlock(); 109 unlock();
@@ -118,7 +119,7 @@ void *LogTimeEntry::threadStart(void *obj) {
118 SocketClient *client = me->mClient; 119 SocketClient *client = me->mClient;
119 if (!client) { 120 if (!client) {
120 me->error(); 121 me->error();
121 pthread_exit(NULL); 122 return NULL;
122 } 123 }
123 124
124 LogBuffer &logbuf = me->mReader.logbuf(); 125 LogBuffer &logbuf = me->mReader.logbuf();
@@ -127,12 +128,7 @@ void *LogTimeEntry::threadStart(void *obj) {
127 128
128 lock(); 129 lock();
129 130
130 me->threadTriggered = true; 131 while (me->threadRunning && !me->isError_Locked()) {
131
132 while(me->threadTriggered && !me->isError_Locked()) {
133
134 me->threadTriggered = false;
135
136 log_time start = me->mStart; 132 log_time start = me->mStart;
137 133
138 unlock(); 134 unlock();
@@ -142,24 +138,21 @@ void *LogTimeEntry::threadStart(void *obj) {
142 } 138 }
143 start = logbuf.flushTo(client, start, privileged, FilterSecondPass, me); 139 start = logbuf.flushTo(client, start, privileged, FilterSecondPass, me);
144 140
141 lock();
142
145 if (start == LogBufferElement::FLUSH_ERROR) { 143 if (start == LogBufferElement::FLUSH_ERROR) {
146 me->error(); 144 me->error_Locked();
147 } 145 }
148 146
149 if (me->mNonBlock) { 147 if (me->mNonBlock || !me->threadRunning || me->isError_Locked()) {
150 lock();
151 break; 148 break;
152 } 149 }
153 150
154 sched_yield(); 151 pthread_cond_wait(&me->threadTriggeredCondition, &timesLock);
155
156 lock();
157 } 152 }
158 153
159 unlock(); 154 unlock();
160 155
161 pthread_exit(NULL);
162
163 pthread_cleanup_pop(true); 156 pthread_cleanup_pop(true);
164 157
165 return NULL; 158 return NULL;