Line data Source code
1 : /* Copyright 2017 noseglasses <shinynoseglasses@gmail.com>
2 : *
3 : * This program is free software: you can redistribute it and/or modify
4 : * it under the terms of the GNU Lesser General Public License as published by
5 : * the Free Software Foundation, either version 3 of the License, or
6 : * (at your option) any later version.
7 : *
8 : * This program is distributed in the hope that it will be useful,
9 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 : * GNU Lesser General Public License for more details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 : */
16 :
17 : #include "ppg_context.h"
18 : #include "detail/ppg_context_detail.h"
19 : #include "detail/ppg_furcation_detail.h"
20 : #include "ppg_debug.h"
21 : #include "detail/ppg_malloc_detail.h"
22 :
23 : #include <stdlib.h>
24 :
25 41 : void* ppg_context_create(void)
26 : {
27 : // PPG_LOG("Cr. new cntxt\n");
28 :
29 41 : PPG_Context *context = (PPG_Context *)PPG_MALLOC(sizeof(PPG_Context));
30 :
31 41 : ppg_global_initialize_context(context);
32 :
33 41 : return context;
34 : }
35 :
36 41 : void ppg_context_destroy(void *context)
37 : {
38 41 : PPG_Context *context__ = (PPG_Context *)context;
39 :
40 41 : if(!context__->properties.destruction_enabled) { return; }
41 :
42 41 : ppg_event_buffer_free(&context__->event_buffer);
43 41 : ppg_furcation_stack_free(&context__->furcation_stack);
44 41 : ppg_active_tokens_free(&context__->active_tokens);
45 :
46 41 : ppg_token_destroy(context__->pattern_root);
47 :
48 41 : free(context__->pattern_root);
49 :
50 41 : free(context__);
51 : }
52 :
53 : #if !PPG_DISABLE_CONTEXT_SWITCHING
54 :
55 53 : void* ppg_global_set_current_context(void *context)
56 : {
57 53 : void *old_context = ppg_context;
58 :
59 53 : ppg_context = (PPG_Context *)context;
60 :
61 53 : return old_context;
62 : }
63 :
64 40 : void* ppg_global_get_current_context(void)
65 : {
66 40 : return ppg_context;
67 : }
68 :
69 : #endif
|