summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2016-03-08 18:18:26 -0600
committerMark Salyzyn2017-02-08 15:37:44 -0600
commitcf983bcbae801e4660521b9747d9a7516e7df1c1 (patch)
tree0939db184ee66125fc810d82bd7841b1a05c5396
parent62d0d2d683f5d19cf9d451548bd03c4b4f53c42e (diff)
downloadplatform-system-core-cf983bcbae801e4660521b9747d9a7516e7df1c1.tar.gz
platform-system-core-cf983bcbae801e4660521b9747d9a7516e7df1c1.tar.xz
platform-system-core-cf983bcbae801e4660521b9747d9a7516e7df1c1.zip
liblog: add android_log_logger_list management
Add list of android_log_logger_list entities as a way of accessing the list of transport contexts from within one of the transports. This will enable us to iterate back to an internal transport context which may house a last index or signalling semaphore to propagate a wakeup on a blocking read. Test: gTest libcutils-tests, logd-unit-tests, liblog-unit-tests, logcat-unit-tests Bug: 27405083 Change-Id: I0a5e793946c020d97ffe10192369998e4ed92a83
-rw-r--r--liblog/logger.h36
-rw-r--r--liblog/logger_read.c19
2 files changed, 55 insertions, 0 deletions
diff --git a/liblog/logger.h b/liblog/logger.h
index d332c0325..471a52993 100644
--- a/liblog/logger.h
+++ b/liblog/logger.h
@@ -99,6 +99,7 @@ struct android_log_transport_read {
99}; 99};
100 100
101struct android_log_logger_list { 101struct android_log_logger_list {
102 struct listnode node;
102 struct listnode logger; 103 struct listnode logger;
103 struct listnode transport; 104 struct listnode transport;
104 int mode; 105 int mode;
@@ -146,6 +147,41 @@ struct android_log_transport_context {
146 (logp) = node_to_item((logp)->node.next, \ 147 (logp) = node_to_item((logp)->node.next, \
147 struct android_log_logger, node)) 148 struct android_log_logger, node))
148 149
150/*
151 * Global list of log readers.
152 *
153 * Usage case: search out transport contexts for all readers
154 */
155
156LIBLOG_HIDDEN struct listnode __android_log_readers;
157
158#if defined(_WIN32)
159#define logger_list_rdlock()
160#define logger_list_wrlock()
161#define logger_list_unlock()
162#else
163LIBLOG_HIDDEN pthread_rwlock_t __android_log_readers_lock;
164
165#define logger_list_rdlock() pthread_rwlock_rdlock(&__android_log_readers_lock)
166#define logger_list_wrlock() pthread_rwlock_wrlock(&__android_log_readers_lock)
167#define logger_list_unlock() pthread_rwlock_unlock(&__android_log_readers_lock)
168#endif
169
170/* Must be called with logger_list_rdlock() or logger_list_wrlock() held */
171#define logger_list_for_each(logger_list) \
172 for ((logger_list) = node_to_item(&__android_log_readers, \
173 struct android_log_logger_list, \
174 node); \
175 (logger_list) != node_to_item(&__android_log_readers, \
176 struct android_log_logger_list, \
177 node) && \
178 (logger_list) != node_to_item((logger_list)->node.next, \
179 struct android_log_logger_list, \
180 node); \
181 (logger_list) = node_to_item((logger_list)->node.next, \
182 struct android_log_logger_list, \
183 node))
184
149/* OS specific dribs and drabs */ 185/* OS specific dribs and drabs */
150 186
151#if defined(_WIN32) 187#if defined(_WIN32)
diff --git a/liblog/logger_read.c b/liblog/logger_read.c
index c3cb7adc1..7e50a23fe 100644
--- a/liblog/logger_read.c
+++ b/liblog/logger_read.c
@@ -228,6 +228,13 @@ LIBLOG_ABI_PUBLIC int android_logger_set_prune_list(
228 LOGGER_LIST_FUNCTION(logger_list, -ENODEV, setPrune, buf, len); 228 LOGGER_LIST_FUNCTION(logger_list, -ENODEV, setPrune, buf, len);
229} 229}
230 230
231LIBLOG_HIDDEN struct listnode __android_log_readers =
232 { &__android_log_readers, &__android_log_readers };
233#if !defined(_WIN32)
234LIBLOG_HIDDEN pthread_rwlock_t __android_log_readers_lock =
235 PTHREAD_RWLOCK_INITIALIZER;
236#endif
237
231LIBLOG_ABI_PUBLIC struct logger_list *android_logger_list_alloc( 238LIBLOG_ABI_PUBLIC struct logger_list *android_logger_list_alloc(
232 int mode, 239 int mode,
233 unsigned int tail, 240 unsigned int tail,
@@ -246,6 +253,10 @@ LIBLOG_ABI_PUBLIC struct logger_list *android_logger_list_alloc(
246 logger_list->tail = tail; 253 logger_list->tail = tail;
247 logger_list->pid = pid; 254 logger_list->pid = pid;
248 255
256 logger_list_wrlock();
257 list_add_tail(&__android_log_readers, &logger_list->node);
258 logger_list_unlock();
259
249 return (struct logger_list *)logger_list; 260 return (struct logger_list *)logger_list;
250} 261}
251 262
@@ -267,6 +278,10 @@ LIBLOG_ABI_PUBLIC struct logger_list *android_logger_list_alloc_time(
267 logger_list->start = start; 278 logger_list->start = start;
268 logger_list->pid = pid; 279 logger_list->pid = pid;
269 280
281 logger_list_wrlock();
282 list_add_tail(&__android_log_readers, &logger_list->node);
283 logger_list_unlock();
284
270 return (struct logger_list *)logger_list; 285 return (struct logger_list *)logger_list;
271} 286}
272 287
@@ -502,6 +517,10 @@ LIBLOG_ABI_PUBLIC void android_logger_list_free(struct logger_list *logger_list)
502 return; 517 return;
503 } 518 }
504 519
520 logger_list_wrlock();
521 list_remove(&logger_list_internal->node);
522 logger_list_unlock();
523
505 while (!list_empty(&logger_list_internal->transport)) { 524 while (!list_empty(&logger_list_internal->transport)) {
506 struct listnode *node = list_head(&logger_list_internal->transport); 525 struct listnode *node = list_head(&logger_list_internal->transport);
507 struct android_log_transport_context *transp = 526 struct android_log_transport_context *transp =