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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
*
* The Contents of this file are made available subject to the terms of
* the Sun Industry Standards Source License Version 1.2
*
* Sun Microsystems Inc., March, 2001
*
*
* Sun Industry Standards Source License Version 1.2
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.2 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2007 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
************************************************************************/
/*___INFO__MARK_END__*/
#include <string.h>
#include "uti/sge_rmon.h"
#include "uti/sge_log.h"
#include "uti/sge_sl.h"
#include "gdi/sge_gdi2.h"
#include "gdi/sge_gdi_ctx.h"
#include "sgeobj/sge_answer.h"
#include "sge_sched_order.h"
#include "msg_common.h"
gdi_request_queue_t Master_Request_Queue;
bool
schedd_order_initialize(void) {
bool ret = true;
DENTER(TOP_LAYER, "schedd_order_initialize");
Master_Request_Queue.order_list = NULL;
ret &= sge_sl_create(&Master_Request_Queue.request_list);
DRETURN(ret);
}
bool
schedd_order_destroy(void) {
bool ret = true;
DENTER(TOP_LAYER, "schedd_order_initialize");
ret &= sge_sl_destroy(&Master_Request_Queue.request_list, NULL);
DRETURN(ret);
}
bool
sge_schedd_send_orders(sge_gdi_ctx_class_t *ctx, order_t *orders, lList **order_list, lList **answer_list, const char *name)
{
bool ret = true;
DENTER(TOP_LAYER, "sge_schedd_send_orders");
if ((order_list != NULL) && (*order_list != NULL) && (lGetNumberOfElem(*order_list) != 0)) {
/*
* Add the new orders
*/
if (Master_Request_Queue.order_list == NULL) {
Master_Request_Queue.order_list = *order_list;
*order_list = NULL;
} else {
lAddList(Master_Request_Queue.order_list, order_list);
}
ret = sge_schedd_add_gdi_order_request(ctx, orders, answer_list, &Master_Request_Queue.order_list);
}
lFreeList(order_list);
DRETURN(ret);
}
bool
sge_schedd_add_gdi_order_request(sge_gdi_ctx_class_t *ctx, order_t *orders, lList **answer_list, lList **order_list)
{
bool ret = true;
state_gdi_multi *state = NULL;
DENTER(TOP_LAYER, "sge_schedd_add_gdi_order_request");
state = (state_gdi_multi *)sge_malloc(sizeof(state_gdi_multi));
if (state != NULL) {
int order_id;
memset(state, 0, sizeof(state_gdi_multi));
orders->numberSendOrders += lGetNumberOfElem(*order_list);
orders->numberSendPackages++;
/*
* order_list will be NULL after the call of gdi_multi. This saves a copy operation.
*/
order_id = ctx->gdi_multi(ctx, answer_list, SGE_GDI_SEND, SGE_ORDER_LIST, SGE_GDI_ADD,
order_list, NULL, NULL, false, state, false);
if (order_id != -1) {
sge_sl_insert(Master_Request_Queue.request_list, state, SGE_SL_BACKWARD);
/* EB: TODO: Why is this needed? */
state->next = NULL;
} else {
answer_list_log(answer_list, false, false);
ret = false;
}
} else {
answer_list_add(answer_list, MSG_SGETEXT_NOMEM, STATUS_EMALLOC, ANSWER_QUALITY_ERROR);
ret = false;
}
DRETURN(ret);
}
bool
sge_schedd_block_until_orders_processed(sge_gdi_ctx_class_t *ctx,
lList **answer_list)
{
bool ret = true;
sge_sl_elem_t *next_elem = NULL;
sge_sl_elem_t *current_elem = NULL;
DENTER(TOP_LAYER, "sge_schedd_block_until_orders_processed");
/*
* wait till all GDI order requests are finished
*/
sge_sl_elem_next(Master_Request_Queue.request_list, &next_elem, SGE_SL_FORWARD);
while ((current_elem = next_elem) != NULL) {
state_gdi_multi *current_state = sge_sl_elem_data(current_elem);
lList *request_answer_list = NULL;
lList *multi_answer_list = NULL;
int order_id;
/* get next element, dechain current and destroy it */
sge_sl_elem_next(Master_Request_Queue.request_list, &next_elem, SGE_SL_FORWARD);
sge_sl_dechain(Master_Request_Queue.request_list, current_elem);
sge_sl_elem_destroy(¤t_elem, NULL);
/*
* wait for answer. this call might block if the request
* has not been handled by any worker until now
*/
ctx->gdi_wait(ctx, answer_list, &multi_answer_list, current_state);
/*
* now we have an answer. is it positive?
*/
order_id = 1;
sge_gdi_extract_answer(&request_answer_list, SGE_GDI_ADD, SGE_ORDER_LIST,
order_id, multi_answer_list, NULL);
if (request_answer_list != NULL) {
answer_list_log(&request_answer_list, false, false);
ret = false;
}
/*
* memory cleanup
*/
lFreeList(&request_answer_list);
lFreeList(&multi_answer_list);
sge_free(¤t_state);
}
DRETURN(ret);
}
|