1/*
2 * omp-state.cpp -- OMPD states
3 */
4
5//===----------------------------------------------------------------------===//
6//
7// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8// See https://llvm.org/LICENSE.txt for license information.
9// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10//
11//===----------------------------------------------------------------------===//
12
13#include "omp-debug.h"
14#include "ompd-private.h"
15#include <cstring>
16
17void __ompd_init_states(const ompd_callbacks_t *table) { callbacks = table; }
18
19static const char *get_ompd_state_name(ompd_word_t state) {
20 switch (state) {
21#define ompd_state_macro(state, code) \
22 case code: \
23 return #state;
24 FOREACH_OMPD_STATE(ompd_state_macro)
25#undef ompd_state_macro
26 default:
27 return NULL;
28 }
29}
30
31ompd_rc_t
32ompd_enumerate_states(ompd_address_space_handle_t *address_space_handle,
33 ompd_word_t current_state, ompd_word_t *next_state,
34 const char **next_state_name, ompd_word_t *more_enums) {
35 ompd_rc_t ret;
36 if (current_state > ompt_state_undefined &&
37 current_state >= OMPD_LAST_OMP_STATE) {
38 return ompd_rc_bad_input;
39 }
40 const char *find_next_state_name;
41 *next_state = (current_state == ompt_state_undefined ? ompt_state_work_serial
42 : current_state + 1);
43 while (!(find_next_state_name = get_ompd_state_name(state: *next_state))) {
44 ++(*next_state);
45 }
46
47 char *next_state_name_cpy;
48 ret = callbacks->alloc_memory(strlen(s: find_next_state_name) + 1,
49 (void **)&next_state_name_cpy);
50 if (ret != ompd_rc_ok) {
51 return ret;
52 }
53 strcpy(dest: next_state_name_cpy, src: find_next_state_name);
54
55 *next_state_name = next_state_name_cpy;
56
57 if (*next_state == OMPD_LAST_OMP_STATE) {
58 *more_enums = 0;
59 } else {
60 *more_enums = 1;
61 }
62
63 return ompd_rc_ok;
64}
65

source code of openmp/libompd/src/omp-state.cpp