re-org platform APIs, simplify porting process (#201)

Co-authored-by: Xu Jun <jun1.xu@intel.com>
This commit is contained in:
Xu Jun
2020-03-16 16:43:57 +08:00
committed by GitHub
parent ef5ceffe71
commit f1a0e75ab7
177 changed files with 2954 additions and 7904 deletions

View File

@ -6,10 +6,7 @@
#include "runtime_sensor.h"
#include "app_manager_export.h"
#include "module_wasm_app.h"
#include "bh_thread.h"
#include "bh_time.h"
#include "bh_common.h"
#include "bh_assert.h"
#include "bh_platform.h"
static sys_sensor_t * g_sys_sensors = NULL;
static int g_sensor_id_max = 0;
@ -103,11 +100,11 @@ wasm_sensor_config(wasm_exec_env_t exec_env,
module_inst);
bh_assert(mod_id != ID_NONE);
vm_mutex_lock(&s->lock);
os_mutex_lock(&s->lock);
c = find_sensor_client(s, mod_id, false);
if (c == NULL) {
vm_mutex_unlock(&s->lock);
os_mutex_unlock(&s->lock);
return false;
}
@ -115,7 +112,7 @@ wasm_sensor_config(wasm_exec_env_t exec_env,
c->bit_cfg = bit_cfg;
c->delay = delay;
vm_mutex_unlock(&s->lock);
os_mutex_unlock(&s->lock);
if (s->config != NULL) {
attr_cont = attr_container_create("config sensor");
@ -149,19 +146,19 @@ wasm_sensor_open(wasm_exec_env_t exec_env,
module_inst);
bh_assert(mod_id != ID_NONE);
vm_mutex_lock(&s->lock);
os_mutex_lock(&s->lock);
c = find_sensor_client(s, mod_id, false);
if (c) {
// the app already opened this sensor
vm_mutex_unlock(&s->lock);
os_mutex_unlock(&s->lock);
return -1;
}
sensor_client_t * client = (sensor_client_t*) wasm_runtime_malloc(
sizeof(sensor_client_t));
if (client == NULL) {
vm_mutex_unlock(&s->lock);
os_mutex_unlock(&s->lock);
return -1;
}
@ -172,7 +169,7 @@ wasm_sensor_open(wasm_exec_env_t exec_env,
client->next = s->clients;
s->clients = client;
vm_mutex_unlock(&s->lock);
os_mutex_unlock(&s->lock);
refresh_read_interval(s);
@ -218,10 +215,10 @@ wasm_sensor_close(wasm_exec_env_t exec_env, uint32 sensor)
if (s == NULL)
return false;
vm_mutex_lock(&s->lock);
os_mutex_lock(&s->lock);
if ((c = find_sensor_client(s, client_id, true)) != NULL)
wasm_runtime_free(c);
vm_mutex_unlock(&s->lock);
os_mutex_unlock(&s->lock);
refresh_read_interval(s);
@ -251,7 +248,7 @@ void refresh_read_interval(sensor_obj_t sensor)
{
sensor_client_t *c;
uint32 interval = sensor->default_interval;
vm_mutex_lock(&sensor->lock);
os_mutex_lock(&sensor->lock);
c = sensor->clients;
if (c)
@ -263,7 +260,7 @@ void refresh_read_interval(sensor_obj_t sensor)
c = c->next;
}
vm_mutex_unlock(&sensor->lock);
os_mutex_unlock(&sensor->lock);
sensor->read_interval = interval;
}
@ -310,7 +307,7 @@ add_sys_sensor(char * name, char * description, int instance,
g_sys_sensors = s;
}
vm_mutex_init(&s->lock);
os_mutex_init(&s->lock);
return s;
}
@ -366,7 +363,7 @@ sensor_client_t *find_sensor_client(sys_sensor_t * sensor,
int check_sensor_timers()
{
int ms_to_next_check = -1;
uint32 now = (uint32) bh_get_tick_ms();
uint32 now = (uint32)bh_get_tick_ms();
sys_sensor_t * s = g_sys_sensors;
while (s) {
@ -412,11 +409,11 @@ void sensor_cleanup_callback(uint32 module_id)
while (s) {
sensor_client_t *c;
vm_mutex_lock(&s->lock);
os_mutex_lock(&s->lock);
if ((c = find_sensor_client(s, module_id, true)) != NULL) {
wasm_runtime_free(c);
}
vm_mutex_unlock(&s->lock);
os_mutex_unlock(&s->lock);
s = s->next;
}
}

View File

@ -3,9 +3,7 @@
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
#include "bh_common.h"
#include "bh_queue.h"
#include "bh_thread.h"
#include "bh_platform.h"
#include "runtime_sensor.h"
#include "bi-inc/attr_container.h"
#include "module_wasm_app.h"
@ -91,15 +89,15 @@ static void thread_sensor_check(void * arg)
int ms_to_expiry = check_sensor_timers();
if (ms_to_expiry == -1)
ms_to_expiry = 5000;
vm_mutex_lock(&mutex);
vm_cond_reltimedwait(&cond, &mutex, ms_to_expiry);
vm_mutex_unlock(&mutex);
os_mutex_lock(&mutex);
os_cond_reltimedwait(&cond, &mutex, ms_to_expiry * 1000);
os_mutex_unlock(&mutex);
}
}
static void cb_wakeup_thread()
{
vm_cond_signal(&cond);
os_cond_signal(&cond);
}
void set_sensor_reshceduler(void (*callback)());
@ -107,8 +105,8 @@ void set_sensor_reshceduler(void (*callback)());
void init_sensor_framework()
{
// init the mutext and conditions
vm_cond_init(&cond);
vm_mutex_init(&mutex);
os_cond_init(&cond);
os_mutex_init(&mutex);
set_sensor_reshceduler(cb_wakeup_thread);
@ -123,9 +121,9 @@ void init_sensor_framework()
void start_sensor_framework()
{
korp_thread tid;
korp_tid tid;
vm_thread_create(&tid,
os_thread_create(&tid,
(void *)thread_sensor_check,
NULL,
BH_APPLET_PRESERVED_STACK_SIZE);