1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #include "../includes/common.h"
19 #include "../includes/memutils.h"
20 #include <media/stagefright/MetaDataBase.h>
21 #include <pthread.h>
22 
23 using namespace android;
24 using namespace std;
25 
26 char enable_selective_overload = ENABLE_NONE;
27 const int maxValue = 100000;
28 
even_thread(void * metaDataBase)29 void *even_thread(void *metaDataBase) {
30   MetaDataBase *metaDataBaseObj = (MetaDataBase *)metaDataBase;
31   for (int i = 0; i <= maxValue; i += 2) {
32     metaDataBaseObj->setInt32(i, i);
33   }
34   return nullptr;
35 }
36 
odd_thread(void * metaDataBase)37 void *odd_thread(void *metaDataBase) {
38   MetaDataBase *metaDataBaseObj = (MetaDataBase *)metaDataBase;
39   for (int i = 1; i <= maxValue; i += 2) {
40     metaDataBaseObj->setInt32(i, i);
41   }
42   return nullptr;
43 }
44 
main()45 int main() {
46   MetaDataBase metaDataBase = MetaDataBase();
47   pthread_t even_thread_id;
48   pthread_t odd_thread_id;
49 
50   enable_selective_overload = ENABLE_ALL;
51   pthread_create(&even_thread_id, nullptr, even_thread, &metaDataBase);
52   pthread_create(&odd_thread_id, nullptr, odd_thread, &metaDataBase);
53 
54   // Wait for the threads to finish
55   pthread_join(even_thread_id, nullptr);
56   pthread_join(odd_thread_id, nullptr);
57   enable_selective_overload = ENABLE_FREE_CHECK | ENABLE_REALLOC_CHECK;
58 
59   return EXIT_SUCCESS;
60 }
61