Asterisk - The Open Source Telephony Project GIT-master-77d630f
serializer_shutdown_group.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2012-2013, Digium, Inc.
5 *
6 * Mark Michelson <mmmichelson@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19
20#include "asterisk.h"
21
23#include "asterisk/astobj2.h"
24#include "asterisk/time.h"
25#include "asterisk/utils.h"
26
27/*! Serializer group shutdown control object. */
29 /*! Shutdown thread waits on this conditional. */
31 /*! Count of serializers needing to shutdown. */
32 int count;
33};
34
35static void serializer_shutdown_group_dtor(void *vdoomed)
36{
37 struct ast_serializer_shutdown_group *doomed = vdoomed;
38
39 ast_cond_destroy(&doomed->cond);
40}
41
43{
45
47 if (!shutdown_group) {
48 return NULL;
49 }
51 return shutdown_group;
52}
53
55{
56 int remaining;
58
59 if (!shutdown_group) {
60 return 0;
61 }
62
65
67 if (timeout) {
68 struct timeval start;
69 struct timespec end;
70
71 start = ast_tvnow();
72 end.tv_sec = start.tv_sec + timeout;
73 end.tv_nsec = start.tv_usec * 1000;
74 while (shutdown_group->count) {
76 /* Error or timed out waiting for the count to reach zero. */
77 break;
78 }
79 }
80 } else {
81 while (shutdown_group->count) {
83 /* Error */
84 break;
85 }
86 }
87 }
88 remaining = shutdown_group->count;
90 return remaining;
91}
92
94{
98}
99
101{
104 if (!shutdown_group->count) {
106 }
108}
ast_mutex_t lock
Definition: app_sla.c:337
Asterisk main include file. File version handling, generic pbx functions.
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
void * ao2_object_get_lockaddr(void *obj)
Return the mutex lock address of an object.
Definition: astobj2.c:476
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
char * end
Definition: eagi_proxy.c:73
#define ast_cond_destroy(cond)
Definition: lock.h:209
#define ast_cond_wait(cond, mutex)
Definition: lock.h:212
#define ast_cond_init(cond, attr)
Definition: lock.h:208
#define ast_cond_timedwait(cond, mutex, time)
Definition: lock.h:213
pthread_cond_t ast_cond_t
Definition: lock.h:185
#define ast_cond_signal(cond)
Definition: lock.h:210
static struct ast_serializer_shutdown_group * shutdown_group
Shutdown group for options serializers.
#define NULL
Definition: resample.c:96
void ast_serializer_shutdown_group_dec(struct ast_serializer_shutdown_group *shutdown_group)
Decrement the number of serializer members in the group.
static void serializer_shutdown_group_dtor(void *vdoomed)
void ast_serializer_shutdown_group_inc(struct ast_serializer_shutdown_group *shutdown_group)
Increment the number of serializer members in the group.
int ast_serializer_shutdown_group_join(struct ast_serializer_shutdown_group *shutdown_group, int timeout)
Wait for the serializers in the group to shutdown with timeout.
struct ast_serializer_shutdown_group * ast_serializer_shutdown_group_alloc(void)
Create a serializer group shutdown control object.
Structure for mutex and tracking information.
Definition: lock.h:142
Time-related functions and macros.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159
Utility functions.
#define ast_assert(a)
Definition: utils.h:776