Commit graph

25 commits

Author SHA1 Message Date
Vic Yang
9fb93edd5b Reland "libutils: Introduce StaticString16""
This reverts commit 1270e4fbf1.

Bug: 138856262
Test: Run unit tests.
Change-Id: I37be01d7d4f98a83078870cb0917275336fa2bbd
Merged-In: I8da93f2c9b95183e32d4a2ea895f90c449abbe4d
2019-09-05 13:19:14 -07:00
Kevin Han
1270e4fbf1 Revert "Reland "libutils: Introduce StaticString16"""
This reverts commit c55ac92bd6.

Reason for revert: Breaks down-stream branches. See b/140315617

Change-Id: I4937fdf4bdcc7a44d5f10700ecf2d5e96aef7d27
Merged-In: I8da93f2c9b95183e32d4a2ea895f90c449abbe4d
2019-08-30 23:50:38 +00:00
Vic Yang
c55ac92bd6 Reland "libutils: Introduce StaticString16""
This time with old branches excluded.

Bug: 138856262
Test: Run unit tests.
Change-Id: Id0bb1d54b71e38244d64f1b684db1fda81de854c
Merged-In: I8da93f2c9b95183e32d4a2ea895f90c449abbe4d
2019-08-30 11:01:27 -07:00
Vic Yang
86eaa8de78 Revert "libutils: Introduce StaticString16"
This reverts commit d4cb489434.

Reason for revert: Breaking aosp_bonito-userdebug

Change-Id: Iea72f39d40f476002ce0ad6b5ce3b4e1ca570de7
2019-08-29 22:47:07 +00:00
Vic Yang
d4cb489434 libutils: Introduce StaticString16
This is a backward compatible implementation of compile time
constructed String16 support.

As much as we'd like a regular constexpr constructor for String16, we
want to make sure the regular non-static String16 does not regress.
We also need to make sure prebuilts built with previous version of
String16 still works with new libutils.  This means we cannot change
the size of String16 objects and we cannot make anything virtual.

To add a flag to indicate whether a String16 is static without
increasing the size of non-static String16 objects, we repurpose a
reserved field in SharedBuffer as "for client use".  With this, we can
tag every String16 and perform memory operation differently based on
how the underlying buffers are allocated.

By using StaticString16, we are able to eliminate the runtime
construction of a String16 and move it out of .bss section.

Bug: 138856262
Test: Run newly added unit tests.
Change-Id: I72bb8dc27a59b9ef34e0d934bc1e00b0f675855a
2019-08-09 11:01:37 -07:00
Yi Kong
e1731a4f2e [libutils] Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I5e89ec8c42151875439d2656475a8739ab9cb7dc
2018-07-16 18:11:34 -07:00
Mathias Agopian
22dbf3947f clean-up libutils includes
moved Foo.h as first include of Foo.cpp, and
removed redundant includes.

Made NativeHandle non virtual.


Test: run & compile
Bug: n/a

Change-Id: I37fa746cd42c9ba23aba181f84cb6c619386406a
2017-03-03 14:47:47 -08:00
Mark Salyzyn
271a1a7cda resolve merge conflicts of a45b1d6f3 to master
Test: compile
Bug: 30465923
Change-Id: I648855539df3cfa176c6ecac19b6a562ba6feaf7
2017-01-11 11:41:38 -08:00
Mark Salyzyn
30f991f251 liblog: use log/log.h when utilizing ALOG macros
Test: compile
Bug: 30465923
Change-Id: Id6d76510819ebd88c3f5003d00d73a0dbe85e943
2017-01-11 09:31:15 -08:00
Mark Salyzyn
b4c9ab960e Merge "system/core: preparation to pull back interfaces from android/log.h" am: 27d2d49f48 am: 8a7297a09f
am: c561af07ae

Change-Id: I7bfb6dd925739345624a1ed16c0c3cb2106ad098
2016-10-20 18:21:18 +00:00
Mark Salyzyn
cfd5b080af system/core: preparation to pull back interfaces from android/log.h
Point to log/log.h where necessary, define LOG_TAG where necessary.
Accept that private/android_logger.h is suitable replacement for
log/logger.h and android/log.h.

Correct liblog/README

Effectively a cleanup and controlled select revert of
'system/core: drop or replace log/logger.h' and
'system/core: Replace log/log.h with android/log.h'.

Test: compile
Bug: 30465923
Change-Id: Ic2ad157bad6f5efe2c6af293a73bb753300b17a2
2016-10-20 08:11:39 -07:00
Mark Salyzyn
7a7b066e5e system/core Replace log/log.h with android/log.h am: ff2dcd9af9 am: cac331afd9 am: 0308b0eabd
am: 9f6b98dec0

Change-Id: I1a1384253e4fce0489b7d1aa77b0f67ee12185c3
2016-10-01 00:43:22 +00:00
Mark Salyzyn
ff2dcd9af9 system/core Replace log/log.h with android/log.h
Should use android/log.h instead of log/log.h as a good example
to all others.  Adjust header order to comply with Android Coding
standards.

Test: Compile
Bug: 26552300
Bug: 31289077
Change-Id: I33a8fb4e754d2dc4754d335660c450e0a67190fc
2016-09-30 12:47:05 -07:00
Greg Kaiser
f068856284 Merge "SharedBuffer: Fix bug in return value of release()"
am: c064db48f1

Change-Id: I401318575ced17a94d19b47b2821ed4c310d9a03
2016-08-08 18:15:44 +00:00
Greg Kaiser
c9b23cbb54 SharedBuffer: Fix bug in return value of release()
Since the equality operator '==' has higher precedence than the
assignment operator '=', we were assigning 'prev' to the result of
our comparison and not the result of mRefs.fetch_sub().

This means that 'prev' would only receive the values 0 or 1.  In
the cases where fetch_sub() returned 0 or 1, we were happening to
get the correct value.  But if fetch_sub() was greator than 1,
we would return to the user 0, instead of the previous reference
count.

We fix this by properly adding parentheses.  We also adjust the
whitespace a little to hopefully make the groupings of the logic
easier to see.

Change-Id: Ib129798a7076854b9ca4f6385c42edbf4fb75e57
2016-08-08 06:55:10 -07:00
Greg Kaiser
476dbc48da SharedBuffer: Refactor release() logic
We refactor this mildly in the hopes of making this a little easier
to follow for future readers.  We also go through the dealloc()
method so if we decide to invoke the SharedBuffer destructor in
the future, we only need to remember it in one place.

In addition, this is slightly more efficient in the multi-owner
case, since we no longer subtract to 0 and then (redundantly) set the
reference count explicitly to 0 as well.

Change-Id: Ifc773bd7900c89c36ac24904b2716f02cb57c095
2016-08-05 17:04:45 -07:00
Greg Kaiser
dd55734dda SharedBuffer: Fix bug in return value of release()
Since the equality operator '==' has higher precedence than the
assignment operator '=', we were assigning 'prev' to the result of
our comparison and not the result of mRefs.fetch_sub().

This means that 'prev' would only receive the values 0 or 1.  In
the cases where fetch_sub() returned 0 or 1, we were happening to
get the correct value.  But if fetch_sub() was greator than 1,
we would return to the user 0, instead of the previous reference
count.

We fix this by properly adding parentheses.  We also adjust the
whitespace a little to hopefully make the groupings of the logic
easier to see.

Change-Id: Ib129798a7076854b9ca4f6385c42edbf4fb75e57
2016-08-05 06:28:10 -07:00
Hans Boehm
12f788e763 Merge "Fix SharedBuffer. Remove aref." am: 069517574e
am: 1e081a8c5f

* commit '1e081a8c5f2d6e6cb55658bb289db1f0b4f5774a':
  Fix SharedBuffer. Remove aref.

Change-Id: I5849137bb49d727d1c1d245f0f61d11c4ee10859
2016-05-23 22:22:18 +00:00
Hans Boehm
3e4c076ef2 Fix SharedBuffer. Remove aref.
Add comment that SharedBuffer is deprecated.

Both aref and SharedBuffer had memory ordering bugs.  Aref has no
clients.

SharedBuffer had several bugs, which are fixed here:

mRefs was declared neither volatile, not atomic, allowing the
compiler to, for example, reuse a stale previously loaded value.

It used the default android_atomic release memory ordering, which
is insufficient for reference count decrements.

It used an ordinary memory read in onlyOwner() to check whether
an object is safe to deallocate, without any attempt to ensure
memory ordering.

Comments claimed that SharedBuffer was exactly 16 bytes, but
this was neither checked, nor correct on 64-bit platforms.

This turns mRef into a std::atomic and removes the android_atomic
dependency.

Bug: 28826227
Change-Id: I39fa0b4f70ac0471b14ad274806fc4e0c0802e78
2016-05-23 17:28:52 +00:00
Sergio Giro
fa2f9d603c am c565bdb6: am f777655d: resolved conflicts for 6ee734cf to stage-aosp-master
* commit 'c565bdb67b801fe2b4965b44e53dccfd9097993c':
  libutils: hide SharedBuffer by moving SharedBuffer.h to the implementation directory
2015-09-23 19:50:33 +00:00
Sergio Giro
f777655d85 resolved conflicts for 6ee734cf to stage-aosp-master
Change-Id: Ia06c4d941d9b8828707299bb363f51fab5549897
2015-09-23 17:58:25 +01:00
Sergio Giro
d2529f2830 libutils: hide SharedBuffer by moving SharedBuffer.h to the implementation directory
Some methods in header files of classes using SharedBuffer need
to be moved to the implementation files accordingly

Change-Id: I891f3ace2b940ab219e4e449040bfed71c0547db
2015-09-23 16:22:59 +01:00
Sergio Giro
d95e47f136 libutils: fix overflow in SharedBuffer [DO NOT MERGE]
See
https://code.google.com/p/android/issues/detail?id=181910

Bug: 22952485
(cherry picked from commit 66b6eb9490)

Change-Id: I363f49b5b3c6b7b3ac08cba2c14d72c431588c5a
2015-08-25 17:40:47 +01:00
Sergio Giro
7987b83553 libutils: fix overflow in SharedBuffer
See
https://code.google.com/p/android/issues/detail?id=181910

Bug: 22952485
Change-Id: Idcc7e581a69436c8a623659fbd9add9e5f0d4c74
2015-08-21 14:17:32 +01:00
Alex Ray
d98e07fdf9 move libs/utils to libutils
Change-Id: I6cf4268599460791414882f91eeb88a992fbd29d
2013-08-02 14:40:08 -07:00
Renamed from libs/utils/SharedBuffer.cpp (Browse further)