8
/*___INFO__MARK_BEGIN__*/
9
/*************************************************************************
11
* The Contents of this file are made available subject to the terms of
12
* the Sun Industry Standards Source License Version 1.2
14
* Sun Microsystems Inc., March, 2001
17
* Sun Industry Standards Source License Version 1.2
18
* =================================================
19
* The contents of this file are subject to the Sun Industry Standards
20
* Source License Version 1.2 (the "License"); You may not use this file
21
* except in compliance with the License. You may obtain a copy of the
22
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
24
* Software provided under this License is provided on an "AS IS" basis,
25
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
26
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
27
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
28
* See the License for the specific provisions governing your rights and
29
* obligations concerning the Software.
31
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
33
* Copyright: 2001 by Sun Microsystems, Inc.
35
* All Rights Reserved.
37
************************************************************************/
38
/*___INFO__MARK_END__*/
41
#include "cl_app_message_queue.h"
44
#ifdef __CL_FUNCTION__
45
#undef __CL_FUNCTION__
47
#define __CL_FUNCTION__ "cl_app_message_queue_setup()"
48
int cl_app_message_queue_setup(cl_raw_list_t** list_p, char* list_name, int enable_locking) {
50
ret_val = cl_raw_list_setup(list_p, list_name , enable_locking);
54
#ifdef __CL_FUNCTION__
55
#undef __CL_FUNCTION__
57
#define __CL_FUNCTION__ "cl_app_message_queue_cleanup()"
58
int cl_app_message_queue_cleanup(cl_raw_list_t** list_p) {
59
return cl_raw_list_cleanup(list_p);
63
#ifdef __CL_FUNCTION__
64
#undef __CL_FUNCTION__
66
#define __CL_FUNCTION__ "cl_app_message_queue_append()"
67
int cl_app_message_queue_append(cl_raw_list_t* list_p,
68
cl_com_connection_t* rcv_connection,
69
cl_com_endpoint_t* snd_destination,
70
cl_xml_ack_type_t snd_ack_type,
72
unsigned long snd_size,
73
unsigned long snd_response_mid,
74
unsigned long snd_tag,
78
cl_app_message_queue_elem_t* new_elem = NULL;
81
return CL_RETVAL_PARAMS;
84
/* add new element list */
85
new_elem = (cl_app_message_queue_elem_t*) malloc(sizeof(cl_app_message_queue_elem_t));
86
if (new_elem == NULL) {
87
return CL_RETVAL_MALLOC;
90
new_elem->rcv_connection = rcv_connection;
91
new_elem->snd_destination = snd_destination;
92
new_elem->snd_ack_type = snd_ack_type;
93
new_elem->snd_data = snd_data;
94
new_elem->snd_size = snd_size;
95
new_elem->snd_response_mid = snd_response_mid;
96
new_elem->snd_tag = snd_tag;
101
if ( ( ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
106
new_elem->raw_elem = cl_raw_list_append_elem(list_p, (void*) new_elem);
107
if ( new_elem->raw_elem == NULL) {
109
cl_raw_list_unlock(list_p);
112
return CL_RETVAL_MALLOC;
115
/* unlock the thread list */
117
if ( ( ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
125
#ifdef __CL_FUNCTION__
126
#undef __CL_FUNCTION__
128
#define __CL_FUNCTION__ "cl_app_message_queue_remove()"
129
int cl_app_message_queue_remove(cl_raw_list_t* list_p, cl_com_connection_t* connection, int do_lock, cl_bool_t remove_all_elements ) {
130
int function_return = CL_RETVAL_CONNECTION_NOT_FOUND;
131
int ret_val = CL_RETVAL_OK;
132
cl_app_message_queue_elem_t* elem = NULL;
133
cl_app_message_queue_elem_t* next_elem = NULL;
136
if (list_p == NULL || connection == NULL) {
137
return CL_RETVAL_PARAMS;
142
if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
147
elem = cl_app_message_queue_get_first_elem(list_p);
148
while ( elem != NULL) {
149
next_elem = cl_app_message_queue_get_next_elem(elem);
150
if (elem->rcv_connection == connection) {
151
/* found matching element */
152
cl_raw_list_remove_elem(list_p, elem->raw_elem);
155
function_return = CL_RETVAL_OK;
156
if (remove_all_elements == CL_FALSE) {
157
break; /* break here, we don't want to remove all elems */
164
/* unlock the thread list */
166
if ( ( ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
171
return function_return;
176
#ifdef __CL_FUNCTION__
177
#undef __CL_FUNCTION__
179
#define __CL_FUNCTION__ "cl_app_message_queue_get_first_elem()"
180
cl_app_message_queue_elem_t* cl_app_message_queue_get_first_elem(cl_raw_list_t* list_p) {
181
cl_raw_list_elem_t* raw_elem = cl_raw_list_get_first_elem(list_p);
183
return (cl_app_message_queue_elem_t*) raw_elem->data;
188
#ifdef __CL_FUNCTION__
189
#undef __CL_FUNCTION__
191
#define __CL_FUNCTION__ "cl_app_message_queue_get_least_elem()"
192
cl_app_message_queue_elem_t* cl_app_message_queue_get_least_elem(cl_raw_list_t* list_p) {
193
cl_raw_list_elem_t* raw_elem = cl_raw_list_get_least_elem(list_p);
195
return (cl_app_message_queue_elem_t*) raw_elem->data;
201
#ifdef __CL_FUNCTION__
202
#undef __CL_FUNCTION__
204
#define __CL_FUNCTION__ "cl_app_message_queue_get_next_elem()"
205
cl_app_message_queue_elem_t* cl_app_message_queue_get_next_elem(cl_app_message_queue_elem_t* elem) {
207
cl_raw_list_elem_t* next_raw_elem = NULL;
210
cl_raw_list_elem_t* raw_elem = elem->raw_elem;
211
next_raw_elem = cl_raw_list_get_next_elem(raw_elem);
213
return (cl_app_message_queue_elem_t*) next_raw_elem->data;
220
#ifdef __CL_FUNCTION__
221
#undef __CL_FUNCTION__
223
#define __CL_FUNCTION__ "cl_app_message_queue_get_last_elem()"
224
cl_app_message_queue_elem_t* cl_app_message_queue_get_last_elem(cl_app_message_queue_elem_t* elem) {
226
cl_raw_list_elem_t* last_raw_elem = NULL;
229
cl_raw_list_elem_t* raw_elem = elem->raw_elem;
230
last_raw_elem = cl_raw_list_get_last_elem(raw_elem);
232
return (cl_app_message_queue_elem_t*) last_raw_elem->data;