libassa
3.5.1
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
assa
IdSet.cpp
Go to the documentation of this file.
1
// -*- c++ -*-
2
//------------------------------------------------------------------------------
3
// IdSet.cpp
4
//------------------------------------------------------------------------------
5
// Copyright (C) 1997-2002 Vladislav Grinchenko
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Library General Public
9
// License as published by the Free Software Foundation; either
10
// version 2 of the License, or (at your option) any later version.
11
//------------------------------------------------------------------------------
12
13
#include "
assa/Logger.h
"
14
#include "
assa/IdSet.h
"
15
16
using namespace
ASSA;
17
18
int
19
IdSet::
20
newid
()
21
{
22
register
int
i;
23
register
int
current;
24
25
trace
(
"IdSet::newid"
);
26
27
current =
m_next_available_id
++;
28
29
if
(
m_next_available_id
< FD_SETSIZE)
30
{
31
// mark current id as being in use
32
FD_SET(current, &
m_id_set_map
);
33
34
// search starting from current position to the end
35
// assuming that m_next_available_id is maintained
36
// to be the lowest available at all times.
37
38
for
(i=current+1; i<FD_SETSIZE; i++)
39
{
40
if
(!FD_ISSET(i, &
m_id_set_map
))
41
{
42
m_next_available_id
= i;
43
return
current;
44
}
45
}
46
// if I am here, I am out of ids
47
m_next_available_id
= FD_SETSIZE;
48
}
49
return
-1;
50
}
51
52
int
53
IdSet::
54
recycle
(
int
id_)
55
{
56
trace
(
"IdSet::recycle"
);
57
58
if
( 0 <= id_ && id_ < FD_SETSIZE ) {
59
FD_CLR(id_, &
m_id_set_map
);
// mark id as free
60
61
// if id is smaller then current, adjust current
62
if
(id_ <
m_next_available_id
) {
63
m_next_available_id
= id_;
64
}
65
return
0;
66
}
67
return
-1;
68
}
Generated on Tue Jun 19 2012 08:04:33 for libassa by
1.8.1.1