annotate libfdproto/fifo.c @ 1384:2131d6bdf32a

Be more lenient in infinite loop check, 20 is too low for some setups.
author Thomas Klausner <tk@giga.or.at>
date Fri, 19 Jul 2019 11:43:26 +0200
parents ce257e43085d
children 4968bc47a1a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
1127
1af09cc156d6 Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1104
diff changeset
5 * Copyright (c) 2013, WIDE Project and NICT *
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
36 /* FIFO queues module.
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37 *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 * The threads that call these functions must be in the cancellation state PTHREAD_CANCEL_ENABLE and type PTHREAD_CANCEL_DEFERRED.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39 * This is the default state and type on thread creation.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 *
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41 * In order to destroy properly a queue, the application must:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42 * -> shutdown any process that can add into the queue first.
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
46 */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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 */
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
53
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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 */
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
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
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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) */
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
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 */
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
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
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
66 uint16_t low; /* Low level threshhold */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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) */
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
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 */
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
77
1060
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
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
83 };
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
84
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
90
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
94 {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
95 struct fifo * new;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
96
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
97 TRACE_ENTRY( "%p", queue );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
98
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
99 CHECK_PARAMS( queue );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
100
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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) ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
103
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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));
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
106
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
107 new->eyec = FIFO_EYEC;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
112
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
113 fd_list_init(&new->list, NULL);
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
114
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
115 /* We're done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
116 *queue = new;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
117 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
118 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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();
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
124
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1073
diff changeset
125 if (name) {
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
126 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "'%s'(@%p): ", name, queue), return NULL);
1085
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 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
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 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
134
10
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 */ );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
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),
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
140 queue->high, queue->low, queue->highest, queue->h_cb, queue->l_cb, queue->data),
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1073
diff changeset
141 goto error);
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
142
10
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;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
148 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "\n [#%i](@%p)@%ld.%06ld: ",
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
149 i++, fi->item.o, (long)fi->posted_on.tv_sec,(long)(fi->posted_on.tv_nsec/1000)),
1085
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 */ );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
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
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
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
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
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;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
167
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
168 TRACE_ENTRY( "%p", queue );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
169
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
170 if (queue && *queue == NULL) {
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
171 /* Queue already (in the process of being) deleted */
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
172 return 0;
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
173 }
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
174
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
175 CHECK_PARAMS( queue && CHECK_FIFO( *queue ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
176
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
177 q = *queue;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
178
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
179 CHECK_POSIX( pthread_mutex_lock( &q->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
180
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
181 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
182 TRACE_DEBUG(INFO, "The queue cannot be destroyed (%d, %p)", q->count, q->data);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
183 CHECK_POSIX_DO( pthread_mutex_unlock( &q->mtx ), /* no fallback */ );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
184 return EINVAL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
186
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
187 /* Ok, now invalidate the queue */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
188 q->eyec = 0xdead;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
189
156
e2dc300819b3 Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 139
diff changeset
190 /* 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
191 while (q->thrs) {
138
4249a55f859a Attempt to fix behavior on multi-CPU platforms
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 137
diff changeset
192 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
193 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
194 usleep(1000);
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
195
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
196 CHECK_POSIX( pthread_mutex_lock( &q->mtx ) );
1384
2131d6bdf32a Be more lenient in infinite loop check, 20 is too low for some setups.
Thomas Klausner <tk@giga.or.at>
parents: 1377
diff changeset
197 ASSERT( ++loops < 200 ); /* detect infinite loops */
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
198 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
199
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
200 /* sanity check */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
201 ASSERT(FD_IS_LIST_EMPTY(&q->list));
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
202
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
203 /* And destroy it */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
204 CHECK_POSIX( pthread_mutex_unlock( &q->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
205
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
206 CHECK_POSIX_DO( pthread_cond_destroy( &q->cond_pull ), );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
207
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
208 CHECK_POSIX_DO( pthread_cond_destroy( &q->cond_push ), );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
209
451
4395961aad27 Some libc seem to have an issue with canceled threads...
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 450
diff changeset
210 CHECK_POSIX_DO( pthread_mutex_destroy( &q->mtx ), );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
211
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
212 free(q);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
213 *queue = NULL;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
214
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
215 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
216 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
217
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
218 /* 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
219 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
220 {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
221 int loops = 0;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
222
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
223 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
224 CHECK_PARAMS( CHECK_FIFO( old ) && CHECK_FIFO( new ));
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
225
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
226 CHECK_PARAMS( ! old->data );
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
227 if (new->high) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
228 TODO("Implement support for thresholds in fd_fifo_move...");
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
229 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
230
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
231 /* Update loc_update */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
232 if (loc_update)
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
233 *loc_update = new;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
234
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
235 /* 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
236 CHECK_POSIX( pthread_mutex_lock( &old->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
237
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
238 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
239 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
240 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
241 } );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
242
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
243 CHECK_POSIX( pthread_mutex_lock( &new->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
244
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
245 /* 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
246 old->eyec = 0xdead;
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
247 while (old->thrs) {
138
4249a55f859a Attempt to fix behavior on multi-CPU platforms
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 137
diff changeset
248 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
249 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
250 usleep(1000);
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
251
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
252 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
253 ASSERT( loops < 20 ); /* detect infinite loops */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
254 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
255
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
256 /* 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
257 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
258 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
259 CHECK_POSIX( pthread_cond_signal(&new->cond_pull) );
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
260 }
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
261 new->count += old->count;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
262
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
263 /* Reset old */
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
264 old->count = 0;
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
265 old->eyec = FIFO_EYEC;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
266
1067
23989d6c8390 Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1060
diff changeset
267 /* 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
268 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
269 old->total_items = 0;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
270
1067
23989d6c8390 Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1060
diff changeset
271 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
272 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
273 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
274 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
275 old->total_time.tv_sec = 0;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
276
1067
23989d6c8390 Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1060
diff changeset
277 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
278 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
279 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
280 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
281 old->blocking_time.tv_sec = 0;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
282
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
283 /* Unlock, we're done */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
284 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
285 CHECK_POSIX( pthread_mutex_unlock( &old->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
286
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
287 return 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
288 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
289
1071
6ca6cadf209c Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1067
diff changeset
290 /* Get the information on the queue */
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
291 int fd_fifo_getstats( struct fifo * queue, int * current_count, int * limit_count, int * highest_count, long long * total_count,
1071
6ca6cadf209c Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1067
diff changeset
292 struct timespec * total, struct timespec * blocking, struct timespec * last)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
293 {
1071
6ca6cadf209c Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1067
diff changeset
294 TRACE_ENTRY( "%p %p %p %p %p %p %p %p", queue, current_count, limit_count, highest_count, total_count, total, blocking, last);
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
295
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
296 /* Check the parameters */
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
297 CHECK_PARAMS( CHECK_FIFO( queue ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
298
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
299 /* lock the queue */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
300 CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
301
1071
6ca6cadf209c Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1067
diff changeset
302 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
303 *current_count = queue->count;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
304
1071
6ca6cadf209c Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1067
diff changeset
305 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
306 *limit_count = queue->max;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
307
1071
6ca6cadf209c Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1067
diff changeset
308 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
309 *highest_count = queue->highest_ever;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
310
1071
6ca6cadf209c Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1067
diff changeset
311 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
312 *total_count = queue->total_items;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
313
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
314 if (total)
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
315 memcpy(total, &queue->total_time, sizeof(struct timespec));
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
316
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
317 if (blocking)
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
318 memcpy(blocking, &queue->blocking_time, sizeof(struct timespec));
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
319
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
320 if (last)
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
321 memcpy(last, &queue->last_time, sizeof(struct timespec));
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
322
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
323 /* Unlock */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
324 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
325
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
326 /* Done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
327 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
328 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
329
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
330
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
331 /* 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
332 int fd_fifo_length ( struct fifo * queue )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
333 {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
334 if ( !CHECK_FIFO( queue ) )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
335 return 0;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
336
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
337 return queue->count; /* Let's hope it's read atomically, since we are not locking... */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
338 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
339
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
340 /* Set the thresholds of the queue */
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
341 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
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
342 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
343 TRACE_ENTRY( "%p %p %hu %p %hu %p", queue, data, high, h_cb, low, l_cb );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
344
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
345 /* Check the parameters */
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
346 CHECK_PARAMS( CHECK_FIFO( queue ) && (high > low) && (queue->data == NULL) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
347
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
348 /* lock the queue */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
349 CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
350
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
351 /* Save the values */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
352 queue->high = high;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
353 queue->low = low;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
354 queue->data = data;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
355 queue->h_cb = h_cb;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
356 queue->l_cb = l_cb;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
357
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
358 /* Unlock */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
359 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
360
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
361 /* Done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
362 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
363 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
364
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
365
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 /* 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
367 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
368 {
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 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
370 TRACE_ENTRY( "%p", queue );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
371
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
372 /* 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
373 q->thrs_push--;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
374
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
375 /* 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
376 CHECK_POSIX_DO( pthread_mutex_unlock( &q->mtx ), /* nothing */ );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
377
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
378 /* 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
379 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
380 }
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
381
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
382
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
383 /* Post a new item in the queue */
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
384 int fd_fifo_post_internal ( struct fifo * queue, void ** item, int skip_max )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
385 {
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
386 struct fifo_item * new;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
387 int call_cb = 0;
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
388 struct timespec posted_on, queued_on;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
389
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
390 /* 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
391 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &posted_on) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
392
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
393 /* 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
394 CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
395
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
396 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
397 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
398 int ret = 0;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
399
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
400 /* 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
401 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
402 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
403 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
404 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
405 queue->thrs_push-- ;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
406
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
407 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
408 }
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
409 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
410
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
411 /* 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
412 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
413 pthread_mutex_unlock( &queue->mtx );
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
414 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
415 } );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
416
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
417 fd_list_init(&new->item, *item);
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
418 *item = NULL;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
419
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
420 /* 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
421 fd_list_insert_before( &queue->list, &new->item);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
422 queue->count++;
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 11
diff changeset
423 if (queue->highest_ever < queue->count)
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 11
diff changeset
424 queue->highest_ever = queue->count;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
425 if (queue->high && ((queue->count % queue->high) == 0)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
426 call_cb = 1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
427 queue->highest = queue->count;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
428 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
429
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
430 /* store timing */
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
431 memcpy(&new->posted_on, &posted_on, sizeof(struct timespec));
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
432
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
433 /* 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
434 {
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
435 long long blocked_ns;
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
436 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
437 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
438 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
439 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
440 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
441 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
442 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
443
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
444 /* Signal if threads are asleep */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
445 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
446 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
447 }
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
448 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
449 /* 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
450 CHECK_POSIX( pthread_cond_signal(&queue->cond_push) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
451 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
452
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
453 /* Unlock */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
454 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
455
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
456 /* Call high-watermark cb as needed */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
457 if (call_cb && queue->h_cb)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
458 (*queue->h_cb)(queue, &queue->data);
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
459
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
460 /* Done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
461 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
462 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
463
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
464 /* Post a new item in the queue */
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
465 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
466 {
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
467 TRACE_ENTRY( "%p %p", queue, item );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
468
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
469 /* Check the parameters */
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
470 CHECK_PARAMS( CHECK_FIFO( queue ) && item && *item );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
471
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
472 return fd_fifo_post_internal ( queue,item, 0 );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
473
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
474 }
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 /* 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
477 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
478 {
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
479 TRACE_ENTRY( "%p %p", queue, item );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
480
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
481 /* Check the parameters */
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
482 CHECK_PARAMS( CHECK_FIFO( queue ) && item && *item );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
483
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
484 return fd_fifo_post_internal ( queue,item, 1 );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
485
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
486 }
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
487
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
488 /* Pop the first item from the queue */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
489 static void * mq_pop(struct fifo * queue)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
490 {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
491 void * ret = NULL;
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
492 struct fifo_item * fi;
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
493 struct timespec now;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
494
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
495 ASSERT( ! FD_IS_LIST_EMPTY(&queue->list) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
496
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
497 fi = (struct fifo_item *)(queue->list.next);
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
498 ret = fi->item.o;
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
499 fd_list_unlink(&fi->item);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
500 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
501 queue->total_items++;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
502
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
503 /* Update the timings */
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
504 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
505 {
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
506 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
507 elapsed += now.tv_nsec - fi->posted_on.tv_nsec;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
508
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
509 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
510 queue->last_time.tv_nsec = elapsed % 1000000000;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
511
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
512 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
513 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
514 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
515 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
516 skip_timing:
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
517 free(fi);
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
518
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
519 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
520 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
521 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
522
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
523 return ret;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
524 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
525
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
526 /* 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
527 static __inline__ int test_l_cb(struct fifo * queue)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
528 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
529 if ((queue->high == 0) || (queue->low == 0) || (queue->l_cb == 0))
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
530 return 0;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
531
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
532 if (((queue->count % queue->high) == queue->low) && (queue->highest > queue->count)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
533 queue->highest -= queue->high;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
534 return 1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
535 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
536
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
537 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
538 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
539
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
540 /* Try poping an item */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
541 int fd_fifo_tryget_int ( struct fifo * queue, void ** item )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
542 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
543 int wouldblock = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
544 int call_cb = 0;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
545
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
546 TRACE_ENTRY( "%p %p", queue, item );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
547
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
548 /* Check the parameters */
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
549 CHECK_PARAMS( CHECK_FIFO( queue ) && item );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
550
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
551 /* lock the queue */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
552 CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
553
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
554 /* Check queue status */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
555 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
556 got_item:
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
557 /* 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
558 *item = mq_pop(queue);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
559 call_cb = test_l_cb(queue);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
560 } 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
561 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
562 /* 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
563 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
564 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
565 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
566 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
567 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
568 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
569 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
570
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
571 wouldblock = 1;
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
572 *item = NULL;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
573 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
574
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
575 /* Unlock */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
576 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
577
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
578 /* Call low watermark callback as needed */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
579 if (call_cb)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
580 (*queue->l_cb)(queue, &queue->data);
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
581
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
582 /* Done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
583 return wouldblock ? EWOULDBLOCK : 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
584 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
585
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
586 /* 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
587 static void fifo_cleanup(void * queue)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
588 {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
589 struct fifo * q = (struct fifo *)queue;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
590 TRACE_ENTRY( "%p", queue );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
591
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
592 /* The thread has been cancelled, therefore it does not wait on the queue anymore */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
593 q->thrs--;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
594
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
595 /* Now unlock the queue, and we're done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
596 CHECK_POSIX_DO( pthread_mutex_unlock( &q->mtx ), /* nothing */ );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
597
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
598 /* End of cleanup handler */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
599 return;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
600 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
601
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
602 /* 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
603 static int fifo_tget ( struct fifo * queue, void ** item, int istimed, const struct timespec *abstime)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
604 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
605 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
606 int ret = 0;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
607
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
608 /* Check the parameters */
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
609 CHECK_PARAMS( CHECK_FIFO( queue ) && item && (abstime || !istimed) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
610
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
611 /* Initialize the return value */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
612 *item = NULL;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
613
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
614 /* lock the queue */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
615 CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
616
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
617 awaken:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
618 /* Check queue status */
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
619 if (!CHECK_FIFO( queue )) {
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
620 /* 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
621 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
622 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
623 return EPIPE;
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
624 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
625
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
626 if (queue->count > 0) {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
627 /* 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
628 *item = mq_pop(queue);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
629 call_cb = test_l_cb(queue);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
630 } else {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
631 /* We have to wait for a new item */
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
632 queue->thrs++ ;
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
633 pthread_cleanup_push( fifo_cleanup, queue);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
634 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
635 ret = pthread_cond_timedwait( &queue->cond_pull, &queue->mtx, abstime );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
636 } 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
637 ret = pthread_cond_wait( &queue->cond_pull, &queue->mtx );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
638 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
639 pthread_cleanup_pop(0);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
640 queue->thrs-- ;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
641 if (ret == 0)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
642 goto awaken; /* test for spurious wake-ups */
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
643
1059
a1d6e1980132 Fix fifo_tget to propagate any error returned by the posix call
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
644 /* otherwise (ETIMEDOUT / other error) just continue */
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
645 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
646
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
647 /* Unlock */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
648 CHECK_POSIX( pthread_mutex_unlock( &queue->mtx ) );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
649
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
650 /* Call low watermark callback as needed */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
651 if (call_cb)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
652 (*queue->l_cb)(queue, &queue->data);
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
653
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
654 /* Done */
1059
a1d6e1980132 Fix fifo_tget to propagate any error returned by the posix call
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
655 return ret;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
656 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
657
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
658 /* 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
659 int fd_fifo_get_int ( struct fifo * queue, void ** item )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
660 {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
661 TRACE_ENTRY( "%p %p", queue, item );
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
662 return fifo_tget(queue, item, 0, NULL);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
663 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
664
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
665 /* 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
666 int fd_fifo_timedget_int ( struct fifo * queue, void ** item, const struct timespec *abstime )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
667 {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
668 TRACE_ENTRY( "%p %p %p", queue, item, abstime );
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
669 return fifo_tget(queue, item, 1, abstime);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
670 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
671
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
672 /* 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
673 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
674 {
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
675 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
676 TRACE_ENTRY( "%p %p", queue, abstime );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
677
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
678 CHECK_PARAMS_DO( CHECK_FIFO( queue ), return -EINVAL );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
679
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
680 /* 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
681 CHECK_POSIX_DO( pthread_mutex_lock( &queue->mtx ), return -__ret__ );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
682
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
683 awaken:
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
684 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
685 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
686 /* 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
687 queue->thrs++ ;
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
688 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
689 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
690 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
691 queue->thrs-- ;
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
692 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
693 goto awaken; /* test for spurious wake-ups */
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
694
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
695 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
696 ret = 0;
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
697 else
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
698 ret = -ret;
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
699 }
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
700
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
701 /* Unlock */
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
702 CHECK_POSIX_DO( pthread_mutex_unlock( &queue->mtx ), return -__ret__ );
1377
ce257e43085d fd_fifo_del: check if queue is already (being) destroyed and return success in that case.
Thomas Klausner <tk@giga.or.at>
parents: 1188
diff changeset
703
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
704 return ret;
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
705 }
"Welcome to our mercurial repository"