File: patcher_base_frame.c

package info (click to toggle)
openmpi 5.0.8-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 201,684 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (98 lines) | stat: -rw-r--r-- 2,551 bytes parent folder | download | duplicates (5)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2016      Los Alamos National Security, LLC. All rights
 *                         reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "opal_config.h"

#include "opal/mca/patcher/base/base.h"
#include "opal/mca/patcher/base/static-components.h"
#include "opal/mca/patcher/patcher.h"

/*
 * Local variables
 */
static mca_patcher_base_module_t empty_module;

/*
 * Globals
 */
mca_patcher_base_module_t *opal_patcher = &empty_module;

int opal_patcher_base_select(void)
{
    mca_patcher_base_module_t *best_module;
    mca_patcher_base_component_t *best_component;
    int rc, priority;

    rc = mca_base_select("patcher", opal_patcher_base_framework.framework_output,
                         &opal_patcher_base_framework.framework_components,
                         (mca_base_module_t **) &best_module,
                         (mca_base_component_t **) &best_component, &priority);
    if (OPAL_SUCCESS != rc) {
        return rc;
    }

    OBJ_CONSTRUCT(&best_module->patch_list, opal_list_t);
    OBJ_CONSTRUCT(&best_module->patch_list_mutex, opal_mutex_t);

    if (best_module->patch_init) {
        rc = best_module->patch_init();
        if (OPAL_SUCCESS != rc) {
            return rc;
        }
    }

    opal_patcher = best_module;

    return OPAL_SUCCESS;
}

int opal_patcher_base_restore_all(void)
{
    mca_patcher_base_patch_t *patch, *patch_next;

    if (opal_patcher == &empty_module) {
        return OPAL_SUCCESS;
    }

    opal_mutex_lock(&opal_patcher->patch_list_mutex);

    OPAL_LIST_FOREACH_SAFE_REV(patch, patch_next, &opal_patcher->patch_list, mca_patcher_base_patch_t) {
        patch->patch_restore (patch);
        opal_list_remove_item(&opal_patcher->patch_list, &patch->super);
        OBJ_RELEASE(patch);
    }

    opal_mutex_unlock(&opal_patcher->patch_list_mutex);

    return OPAL_SUCCESS;
}

static int opal_patcher_base_close(void)
{
    if (opal_patcher == &empty_module) {
        return OPAL_SUCCESS;
    }

    opal_patcher_base_restore_all();

    OPAL_LIST_DESTRUCT(&opal_patcher->patch_list);
    OBJ_DESTRUCT(&opal_patcher->patch_list_mutex);

    if (opal_patcher->patch_fini) {
        return opal_patcher->patch_fini();
    }

    return OPAL_SUCCESS;
}

/* Use default register/open functions */
MCA_BASE_FRAMEWORK_DECLARE(opal, patcher, "runtime code patching", NULL, NULL,
                           opal_patcher_base_close, mca_patcher_base_static_components, 0);