summaryrefslogtreecommitdiffstats
path: root/libs/utils
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2011-06-15 20:41:15 -0700
committerKenny Root <kroot@google.com>2011-06-15 20:55:49 -0700
commite04f826fef44b85108be85fb6d3a16c35a9e5c29 (patch)
tree13afd43678741a6439d23a966950cd7c6d40bdaa /libs/utils
parenta27ad3cca3f17e394ce96011422a0131c15939a9 (diff)
downloadframeworks_base-e04f826fef44b85108be85fb6d3a16c35a9e5c29.zip
frameworks_base-e04f826fef44b85108be85fb6d3a16c35a9e5c29.tar.gz
frameworks_base-e04f826fef44b85108be85fb6d3a16c35a9e5c29.tar.bz2
Use rand() for MinGW
The version of MinGW we use doesn't have nrand48() which is really lame, but we need to use libutils in the Windows SDK. Change-Id: If854c03dbf02bc29e79f49e4539f08c2bf057517
Diffstat (limited to 'libs/utils')
-rw-r--r--libs/utils/BlobCache.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/libs/utils/BlobCache.cpp b/libs/utils/BlobCache.cpp
index 1298fa7..590576a 100644
--- a/libs/utils/BlobCache.cpp
+++ b/libs/utils/BlobCache.cpp
@@ -31,9 +31,13 @@ BlobCache::BlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize
mMaxTotalSize(maxTotalSize),
mTotalSize(0) {
nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
+#ifdef _WIN32
+ srand(now);
+#else
mRandState[0] = (now >> 0) & 0xFFFF;
mRandState[1] = (now >> 16) & 0xFFFF;
mRandState[2] = (now >> 32) & 0xFFFF;
+#endif
LOGV("initializing random seed using %lld", now);
}
@@ -148,11 +152,19 @@ size_t BlobCache::get(const void* key, size_t keySize, void* value,
return valueBlobSize;
}
+long int BlobCache::blob_random() {
+#ifdef _WIN32
+ return rand();
+#else
+ return nrand48(mRandState);
+#endif
+}
+
void BlobCache::clean() {
// Remove a random cache entry until the total cache size gets below half
// the maximum total cache size.
while (mTotalSize > mMaxTotalSize / 2) {
- size_t i = size_t(nrand48(mRandState) % (mCacheEntries.size()));
+ size_t i = size_t(blob_random() % (mCacheEntries.size()));
const CacheEntry& entry(mCacheEntries[i]);
mTotalSize -= entry.getKey()->getSize() + entry.getValue()->getSize();
mCacheEntries.removeAt(i);