Mercurial > hg > freeDiameter
annotate libfdproto/fifo.c @ 1288:389c26b904d7
Added a comment in the OSX file.
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Sun, 03 May 2015 21:04:54 +0800 |
parents | f40de74bd1c7 |
children | ce257e43085d |
rev | line source |
---|---|
0 | 1 /********************************************************************************************************* |
2 * Software License Agreement (BSD License) * | |
740
4a9f08d6b6ba
Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
662
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
0 | 4 * * |
1127
1af09cc156d6
Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1104
diff
changeset
|
5 * Copyright (c) 2013, WIDE Project and NICT * |
0 | 6 * All rights reserved. * |
7 * * | |
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * | |
9 * permitted provided that the following conditions are met: * | |
10 * * | |
11 * * Redistributions of source code must retain the above * | |
12 * copyright notice, this list of conditions and the * | |
13 * following disclaimer. * | |
14 * * | |
15 * * Redistributions in binary form must reproduce the above * | |
16 * copyright notice, this list of conditions and the * | |
17 * following disclaimer in the documentation and/or other * | |
18 * materials provided with the distribution. * | |
19 * * | |
20 * * Neither the name of the WIDE Project or NICT nor the * | |
21 * names of its contributors may be used to endorse or * | |
22 * promote products derived from this software without * | |
23 * specific prior written permission of WIDE Project and * | |
24 * NICT. * | |
25 * * | |
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * | |
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * | |
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * | |
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * | |
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * | |
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * | |
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * | |
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * | |
34 *********************************************************************************************************/ | |
35 | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
36 /* FIFO queues module. |
0 | 37 * |
38 * The threads that call these functions must be in the cancellation state PTHREAD_CANCEL_ENABLE and type PTHREAD_CANCEL_DEFERRED. | |
39 * This is the default state and type on thread creation. | |
40 * | |
41 * In order to destroy properly a queue, the application must: | |
42 * -> shutdown any process that can add into the queue first. | |
43 * -> pthread_cancel any thread that could be waiting on the queue. | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
44 * -> consume any element that is in the queue, using fd_qu_tryget_int. |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
45 * -> then destroy the queue using fd_mq_del. |
0 | 46 */ |
47 | |
658
f198d16fa7f4
Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
451
diff
changeset
|
48 #include "fdproto-internal.h" |
0 | 49 |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
50 /* Definition of a FIFO queue object */ |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
51 struct fifo { |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
52 int eyec; /* An eye catcher, also used to check a queue is valid. FIFO_EYEC */ |
0 | 53 |
54 pthread_mutex_t mtx; /* Mutex protecting this queue */ | |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
55 pthread_cond_t cond_pull; /* condition variable for pulling threads */ |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
56 pthread_cond_t cond_push; /* condition variable for pushing threads */ |
0 | 57 |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
58 struct fd_list list; /* sentinel for the list of elements */ |
0 | 59 int count; /* number of objects in the list */ |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
60 int thrs; /* number of threads waiting for a new element (when count is 0) */ |
0 | 61 |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
62 int max; /* maximum number of items to accept if not 0 */ |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
63 int thrs_push; /* number of threads waitnig to push an item */ |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
64 |
1
bafb831ba688
Fix names to proper case for freeDiameter
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
0
diff
changeset
|
65 uint16_t high; /* High level threshold (see libfreeDiameter.h for details) */ |
0 | 66 uint16_t low; /* Low level threshhold */ |
67 void *data; /* Opaque pointer for threshold callbacks */ | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
68 void (*h_cb)(struct fifo *, void **); /* The callbacks */ |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
69 void (*l_cb)(struct fifo *, void **); |
0 | 70 int highest;/* The highest count value for which h_cb has been called */ |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
11
diff
changeset
|
71 int highest_ever; /* The max count value this queue has reached (for tweaking) */ |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
72 |
1067
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
73 long long total_items; /* Cumulated number of items that went through this fifo (excluding current count), always increasing. */ |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
74 struct timespec total_time; /* Cumulated time all items spent in this queue, including blocking time (always growing, use deltas for monitoring) */ |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
75 struct timespec blocking_time; /* Cumulated time threads trying to post new items were blocked (queue full). */ |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
76 struct timespec last_time; /* For the last element retrieved from the queue, how long it take between posting (including blocking) and poping */ |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
77 |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
78 }; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
79 |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
80 struct fifo_item { |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
81 struct fd_list item; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
82 struct timespec posted_on; |
0 | 83 }; |
84 | |
85 /* The eye catcher value */ | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
86 #define FIFO_EYEC 0xe7ec1130 |
0 | 87 |
88 /* Macro to check a pointer */ | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
89 #define CHECK_FIFO( _queue ) (( (_queue) != NULL) && ( (_queue)->eyec == FIFO_EYEC) ) |
0 | 90 |
91 | |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
92 /* Create a new queue, with max number of items -- use 0 for no max */ |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
93 int fd_fifo_new ( struct fifo ** queue, int max ) |
0 | 94 { |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
95 struct fifo * new; |
0 | 96 |
97 TRACE_ENTRY( "%p", queue ); | |
98 | |
99 CHECK_PARAMS( queue ); | |
100 | |
101 /* Create a new object */ | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
102 CHECK_MALLOC( new = malloc (sizeof (struct fifo) ) ); |
0 | 103 |
104 /* Initialize the content */ | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
105 memset(new, 0, sizeof(struct fifo)); |
0 | 106 |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
107 new->eyec = FIFO_EYEC; |
0 | 108 CHECK_POSIX( pthread_mutex_init(&new->mtx, NULL) ); |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
109 CHECK_POSIX( pthread_cond_init(&new->cond_pull, NULL) ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
110 CHECK_POSIX( pthread_cond_init(&new->cond_push, NULL) ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
111 new->max = max; |
0 | 112 |
113 fd_list_init(&new->list, NULL); | |
114 | |
115 /* We're done */ | |
116 *queue = new; | |
117 return 0; | |
118 } | |
119 | |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
120 /* Dump the content of a queue */ |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
121 DECLARE_FD_DUMP_PROTOTYPE(fd_fifo_dump, char * name, struct fifo * queue, fd_fifo_dump_item_cb dump_item) |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
122 { |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
123 FD_DUMP_HANDLE_OFFSET(); |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
124 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
125 if (name) { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
126 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "'%s'(@%p): ", name, queue), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
127 } else { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
128 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "{fifo}(@%p): ", queue), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
129 } |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
130 |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
131 if (!CHECK_FIFO( queue )) { |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
132 return fd_dump_extend(FD_DUMP_STD_PARAMS, "INVALID/NULL"); |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
133 } |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
134 |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
135 CHECK_POSIX_DO( pthread_mutex_lock( &queue->mtx ), /* continue */ ); |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
136 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "items:%d,%d,%d threads:%d,%d stats:%lld/%ld.%06ld,%ld.%06ld,%ld.%06ld thresholds:%d,%d,%d,%p,%p,%p", |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
137 queue->count, queue->highest_ever, queue->max, |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
138 queue->thrs, queue->thrs_push, |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
139 queue->total_items,(long)queue->total_time.tv_sec,(long)(queue->total_time.tv_nsec/1000),(long)queue->blocking_time.tv_sec,(long)(queue->blocking_time.tv_nsec/1000),(long)queue->last_time.tv_sec,(long)(queue->last_time.tv_nsec/1000), |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
140 queue->high, queue->low, queue->highest, queue->h_cb, queue->l_cb, queue->data), |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
141 goto error); |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
142 |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
143 if (dump_item) { |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
144 struct fd_list * li; |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
145 int i = 0; |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
146 for (li = queue->list.next; li != &queue->list; li = li->next) { |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
147 struct fifo_item * fi = (struct fifo_item *)li; |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
148 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n [#%i](@%p)@%ld.%06ld: ", |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
149 i++, fi->item.o, (long)fi->posted_on.tv_sec,(long)(fi->posted_on.tv_nsec/1000)), |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
150 goto error); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
151 CHECK_MALLOC_DO( (*dump_item)(FD_DUMP_STD_PARAMS, fi->item.o), goto error); |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
152 } |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
153 } |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
154 CHECK_POSIX_DO( pthread_mutex_unlock( &queue->mtx ), /* continue */ ); |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
155 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
156 return *buf; |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
157 error: |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
158 CHECK_POSIX_DO( pthread_mutex_unlock( &queue->mtx ), /* continue */ ); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1073
diff
changeset
|
159 return NULL; |
10
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
160 } |
c5c99c73c2bf
Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
8
diff
changeset
|
161 |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
162 /* Delete a queue. It must be empty. */ |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
163 int fd_fifo_del ( struct fifo ** queue ) |
0 | 164 { |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
165 struct fifo * q; |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
166 int loops = 0; |
0 | 167 |
168 TRACE_ENTRY( "%p", queue ); | |
169 | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
170 CHECK_PARAMS( queue && CHECK_FIFO( *queue ) ); |
0 | 171 |
172 q = *queue; | |
173 | |
174 CHECK_POSIX( pthread_mutex_lock( &q->mtx ) ); | |
175 | |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
176 if ((q->count != 0) || (q->data != NULL)) { |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
177 TRACE_DEBUG(INFO, "The queue cannot be destroyed (%d, %p)", q->count, q->data); |
0 | 178 CHECK_POSIX_DO( pthread_mutex_unlock( &q->mtx ), /* no fallback */ ); |
179 return EINVAL; | |
180 } | |
181 | |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
182 /* Ok, now invalidate the queue */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
183 q->eyec = 0xdead; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
184 |
156
e2dc300819b3
Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
139
diff
changeset
|
185 /* Have all waiting threads return an error */ |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
186 while (q->thrs) { |
138
4249a55f859a
Attempt to fix behavior on multi-CPU platforms
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
137
diff
changeset
|
187 CHECK_POSIX( pthread_mutex_unlock( &q->mtx )); |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
188 CHECK_POSIX( pthread_cond_signal(&q->cond_pull) ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
189 usleep(1000); |
139
8b8d11fadc4e
Attempt to fix behavior on multi-CPU platforms, take 2
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
138
diff
changeset
|
190 |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
191 CHECK_POSIX( pthread_mutex_lock( &q->mtx ) ); |
139
8b8d11fadc4e
Attempt to fix behavior on multi-CPU platforms, take 2
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
138
diff
changeset
|
192 ASSERT( ++loops < 20 ); /* detect infinite loops */ |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
193 } |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
194 |
0 | 195 /* sanity check */ |
196 ASSERT(FD_IS_LIST_EMPTY(&q->list)); | |
197 | |
198 /* And destroy it */ | |
199 CHECK_POSIX( pthread_mutex_unlock( &q->mtx ) ); | |
200 | |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
201 CHECK_POSIX_DO( pthread_cond_destroy( &q->cond_pull ), ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
202 |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
203 CHECK_POSIX_DO( pthread_cond_destroy( &q->cond_push ), ); |
0 | 204 |
451
4395961aad27
Some libc seem to have an issue with canceled threads...
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
450
diff
changeset
|
205 CHECK_POSIX_DO( pthread_mutex_destroy( &q->mtx ), ); |
0 | 206 |
207 free(q); | |
208 *queue = NULL; | |
209 | |
210 return 0; | |
211 } | |
212 | |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
213 /* Move the content of old into new, and update loc_update atomically. We leave the old queue empty but valid */ |
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
214 int fd_fifo_move ( struct fifo * old, struct fifo * new, struct fifo ** loc_update ) |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
215 { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
216 int loops = 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
217 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
218 TRACE_ENTRY("%p %p %p", old, new, loc_update); |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
219 CHECK_PARAMS( CHECK_FIFO( old ) && CHECK_FIFO( new )); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
220 |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
221 CHECK_PARAMS( ! old->data ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
222 if (new->high) { |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
223 TODO("Implement support for thresholds in fd_fifo_move..."); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
224 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
225 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
226 /* Update loc_update */ |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
227 if (loc_update) |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
228 *loc_update = new; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
229 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
230 /* Lock the queues */ |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
231 CHECK_POSIX( pthread_mutex_lock( &old->mtx ) ); |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
232 |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
233 CHECK_PARAMS_DO( (! old->thrs_push), { |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
234 pthread_mutex_unlock( &old->mtx ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
235 return EINVAL; |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
236 } ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
237 |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
238 CHECK_POSIX( pthread_mutex_lock( &new->mtx ) ); |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
239 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
240 /* Any waiting thread on the old queue returns an error */ |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
241 old->eyec = 0xdead; |
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
242 while (old->thrs) { |
138
4249a55f859a
Attempt to fix behavior on multi-CPU platforms
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
137
diff
changeset
|
243 CHECK_POSIX( pthread_mutex_unlock( &old->mtx )); |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
244 CHECK_POSIX( pthread_cond_signal( &old->cond_pull ) ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
245 usleep(1000); |
139
8b8d11fadc4e
Attempt to fix behavior on multi-CPU platforms, take 2
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
138
diff
changeset
|
246 |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
247 CHECK_POSIX( pthread_mutex_lock( &old->mtx ) ); |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
248 ASSERT( loops < 20 ); /* detect infinite loops */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
249 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
250 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
251 /* Move all data from old to new */ |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
252 fd_list_move_end( &new->list, &old->list ); |
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
253 if (old->count && (!new->count)) { |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
254 CHECK_POSIX( pthread_cond_signal(&new->cond_pull) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
255 } |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
256 new->count += old->count; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
257 |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
258 /* Reset old */ |
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
259 old->count = 0; |
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
260 old->eyec = FIFO_EYEC; |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
261 |
1067
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
262 /* Merge the stats in the new queue */ |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
263 new->total_items += old->total_items; |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
264 old->total_items = 0; |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
265 |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
266 new->total_time.tv_nsec += old->total_time.tv_nsec; |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
267 new->total_time.tv_sec += old->total_time.tv_sec + (new->total_time.tv_nsec / 1000000000); |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
268 new->total_time.tv_nsec %= 1000000000; |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
269 old->total_time.tv_nsec = 0; |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
270 old->total_time.tv_sec = 0; |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
271 |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
272 new->blocking_time.tv_nsec += old->blocking_time.tv_nsec; |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
273 new->blocking_time.tv_sec += old->blocking_time.tv_sec + (new->blocking_time.tv_nsec / 1000000000); |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
274 new->blocking_time.tv_nsec %= 1000000000; |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
275 old->blocking_time.tv_nsec = 0; |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
276 old->blocking_time.tv_sec = 0; |
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
277 |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
278 /* Unlock, we're done */ |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
279 CHECK_POSIX( pthread_mutex_unlock( &new->mtx ) ); |
43
2db15632a63d
Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
25
diff
changeset
|
280 CHECK_POSIX( pthread_mutex_unlock( &old->mtx ) ); |
25
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
281 |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
282 return 0; |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
283 } |
67ca08d5bc48
Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
21
diff
changeset
|
284 |
1071
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
285 /* Get the information on the queue */ |
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
286 int fd_fifo_getstats( struct fifo * queue, int * current_count, int * limit_count, int * highest_count, long long * total_count, |
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
287 struct timespec * total, struct timespec * blocking, struct timespec * last) |
0 | 288 { |
1071
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
289 TRACE_ENTRY( "%p %p %p %p %p %p %p %p", queue, current_count, limit_count, highest_count, total_count, total, blocking, last); |
0 | 290 |
291 /* Check the parameters */ | |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
292 CHECK_PARAMS( CHECK_FIFO( queue ) ); |
0 | 293 |
294 /* lock the queue */ | |
295 CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) ); | |
296 | |
1071
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
297 if (current_count) |
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
298 *current_count = queue->count; |
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
299 |
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
300 if (limit_count) |
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
301 *limit_count = queue->max; |
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
302 |
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
303 if (highest_count) |
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
304 *highest_count = queue->highest_ever; |
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
305 |
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
306 if (total_count) |
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
307 *total_count = queue->total_items; |
1067
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
308 |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
309 if (total) |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
310 memcpy(total, &queue->total_time, sizeof(struct timespec)); |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
311 |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
312 if (blocking) |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
313 memcpy(blocking, &queue->blocking_time, sizeof(struct timespec)); |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
314 |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
315 if (last) |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
316 memcpy(last, &queue->last_time, sizeof(struct timespec)); |
0 | 317 |
318 /* Unlock */ | |
319 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) ); | |
320 | |
321 /* Done */ | |
322 return 0; | |
323 } | |
324 | |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
325 |
0 | 326 /* alternate version with no error checking */ |
1071
6ca6cadf209c
Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1067
diff
changeset
|
327 int fd_fifo_length ( struct fifo * queue ) |
0 | 328 { |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
329 if ( !CHECK_FIFO( queue ) ) |
0 | 330 return 0; |
331 | |
332 return queue->count; /* Let's hope it's read atomically, since we are not locking... */ | |
333 } | |
334 | |
335 /* Set the thresholds of the queue */ | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
336 int fd_fifo_setthrhd ( struct fifo * queue, void * data, uint16_t high, void (*h_cb)(struct fifo *, void **), uint16_t low, void (*l_cb)(struct fifo *, void **) ) |
0 | 337 { |
338 TRACE_ENTRY( "%p %p %hu %p %hu %p", queue, data, high, h_cb, low, l_cb ); | |
339 | |
340 /* Check the parameters */ | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
341 CHECK_PARAMS( CHECK_FIFO( queue ) && (high > low) && (queue->data == NULL) ); |
0 | 342 |
343 /* lock the queue */ | |
344 CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) ); | |
345 | |
346 /* Save the values */ | |
347 queue->high = high; | |
348 queue->low = low; | |
349 queue->data = data; | |
350 queue->h_cb = h_cb; | |
351 queue->l_cb = l_cb; | |
352 | |
353 /* Unlock */ | |
354 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) ); | |
355 | |
356 /* Done */ | |
357 return 0; | |
358 } | |
359 | |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
360 |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
361 /* This handler is called when a thread is blocked on a queue, and cancelled */ |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
362 static void fifo_cleanup_push(void * queue) |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
363 { |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
364 struct fifo * q = (struct fifo *)queue; |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
365 TRACE_ENTRY( "%p", queue ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
366 |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
367 /* The thread has been cancelled, therefore it does not wait on the queue anymore */ |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
368 q->thrs_push--; |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
369 |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
370 /* Now unlock the queue, and we're done */ |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
371 CHECK_POSIX_DO( pthread_mutex_unlock( &q->mtx ), /* nothing */ ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
372 |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
373 /* End of cleanup handler */ |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
374 return; |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
375 } |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
376 |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
377 |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
378 /* Post a new item in the queue */ |
1188
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
379 int fd_fifo_post_internal ( struct fifo * queue, void ** item, int skip_max ) |
0 | 380 { |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
381 struct fifo_item * new; |
0 | 382 int call_cb = 0; |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
383 struct timespec posted_on, queued_on; |
0 | 384 |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
385 /* Get the timing of this call */ |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
386 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &posted_on) ); |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
387 |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
388 /* lock the queue */ |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
389 CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
390 |
1188
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
391 if ((!skip_max) && (queue->max)) { |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
392 while (queue->count >= queue->max) { |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
393 int ret = 0; |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
394 |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
395 /* We have to wait for an item to be pulled */ |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
396 queue->thrs_push++ ; |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
397 pthread_cleanup_push( fifo_cleanup_push, queue); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
398 ret = pthread_cond_wait( &queue->cond_push, &queue->mtx ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
399 pthread_cleanup_pop(0); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
400 queue->thrs_push-- ; |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
401 |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
402 ASSERT( ret == 0 ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
403 } |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
404 } |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
405 |
0 | 406 /* Create a new list item */ |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
407 CHECK_MALLOC_DO( new = malloc (sizeof (struct fifo_item)) , { |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
408 pthread_mutex_unlock( &queue->mtx ); |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
409 return ENOMEM; |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
410 } ); |
0 | 411 |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
412 fd_list_init(&new->item, *item); |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
413 *item = NULL; |
0 | 414 |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
415 /* Add the new item at the end */ |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
416 fd_list_insert_before( &queue->list, &new->item); |
0 | 417 queue->count++; |
14
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
11
diff
changeset
|
418 if (queue->highest_ever < queue->count) |
14cf6daf716d
Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
11
diff
changeset
|
419 queue->highest_ever = queue->count; |
0 | 420 if (queue->high && ((queue->count % queue->high) == 0)) { |
421 call_cb = 1; | |
422 queue->highest = queue->count; | |
423 } | |
424 | |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
425 /* store timing */ |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
426 memcpy(&new->posted_on, &posted_on, sizeof(struct timespec)); |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
427 |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
428 /* update queue timing info "blocking time" */ |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
429 { |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
430 long long blocked_ns; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
431 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &queued_on) ); |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
432 blocked_ns = (queued_on.tv_sec - posted_on.tv_sec) * 1000000000; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
433 blocked_ns += (queued_on.tv_nsec - posted_on.tv_nsec); |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
434 blocked_ns += queue->blocking_time.tv_nsec; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
435 queue->blocking_time.tv_sec += blocked_ns / 1000000000; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
436 queue->blocking_time.tv_nsec = blocked_ns % 1000000000; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
437 } |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
438 |
0 | 439 /* Signal if threads are asleep */ |
440 if (queue->thrs > 0) { | |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
441 CHECK_POSIX( pthread_cond_signal(&queue->cond_pull) ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
442 } |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
443 if (queue->thrs_push > 0) { |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
444 /* cascade */ |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
445 CHECK_POSIX( pthread_cond_signal(&queue->cond_push) ); |
0 | 446 } |
447 | |
448 /* Unlock */ | |
449 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) ); | |
450 | |
451 /* Call high-watermark cb as needed */ | |
452 if (call_cb && queue->h_cb) | |
453 (*queue->h_cb)(queue, &queue->data); | |
454 | |
455 /* Done */ | |
456 return 0; | |
457 } | |
458 | |
1188
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
459 /* Post a new item in the queue */ |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
460 int fd_fifo_post_int ( struct fifo * queue, void ** item ) |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
461 { |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
462 TRACE_ENTRY( "%p %p", queue, item ); |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
463 |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
464 /* Check the parameters */ |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
465 CHECK_PARAMS( CHECK_FIFO( queue ) && item && *item ); |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
466 |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
467 return fd_fifo_post_internal ( queue,item, 0 ); |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
468 |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
469 } |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
470 |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
471 /* Post a new item in the queue, not blocking */ |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
472 int fd_fifo_post_noblock ( struct fifo * queue, void ** item ) |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
473 { |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
474 TRACE_ENTRY( "%p %p", queue, item ); |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
475 |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
476 /* Check the parameters */ |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
477 CHECK_PARAMS( CHECK_FIFO( queue ) && item && *item ); |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
478 |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
479 return fd_fifo_post_internal ( queue,item, 1 ); |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
480 |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
481 } |
f40de74bd1c7
Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1186
diff
changeset
|
482 |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
483 /* Pop the first item from the queue */ |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
484 static void * mq_pop(struct fifo * queue) |
0 | 485 { |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
486 void * ret = NULL; |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
487 struct fifo_item * fi; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
488 struct timespec now; |
0 | 489 |
490 ASSERT( ! FD_IS_LIST_EMPTY(&queue->list) ); | |
491 | |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
492 fi = (struct fifo_item *)(queue->list.next); |
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
493 ret = fi->item.o; |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
494 fd_list_unlink(&fi->item); |
0 | 495 queue->count--; |
1067
23989d6c8390
Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1060
diff
changeset
|
496 queue->total_items++; |
1060
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
497 |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
498 /* Update the timings */ |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
499 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), goto skip_timing ); |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
500 { |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
501 long long elapsed = (now.tv_sec - fi->posted_on.tv_sec) * 1000000000; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
502 elapsed += now.tv_nsec - fi->posted_on.tv_nsec; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
503 |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
504 queue->last_time.tv_sec = elapsed / 1000000000; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
505 queue->last_time.tv_nsec = elapsed % 1000000000; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
506 |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
507 elapsed += queue->total_time.tv_nsec; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
508 queue->total_time.tv_sec += elapsed / 1000000000; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
509 queue->total_time.tv_nsec = elapsed % 1000000000; |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
510 } |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
511 skip_timing: |
13fc3fc9c789
New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
512 free(fi); |
0 | 513 |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
514 if (queue->thrs_push) { |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
515 CHECK_POSIX_DO( pthread_cond_signal( &queue->cond_push ), ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
516 } |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
517 |
0 | 518 return ret; |
519 } | |
520 | |
521 /* Check if the low watermark callback must be called. */ | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
522 static __inline__ int test_l_cb(struct fifo * queue) |
0 | 523 { |
524 if ((queue->high == 0) || (queue->low == 0) || (queue->l_cb == 0)) | |
525 return 0; | |
526 | |
527 if (((queue->count % queue->high) == queue->low) && (queue->highest > queue->count)) { | |
528 queue->highest -= queue->high; | |
529 return 1; | |
530 } | |
531 | |
532 return 0; | |
533 } | |
534 | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
535 /* Try poping an item */ |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
536 int fd_fifo_tryget_int ( struct fifo * queue, void ** item ) |
0 | 537 { |
538 int wouldblock = 0; | |
539 int call_cb = 0; | |
540 | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
541 TRACE_ENTRY( "%p %p", queue, item ); |
0 | 542 |
543 /* Check the parameters */ | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
544 CHECK_PARAMS( CHECK_FIFO( queue ) && item ); |
0 | 545 |
546 /* lock the queue */ | |
547 CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) ); | |
548 | |
549 /* Check queue status */ | |
550 if (queue->count > 0) { | |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
551 got_item: |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
552 /* There are elements in the queue, so pick the first one */ |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
553 *item = mq_pop(queue); |
0 | 554 call_cb = test_l_cb(queue); |
555 } else { | |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
556 if (queue->thrs_push > 0) { |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
557 /* A thread is trying to push something, let's give it a chance */ |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
558 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
559 CHECK_POSIX( pthread_cond_signal( &queue->cond_push ) ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
560 usleep(1000); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
561 CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) ); |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
562 if (queue->count > 0) |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
563 goto got_item; |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
564 } |
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
565 |
0 | 566 wouldblock = 1; |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
567 *item = NULL; |
0 | 568 } |
569 | |
570 /* Unlock */ | |
571 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) ); | |
572 | |
573 /* Call low watermark callback as needed */ | |
574 if (call_cb) | |
575 (*queue->l_cb)(queue, &queue->data); | |
576 | |
577 /* Done */ | |
578 return wouldblock ? EWOULDBLOCK : 0; | |
579 } | |
580 | |
581 /* This handler is called when a thread is blocked on a queue, and cancelled */ | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
582 static void fifo_cleanup(void * queue) |
0 | 583 { |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
584 struct fifo * q = (struct fifo *)queue; |
0 | 585 TRACE_ENTRY( "%p", queue ); |
586 | |
587 /* The thread has been cancelled, therefore it does not wait on the queue anymore */ | |
588 q->thrs--; | |
589 | |
590 /* Now unlock the queue, and we're done */ | |
591 CHECK_POSIX_DO( pthread_mutex_unlock( &q->mtx ), /* nothing */ ); | |
592 | |
593 /* End of cleanup handler */ | |
594 return; | |
595 } | |
596 | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
597 /* The internal function for fd_fifo_timedget and fd_fifo_get */ |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
598 static int fifo_tget ( struct fifo * queue, void ** item, int istimed, const struct timespec *abstime) |
0 | 599 { |
600 int call_cb = 0; | |
1059
a1d6e1980132
Fix fifo_tget to propagate any error returned by the posix call
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
601 int ret = 0; |
0 | 602 |
603 /* Check the parameters */ | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
604 CHECK_PARAMS( CHECK_FIFO( queue ) && item && (abstime || !istimed) ); |
0 | 605 |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
606 /* Initialize the return value */ |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
607 *item = NULL; |
0 | 608 |
609 /* lock the queue */ | |
610 CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) ); | |
611 | |
612 awaken: | |
613 /* Check queue status */ | |
21
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
614 if (!CHECK_FIFO( queue )) { |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
615 /* The queue is being destroyed */ |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
616 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) ); |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
617 TRACE_DEBUG(FULL, "The queue is being destroyed -> EPIPE"); |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
618 return EPIPE; |
bef197f6826f
Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
14
diff
changeset
|
619 } |
1103
d8591b1c56cd
Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1093
diff
changeset
|
620 |
0 | 621 if (queue->count > 0) { |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
622 /* There are items in the queue, so pick the first one */ |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
623 *item = mq_pop(queue); |
0 | 624 call_cb = test_l_cb(queue); |
625 } else { | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
626 /* We have to wait for a new item */ |
0 | 627 queue->thrs++ ; |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
628 pthread_cleanup_push( fifo_cleanup, queue); |
0 | 629 if (istimed) { |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
630 ret = pthread_cond_timedwait( &queue->cond_pull, &queue->mtx, abstime ); |
0 | 631 } else { |
767
c47c16436f71
Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
740
diff
changeset
|
632 ret = pthread_cond_wait( &queue->cond_pull, &queue->mtx ); |
0 | 633 } |
634 pthread_cleanup_pop(0); | |
635 queue->thrs-- ; | |
636 if (ret == 0) | |
637 goto awaken; /* test for spurious wake-ups */ | |
638 | |
1059
a1d6e1980132
Fix fifo_tget to propagate any error returned by the posix call
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
639 /* otherwise (ETIMEDOUT / other error) just continue */ |
0 | 640 } |
641 | |
642 /* Unlock */ | |
643 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) ); | |
644 | |
645 /* Call low watermark callback as needed */ | |
646 if (call_cb) | |
647 (*queue->l_cb)(queue, &queue->data); | |
648 | |
649 /* Done */ | |
1059
a1d6e1980132
Fix fifo_tget to propagate any error returned by the posix call
Sebastien Decugis <sdecugis@freediameter.net>
parents:
974
diff
changeset
|
650 return ret; |
0 | 651 } |
652 | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
653 /* Get the next available item, block until there is one */ |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
654 int fd_fifo_get_int ( struct fifo * queue, void ** item ) |
0 | 655 { |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
656 TRACE_ENTRY( "%p %p", queue, item ); |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
657 return fifo_tget(queue, item, 0, NULL); |
0 | 658 } |
659 | |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
660 /* Get the next available item, block until there is one, or the timeout expires */ |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
661 int fd_fifo_timedget_int ( struct fifo * queue, void ** item, const struct timespec *abstime ) |
0 | 662 { |
8
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
663 TRACE_ENTRY( "%p %p %p", queue, item, abstime ); |
3e143f047f78
Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
1
diff
changeset
|
664 return fifo_tget(queue, item, 1, abstime); |
0 | 665 } |
666 | |
1186
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
667 /* Test if data is available in the queue, without pulling it */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
668 int fd_fifo_select ( struct fifo * queue, const struct timespec *abstime ) |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
669 { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
670 int ret = 0; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
671 TRACE_ENTRY( "%p %p", queue, abstime ); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
672 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
673 CHECK_PARAMS_DO( CHECK_FIFO( queue ), return -EINVAL ); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
674 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
675 /* lock the queue */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
676 CHECK_POSIX_DO( pthread_mutex_lock( &queue->mtx ), return -__ret__ ); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
677 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
678 awaken: |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
679 ret = (queue->count > 0 ) ? queue->count : 0; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
680 if ((ret == 0) && (abstime != NULL)) { |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
681 /* We have to wait for a new item */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
682 queue->thrs++ ; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
683 pthread_cleanup_push( fifo_cleanup, queue); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
684 ret = pthread_cond_timedwait( &queue->cond_pull, &queue->mtx, abstime ); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
685 pthread_cleanup_pop(0); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
686 queue->thrs-- ; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
687 if (ret == 0) |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
688 goto awaken; /* test for spurious wake-ups */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
689 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
690 if (ret == ETIMEDOUT) |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
691 ret = 0; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
692 else |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
693 ret = -ret; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
694 } |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
695 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
696 /* Unlock */ |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
697 CHECK_POSIX_DO( pthread_mutex_unlock( &queue->mtx ), return -__ret__ ); |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
698 |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
699 return ret; |
56c36d1007b4
Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1127
diff
changeset
|
700 } |