annotate libfdproto/fifo.c @ 1554:566bb46cc73f

Updated copyright information
author Sebastien Decugis <sdecugis@freediameter.net>
date Tue, 06 Oct 2020 21:34:53 +0800
parents d25ce064c667
children
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 * *
1554
566bb46cc73f Updated copyright information
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1539
diff changeset
5 * Copyright (c) 2020, 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
1393
357e9cec520f libfdproto: add fd_fifo_set_max
Thomas Klausner <tk@giga.or.at>
parents: 1385
diff changeset
120 int fd_fifo_set_max (struct fifo * queue, int max)
357e9cec520f libfdproto: add fd_fifo_set_max
Thomas Klausner <tk@giga.or.at>
parents: 1385
diff changeset
121 {
357e9cec520f libfdproto: add fd_fifo_set_max
Thomas Klausner <tk@giga.or.at>
parents: 1385
diff changeset
122 queue->max = max;
357e9cec520f libfdproto: add fd_fifo_set_max
Thomas Klausner <tk@giga.or.at>
parents: 1385
diff changeset
123 return 0;
357e9cec520f libfdproto: add fd_fifo_set_max
Thomas Klausner <tk@giga.or.at>
parents: 1385
diff changeset
124 }
357e9cec520f libfdproto: add fd_fifo_set_max
Thomas Klausner <tk@giga.or.at>
parents: 1385
diff changeset
125
357e9cec520f libfdproto: add fd_fifo_set_max
Thomas Klausner <tk@giga.or.at>
parents: 1385
diff changeset
126
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 8
diff changeset
127 /* Dump the content of a queue */
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1073
diff changeset
128 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
129 {
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
130 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
131
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1073
diff changeset
132 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
133 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
134 } else {
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1073
diff changeset
135 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
136 }
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
137
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 8
diff changeset
138 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
139 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
140 }
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
141
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 8
diff changeset
142 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
143 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
144 queue->count, queue->highest_ever, queue->max,
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1073
diff changeset
145 queue->thrs, queue->thrs_push,
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1073
diff changeset
146 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
147 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
148 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
149
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 8
diff changeset
150 if (dump_item) {
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 8
diff changeset
151 struct fd_list * li;
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 8
diff changeset
152 int i = 0;
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 8
diff changeset
153 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
154 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
155 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
156 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
157 goto error);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1073
diff changeset
158 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
159 }
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 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
162
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1073
diff changeset
163 return *buf;
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1073
diff changeset
164 error:
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1073
diff changeset
165 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
166 return NULL;
10
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 8
diff changeset
167 }
c5c99c73c2bf Added some extensions and functions in the daemon
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 8
diff changeset
168
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
169 /* Delete a queue. It must be empty. */
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
170 int fd_fifo_del ( struct fifo ** queue )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
171 {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
172 struct fifo * q;
1539
d25ce064c667 Correctly fix compiler warnings
Luke Mewburn <luke@mewburn.net>
parents: 1405
diff changeset
173 #ifndef NDEBUG
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
174 int loops = 0;
1405
3cbe458fbfa9 Fix compiler warnings
Luke Mewburn <luke@mewburn.net>
parents: 1393
diff changeset
175 #endif
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 TRACE_ENTRY( "%p", queue );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
178
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
179 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
180 /* 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
181 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
182 }
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
183
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
184 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
185
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
186 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
187
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
188 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
189
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
190 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
191 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
192 CHECK_POSIX_DO( pthread_mutex_unlock( &q->mtx ), /* no fallback */ );
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
193 return EINVAL;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
194 }
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
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
196 /* Ok, now invalidate the queue */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
197 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
198
156
e2dc300819b3 Fix overwriten thread location
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 139
diff changeset
199 /* 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
200 while (q->thrs) {
138
4249a55f859a Attempt to fix behavior on multi-CPU platforms
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 137
diff changeset
201 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
202 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
203 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
204
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
205 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
206 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
207 }
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
208
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
209 /* sanity check */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
210 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
211
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
212 /* And destroy it */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
213 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
214
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
215 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
216
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
217 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
218
451
4395961aad27 Some libc seem to have an issue with canceled threads...
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 450
diff changeset
219 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
220
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
221 free(q);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
222 *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
223
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
224 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
225 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
226
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
227 /* 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
228 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
229 {
1539
d25ce064c667 Correctly fix compiler warnings
Luke Mewburn <luke@mewburn.net>
parents: 1405
diff changeset
230 #ifndef NDEBUG
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
231 int loops = 0;
1405
3cbe458fbfa9 Fix compiler warnings
Luke Mewburn <luke@mewburn.net>
parents: 1393
diff changeset
232 #endif
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
233
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
234 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
235 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
236
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
237 CHECK_PARAMS( ! old->data );
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
238 if (new->high) {
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
239 TODO("Implement support for thresholds in fd_fifo_move...");
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
240 }
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
241
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
242 /* Update loc_update */
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
243 if (loc_update)
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
244 *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
245
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
246 /* 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
247 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
248
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_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
250 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
251 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
252 } );
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
253
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
254 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
255
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
256 /* 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
257 old->eyec = 0xdead;
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
258 while (old->thrs) {
138
4249a55f859a Attempt to fix behavior on multi-CPU platforms
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 137
diff changeset
259 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
260 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
261 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
262
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
263 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
264 ASSERT( loops < 20 ); /* detect infinite loops */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
265 }
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
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
267 /* 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
268 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
269 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
270 CHECK_POSIX( pthread_cond_signal(&new->cond_pull) );
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
271 }
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
272 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
273
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
274 /* Reset old */
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
275 old->count = 0;
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
276 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
277
1067
23989d6c8390 Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1060
diff changeset
278 /* 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
279 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
280 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
281
1067
23989d6c8390 Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1060
diff changeset
282 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
283 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
284 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
285 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
286 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
287
1067
23989d6c8390 Add total count in the statistics of the queues, thanks for the feedback :)
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1060
diff changeset
288 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
289 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
290 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
291 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
292 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
293
43
2db15632a63d Added a large part of connection establishment logic, to test
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 25
diff changeset
294 /* Unlock, we're done */
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
295 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
296 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
297
25
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
298 return 0;
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
299 }
67ca08d5bc48 Completed connection context files
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 21
diff changeset
300
1071
6ca6cadf209c Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1067
diff changeset
301 /* 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
302 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
303 struct timespec * total, struct timespec * blocking, struct timespec * last)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
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 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
306
1385
4968bc47a1a5 fd_fifo_getstats: it is not an error if a queue does not exist
Thomas Klausner <tk@giga.or.at>
parents: 1384
diff changeset
307 if (queue == NULL) {
4968bc47a1a5 fd_fifo_getstats: it is not an error if a queue does not exist
Thomas Klausner <tk@giga.or.at>
parents: 1384
diff changeset
308 /* It is not an error if the queue is not available; happens e.g. when peers disappear */
4968bc47a1a5 fd_fifo_getstats: it is not an error if a queue does not exist
Thomas Klausner <tk@giga.or.at>
parents: 1384
diff changeset
309 return 0;
4968bc47a1a5 fd_fifo_getstats: it is not an error if a queue does not exist
Thomas Klausner <tk@giga.or.at>
parents: 1384
diff changeset
310 }
4968bc47a1a5 fd_fifo_getstats: it is not an error if a queue does not exist
Thomas Klausner <tk@giga.or.at>
parents: 1384
diff changeset
311
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
312 /* Check the parameters */
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
313 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
314
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
315 /* lock the queue */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
316 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
317
1071
6ca6cadf209c Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1067
diff changeset
318 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
319 *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
320
1071
6ca6cadf209c Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1067
diff changeset
321 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
322 *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
323
1071
6ca6cadf209c Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1067
diff changeset
324 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
325 *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
326
1071
6ca6cadf209c Implement the fd_stat_getstats function; changed prototype of fd_fifo_length.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1067
diff changeset
327 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
328 *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
329
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
330 if (total)
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
331 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
332
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
333 if (blocking)
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
334 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
335
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
336 if (last)
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
337 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
338
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
339 /* Unlock */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
340 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
341
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
342 /* Done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
343 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
344 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
345
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
346
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
347 /* 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
348 int fd_fifo_length ( struct fifo * queue )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
349 {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
350 if ( !CHECK_FIFO( queue ) )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
351 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
352
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
353 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
354 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
355
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
356 /* Set the thresholds of the queue */
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
357 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
358 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
359 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
360
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
361 /* Check the parameters */
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
362 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
363
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
364 /* lock the queue */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
365 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
366
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
367 /* Save the values */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
368 queue->high = high;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
369 queue->low = low;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
370 queue->data = data;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
371 queue->h_cb = h_cb;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
372 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
373
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
374 /* Unlock */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
375 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
376
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
377 /* Done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
378 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
379 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
380
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
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 /* 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
383 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
384 {
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
385 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
386 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
387
767
c47c16436f71 Added a limit on fifo queues to avoid memory exaustion when messages are received faster than handled
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
388 /* 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
389 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
390
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
391 /* 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
392 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
393
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
394 /* 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
395 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
396 }
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
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
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
399 /* Post a new item in the queue */
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
400 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
401 {
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
402 struct fifo_item * new;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
403 int call_cb = 0;
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
404 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
405
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
406 /* 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
407 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
408
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
409 /* 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
410 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
411
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
412 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
413 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
414 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
415
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
416 /* 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
417 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
418 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
419 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
420 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
421 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
422
1539
d25ce064c667 Correctly fix compiler warnings
Luke Mewburn <luke@mewburn.net>
parents: 1405
diff changeset
423 #ifdef NDEBUG
1405
3cbe458fbfa9 Fix compiler warnings
Luke Mewburn <luke@mewburn.net>
parents: 1393
diff changeset
424 (void)ret;
3cbe458fbfa9 Fix compiler warnings
Luke Mewburn <luke@mewburn.net>
parents: 1393
diff changeset
425 #endif
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
426 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
427 }
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
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
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
430 /* 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
431 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
432 pthread_mutex_unlock( &queue->mtx );
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
433 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
434 } );
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
435
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
436 fd_list_init(&new->item, *item);
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
437 *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
438
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
439 /* 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
440 fd_list_insert_before( &queue->list, &new->item);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
441 queue->count++;
14
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 11
diff changeset
442 if (queue->highest_ever < queue->count)
14cf6daf716d Some progress on peers module
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 11
diff changeset
443 queue->highest_ever = queue->count;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
444 if (queue->high && ((queue->count % queue->high) == 0)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
445 call_cb = 1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
446 queue->highest = queue->count;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
447 }
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
448
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
449 /* store timing */
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
450 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
451
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
452 /* 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
453 {
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
454 long long blocked_ns;
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
455 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
456 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
457 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
458 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
459 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
460 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
461 }
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
462
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
463 /* Signal if threads are asleep */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
464 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
465 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
466 }
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
467 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
468 /* 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
469 CHECK_POSIX( pthread_cond_signal(&queue->cond_push) );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
470 }
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
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
472 /* Unlock */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
473 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
474
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
475 /* Call high-watermark cb as needed */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
476 if (call_cb && queue->h_cb)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
477 (*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
478
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
479 /* Done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
480 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
481 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
482
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
483 /* Post a new item in the queue */
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
484 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
485 {
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
486 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
487
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
488 /* Check the parameters */
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
489 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
490
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
491 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
492
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
493 }
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
494
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
495 /* 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
496 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
497 {
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
498 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
499
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
500 /* Check the parameters */
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
501 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
502
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
503 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
504
1188
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
505 }
f40de74bd1c7 Don't block PSM during failover
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1186
diff changeset
506
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
507 /* Pop the first item from the queue */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
508 static void * mq_pop(struct fifo * queue)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
509 {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
510 void * ret = NULL;
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
511 struct fifo_item * fi;
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
512 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
513
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
514 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
515
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
516 fi = (struct fifo_item *)(queue->list.next);
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
517 ret = fi->item.o;
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
518 fd_list_unlink(&fi->item);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
519 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
520 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
521
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
522 /* Update the timings */
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
523 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
524 {
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
525 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
526 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
527
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
528 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
529 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
530
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
531 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
532 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
533 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
534 }
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
535 skip_timing:
1060
13fc3fc9c789 New feature in fd_fifo to get timing statistics
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
536 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
537
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
538 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
539 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
540 }
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
541
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
542 return ret;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
543 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
544
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
545 /* 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
546 static __inline__ int test_l_cb(struct fifo * queue)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
547 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
548 if ((queue->high == 0) || (queue->low == 0) || (queue->l_cb == 0))
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
549 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
550
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
551 if (((queue->count % queue->high) == queue->low) && (queue->highest > queue->count)) {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
552 queue->highest -= queue->high;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
553 return 1;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
554 }
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
555
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
556 return 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
557 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
558
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
559 /* Try poping an item */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
560 int fd_fifo_tryget_int ( struct fifo * queue, void ** item )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
561 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
562 int wouldblock = 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
563 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
564
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
565 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
566
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
567 /* Check the parameters */
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
568 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
569
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
570 /* lock the queue */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
571 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
572
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
573 /* Check queue status */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
574 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
575 got_item:
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
576 /* 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
577 *item = mq_pop(queue);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
578 call_cb = test_l_cb(queue);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
579 } 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
580 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
581 /* 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
582 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
583 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
584 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
585 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
586 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
587 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
588 }
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
589
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
590 wouldblock = 1;
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
591 *item = NULL;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
592 }
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
593
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
594 /* Unlock */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
595 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
596
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
597 /* Call low watermark callback as needed */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
598 if (call_cb)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
599 (*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
600
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
601 /* Done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
602 return wouldblock ? EWOULDBLOCK : 0;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
603 }
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 /* 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
606 static void fifo_cleanup(void * queue)
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
607 {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
608 struct fifo * q = (struct fifo *)queue;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
609 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
610
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
611 /* 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
612 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
613
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
614 /* Now unlock the queue, and we're done */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
615 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
616
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
617 /* End of cleanup handler */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
618 return;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
619 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
620
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
621 /* 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
622 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
623 {
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
624 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
625 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
626
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
627 /* Check the parameters */
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
628 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
629
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
630 /* Initialize the return value */
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
631 *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
632
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
633 /* lock the queue */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
634 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
635
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
636 awaken:
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
637 /* Check queue status */
21
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
638 if (!CHECK_FIFO( queue )) {
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
639 /* 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
640 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
641 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
642 return EPIPE;
bef197f6826f Backup before week-end, cnxctx and server in progress
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 14
diff changeset
643 }
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
644
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
645 if (queue->count > 0) {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
646 /* 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
647 *item = mq_pop(queue);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
648 call_cb = test_l_cb(queue);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
649 } else {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
650 /* We have to wait for a new item */
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
651 queue->thrs++ ;
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
652 pthread_cleanup_push( fifo_cleanup, queue);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
653 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
654 ret = pthread_cond_timedwait( &queue->cond_pull, &queue->mtx, abstime );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
655 } 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
656 ret = pthread_cond_wait( &queue->cond_pull, &queue->mtx );
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
657 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
658 pthread_cleanup_pop(0);
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
659 queue->thrs-- ;
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
660 if (ret == 0)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
661 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
662
1059
a1d6e1980132 Fix fifo_tget to propagate any error returned by the posix call
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
663 /* otherwise (ETIMEDOUT / other error) just continue */
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
664 }
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
665
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
666 /* Unlock */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
667 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
668
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
669 /* Call low watermark callback as needed */
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
670 if (call_cb)
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
671 (*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
672
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
673 /* Done */
1059
a1d6e1980132 Fix fifo_tget to propagate any error returned by the posix call
Sebastien Decugis <sdecugis@freediameter.net>
parents: 974
diff changeset
674 return ret;
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
675 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
676
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
677 /* 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
678 int fd_fifo_get_int ( struct fifo * queue, void ** item )
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
679 {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
680 TRACE_ENTRY( "%p %p", queue, item );
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
681 return fifo_tget(queue, item, 0, NULL);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
682 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
683
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
684 /* 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
685 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
686 {
8
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
687 TRACE_ENTRY( "%p %p %p", queue, item, abstime );
3e143f047f78 Backup for the week-end
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 1
diff changeset
688 return fifo_tget(queue, item, 1, abstime);
0
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
689 }
13530e1f02e3 Initial files imported
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
690
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
691 /* 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
692 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
693 {
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
694 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
695 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
696
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
697 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
698
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
699 /* 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
700 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
701
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
702 awaken:
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
703 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
704 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
705 /* 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
706 queue->thrs++ ;
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
707 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
708 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
709 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
710 queue->thrs-- ;
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
711 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
712 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
713
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
714 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
715 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
716 else
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
717 ret = -ret;
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
718 }
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
719
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
720 /* Unlock */
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
721 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
722
1186
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
723 return ret;
56c36d1007b4 Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1127
diff changeset
724 }
"Welcome to our mercurial repository"