~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/comm/cl_app_message_queue.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <errno.h>
 
3
#include <string.h>
 
4
#include <sys/time.h>
 
5
#include <stdlib.h>
 
6
 
 
7
 
 
8
/*___INFO__MARK_BEGIN__*/
 
9
/*************************************************************************
 
10
 * 
 
11
 *  The Contents of this file are made available subject to the terms of
 
12
 *  the Sun Industry Standards Source License Version 1.2
 
13
 * 
 
14
 *  Sun Microsystems Inc., March, 2001
 
15
 * 
 
16
 * 
 
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
 
23
 * 
 
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.
 
30
 * 
 
31
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
32
 * 
 
33
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
34
 * 
 
35
 *   All Rights Reserved.
 
36
 * 
 
37
 ************************************************************************/
 
38
/*___INFO__MARK_END__*/
 
39
 
 
40
 
 
41
#include "cl_app_message_queue.h"
 
42
 
 
43
 
 
44
#ifdef __CL_FUNCTION__
 
45
#undef __CL_FUNCTION__
 
46
#endif
 
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) {
 
49
   int ret_val;
 
50
   ret_val = cl_raw_list_setup(list_p, list_name , enable_locking); 
 
51
   return ret_val;
 
52
}
 
53
 
 
54
#ifdef __CL_FUNCTION__
 
55
#undef __CL_FUNCTION__
 
56
#endif
 
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);
 
60
}
 
61
 
 
62
 
 
63
#ifdef __CL_FUNCTION__
 
64
#undef __CL_FUNCTION__
 
65
#endif
 
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,
 
71
                                cl_byte_t*            snd_data,
 
72
                                unsigned long         snd_size,
 
73
                                unsigned long         snd_response_mid,
 
74
                                unsigned long         snd_tag,
 
75
                                int                   do_lock) {
 
76
 
 
77
   int ret_val;
 
78
   cl_app_message_queue_elem_t* new_elem = NULL;
 
79
 
 
80
   if (list_p == NULL) {
 
81
      return CL_RETVAL_PARAMS;
 
82
   }
 
83
 
 
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;
 
88
   }
 
89
 
 
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;
 
97
 
 
98
 
 
99
   /* lock the list */
 
100
   if (do_lock != 0) {
 
101
      if (  ( ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
 
102
         return ret_val;
 
103
      }
 
104
   }
 
105
   
 
106
   new_elem->raw_elem = cl_raw_list_append_elem(list_p, (void*) new_elem);
 
107
   if ( new_elem->raw_elem == NULL) {
 
108
      if (do_lock != 0) {
 
109
         cl_raw_list_unlock(list_p);
 
110
      }
 
111
      free(new_elem);
 
112
      return CL_RETVAL_MALLOC;
 
113
   }
 
114
   
 
115
   /* unlock the thread list */
 
116
   if (do_lock != 0) {
 
117
      if (  ( ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
 
118
         return ret_val;
 
119
      }
 
120
   }
 
121
   return CL_RETVAL_OK;
 
122
}
 
123
 
 
124
 
 
125
#ifdef __CL_FUNCTION__
 
126
#undef __CL_FUNCTION__
 
127
#endif
 
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;
 
134
 
 
135
 
 
136
   if (list_p == NULL || connection == NULL) {
 
137
      return CL_RETVAL_PARAMS;
 
138
   }
 
139
 
 
140
   /* lock list */
 
141
   if (do_lock != 0) {
 
142
      if ( (ret_val = cl_raw_list_lock(list_p)) != CL_RETVAL_OK) {
 
143
         return ret_val;
 
144
      }
 
145
   }
 
146
 
 
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);
 
153
         free(elem);
 
154
         elem = NULL;
 
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 */
 
158
         }
 
159
      }
 
160
      elem = next_elem;
 
161
   } 
 
162
 
 
163
 
 
164
   /* unlock the thread list */
 
165
   if (do_lock != 0) {
 
166
      if (  ( ret_val = cl_raw_list_unlock(list_p)) != CL_RETVAL_OK) {
 
167
         return ret_val;
 
168
      }
 
169
   }
 
170
 
 
171
   return function_return;
 
172
}
 
173
 
 
174
 
 
175
 
 
176
#ifdef __CL_FUNCTION__
 
177
#undef __CL_FUNCTION__
 
178
#endif
 
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);
 
182
   if (raw_elem) {
 
183
      return (cl_app_message_queue_elem_t*) raw_elem->data;
 
184
   }
 
185
   return NULL;
 
186
}
 
187
 
 
188
#ifdef __CL_FUNCTION__
 
189
#undef __CL_FUNCTION__
 
190
#endif
 
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);
 
194
   if (raw_elem) {
 
195
      return (cl_app_message_queue_elem_t*) raw_elem->data;
 
196
   }
 
197
   return NULL;
 
198
}
 
199
 
 
200
 
 
201
#ifdef __CL_FUNCTION__
 
202
#undef __CL_FUNCTION__
 
203
#endif
 
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) {
 
206
 
 
207
   cl_raw_list_elem_t* next_raw_elem = NULL;
 
208
   
 
209
   if (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);
 
212
      if (next_raw_elem) {
 
213
         return (cl_app_message_queue_elem_t*) next_raw_elem->data;
 
214
      }
 
215
   }
 
216
   return NULL;
 
217
}
 
218
 
 
219
 
 
220
#ifdef __CL_FUNCTION__
 
221
#undef __CL_FUNCTION__
 
222
#endif
 
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) {
 
225
 
 
226
   cl_raw_list_elem_t* last_raw_elem = NULL;
 
227
   
 
228
   if (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);
 
231
      if (last_raw_elem) {
 
232
         return (cl_app_message_queue_elem_t*) last_raw_elem->data;
 
233
      }
 
234
   }
 
235
   return NULL;
 
236
}
 
237