forked from accre/lstore-ibp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ibp_errno.c
89 lines (66 loc) · 2.24 KB
/
ibp_errno.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* IBP Client version 1.0: Internet BackPlane Protocol
* University of Tennessee, Knoxville TN.
* Authors: Y. Zheng A. Bassi, W. Elwasif, J. Plank, M. Beck
* (C) 1999 All Rights Reserved
*
* NOTICE
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby granted
* provided that the above copyright notice appear in all copies and
* that both the copyright notice and this permission notice appear in
* supporting documentation.
*
* Neither the Institution (University of Tennessee) nor the Authors
* make any representations about the suitability of this software for
* any purpose. This software is provided ``as is'' without express or
* implied warranty.
*
*/
// *** Modified by Alan Tackett on 7/7/2008 for sync/async compatiblity
#define _log_module_index 130
#include <stdlib.h>
#include <apr_pools.h>
#include <apr_thread_proc.h>
static apr_threadkey_t *errno_key;
apr_thread_once_t *_err_once = NULL;
apr_pool_t *_err_mpool = NULL;
int _times_used = 0;
//***************************************************************************
void ibp_errno_destroy()
{
_times_used--;
if (_times_used != 0) return;
apr_pool_destroy(_err_mpool);
}
//***************************************************************************
void ibp_errno_init()
{
if (_times_used != 0) return;
_times_used++;
apr_pool_create(&_err_mpool, NULL);
apr_thread_once_init(&_err_once, _err_mpool);
}
//***************************************************************************
void _errno_destructor( void *ptr)
{
free(ptr);
}
//***************************************************************************
void _errno_once(void)
{
apr_threadkey_private_create(&errno_key,_errno_destructor, _err_mpool);
}
//***************************************************************************
int *_IBP_errno()
{
void *output = NULL;
apr_thread_once(_err_once,_errno_once);
apr_threadkey_private_get(&output, errno_key);
if (output == NULL ) {
output = (void *)malloc(sizeof(int));
apr_threadkey_private_set(output, errno_key);
}
return((int *)output);
}