diff options
| author | Shuzhen Wang <shuzhenw@codeaurora.org> | 2014-01-27 16:06:57 -0800 |
|---|---|---|
| committer | Ali B <abittin@gmail.com> | 2018-06-17 19:19:52 +0300 |
| commit | 45c71859ea2a0fe174b8fa310d254120ab4f97b4 (patch) | |
| tree | 153c81bd74e94848f6fb6a77a612f0b66629f131 | |
| parent | 8db6f92194f9aad6313958b6bb6de67e9a002a8a (diff) | |
Camera3: Only use Plain Old Data for global variable
When a shared library is loaded, the order in which its global
variables is not defined. For example, for case like below:
A a;
int *ptr = NULL;
Class A {
A() {
if (ptr == NULL) {
//do this;
} else {
// do that;
}
}
};
ptr could be initialized before or after A, which causes the
behavior of A's constructor to be different.
The fix is to use Plain Old Data (integer, float, char, or pointer)
as global variable, and defer instantiation of class instance to
runtime.
Bug: 11822202
Change-Id: I806c527f06e19fc44e880d9a536ee7a060b4fa4f
Signed-off-by: Daniel Jarai <jaraidaniel@gmail.com>
| -rw-r--r-- | camera/QCamera2/HAL3/QCamera3Factory.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/camera/QCamera2/HAL3/QCamera3Factory.cpp b/camera/QCamera2/HAL3/QCamera3Factory.cpp index 8094087..df3bef7 100644 --- a/camera/QCamera2/HAL3/QCamera3Factory.cpp +++ b/camera/QCamera2/HAL3/QCamera3Factory.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2013, The Linux Foundataion. All rights reserved. +/* Copyright (c) 2012-2014, The Linux Foundataion. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -40,7 +40,7 @@ using namespace android; namespace qcamera { -QCamera3Factory gQCamera3Factory; +QCamera3Factory *gQCamera3Factory = NULL; /*=========================================================================== * FUNCTION : QCamera3Factory @@ -80,7 +80,14 @@ QCamera3Factory::~QCamera3Factory() *==========================================================================*/ int QCamera3Factory::get_number_of_cameras() { - return gQCamera3Factory.getNumberOfCameras(); + if (!gQCamera3Factory) { + gQCamera3Factory = new QCamera3Factory(); + if (!gQCamera3Factory) { + ALOGE("%s: Failed to allocate Camera3Factory object", __func__); + return 0; + } + } + return gQCamera3Factory->getNumberOfCameras(); } /*=========================================================================== @@ -98,7 +105,7 @@ int QCamera3Factory::get_number_of_cameras() *==========================================================================*/ int QCamera3Factory::get_camera_info(int camera_id, struct camera_info *info) { - return gQCamera3Factory.getCameraInfo(camera_id, info); + return gQCamera3Factory->getCameraInfo(camera_id, info); } /*=========================================================================== @@ -201,7 +208,7 @@ int QCamera3Factory::camera_device_open( ALOGE("Invalid camera id"); return BAD_VALUE; } - return gQCamera3Factory.cameraDeviceOpen(atoi(id), hw_device); + return gQCamera3Factory->cameraDeviceOpen(atoi(id), hw_device); } struct hw_module_methods_t QCamera3Factory::mModuleMethods = { |
