summaryrefslogtreecommitdiffstats
path: root/src/framework/init/fw_module.h
blob: a3da4f4ebf82ebdbe7bdf9f79a87db338158334b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
*
* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef _FW_MODULE
#define _FW_MODULE
#include <pthread.h>
#include "nsfw_init_api.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C"{
/* *INDENT-ON* */
#endif /* _cplusplus */

/* Unique name declare */
#define NSFW__STRINGIFY(x) #x
#define NSFW_STRINGIFY(x) NSFW__STRINGIFY(x)

#define NSFW__PASTE(a,b) a##b
#define NSFW_PASTE(a,b) NSFW__PASTE(a,b)

#define NSFW_UNIQUE_ID(prefix) NSFW_PASTE(NSFW_PASTE(__LINE__, prefix), __COUNTER__)

#define NSFW_MODULE_INITFN(_fn) \
    static int _fn(void* param)

#define NSFW_DEPENDS_SIZE 8

#define NSFW_MODULE_SET_STATE(inst, state) ((inst)->stat = (state))

/*Change module malloc to pool array*/
#define NSFW_MODULE_INSTANCE_POOL_SIZE 64
#define NSFW_MODULE_DEPENDS_POOL_SIZE 128

typedef struct _nsfw_module_done_node
{
    nsfw_module_instance_t *inst;
    struct _nsfw_module_done_node *next;
} nsfw_module_done_node_t;

typedef struct _nsfw_module_manager
{
    pthread_mutex_t initMutex;
    int done;                   // 0 - not finished, 1 - finished, -1 - error
    nsfw_module_instance_t *inst;
    nsfw_module_done_node_t *doneHead;
} nsfw_module_manager_t;

extern int nsfw_module_add_done_node(nsfw_module_instance_t * inst);

extern nsfw_module_manager_t g_nsfw_module_manager;
#define nsfw_module_get_manager() (&g_nsfw_module_manager)

typedef struct _nsfw_module_instance_pool
{
    int last_idx;
      nsfw_module_instance_t
        module_instance_pool[NSFW_MODULE_INSTANCE_POOL_SIZE];
} nsfw_module_instance_pool_t;

typedef struct _nsfw_module_depends_pool
{
    int last_idx;
    nsfw_module_depends_t module_depends_pool[NSFW_MODULE_DEPENDS_POOL_SIZE];
} nsfw_module_depends_pool_t;

#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif /* _cplusplus */

#endif /* _FW_MODULE */