-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.cpp
98 lines (74 loc) · 2.12 KB
/
context.cpp
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
89
90
91
92
93
94
95
96
97
98
/*
Copyright 2010 Toshiyuki Terashita.
fuse-autohttpfs is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this software. If not, see <http://www.gnu.org/licenses/>.
*/
#include <signal.h>
#include "context.h"
#include "int64format.h"
// AutoHttpFsContext class implements.
AutoHttpFsContext::AutoHttpFsContext(uint64_t seq, RemoteAttr& attr)
{
m_seq = seq;
m_attr = &attr;
proc = NULL;
}
AutoHttpFsContext::~AutoHttpFsContext()
{
}
// AutoHttpFsContexts class implements.
AutoHttpFsContexts::AutoHttpFsContexts(AutoHttpFs* fs)
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&m_lock, &attr);
m_fs = fs;
m_contexts.clear();
m_proc.init();
sequence = 1;
}
AutoHttpFsContexts::~AutoHttpFsContexts()
{
}
AutoHttpFsContext* AutoHttpFsContexts::alloc_context()
{
AutoHttpFsContext* ctx = NULL;
pthread_mutex_lock(&m_lock);
{
ctx = new AutoHttpFsContext(sequence, m_attr);
m_contexts.insert(AutoHttpFsContextMap::value_type(sequence, ctx));
sequence++;
}
pthread_mutex_unlock(&m_lock);
return ctx;
}
void AutoHttpFsContexts::release_context(AutoHttpFsContext* ctx)
{
pthread_mutex_lock(&m_lock);
{
m_contexts.erase(ctx->seq());
}
pthread_mutex_unlock(&m_lock);
delete ctx;
}
AutoHttpFsContext* AutoHttpFsContexts::find(uint64_t seq)
{
AutoHttpFsContextMap::iterator it;
pthread_mutex_lock(&m_lock);
{
it = m_contexts.find(seq);
}
pthread_mutex_unlock(&m_lock);
if(it!=m_contexts.end()) return (*it).second;
return NULL;
}
// vim: sw=2 sts=2 ts=4 expandtab :