aboutsummaryrefslogtreecommitdiff
path: root/man/man3/9p-intmap.html
blob: f6d1822f7653dcc0d6c3078fc3ae12b9f00227ad (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
<head>
<title>9p-intmap(3) - Plan 9 from User Space</title>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
</head>
<body bgcolor=#ffffff>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=10><td>
<tr><td width=20><td>
<tr><td width=20><td><b>9P-INTMAP(3)</b><td align=right><b>9P-INTMAP(3)</b>
<tr><td width=20><td colspan=2>
    <br>
<p><font size=+1><b>NAME     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    Intmap, allocmap, freemap, insertkey, caninsertkey, lookupkey,
    deletekey &ndash; integer to data structure maps<br>
    
</table>
<p><font size=+1><b>SYNOPSIS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>#include &lt;u.h&gt;<br>
    #include &lt;libc.h&gt;<br>
    #include &lt;fcall.h&gt;<br>
    #include &lt;thread.h&gt;<br>
    #include &lt;9p.h&gt;<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    Intmap* allocmap(void (*inc)(void*))<br>
    void &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;freemap(Intmap *map, void (*dec)(void*))<br>
    void* &nbsp;&nbsp;&nbsp;&nbsp;lookupkey(Intmap *map, ulong key)<br>
    void* &nbsp;&nbsp;&nbsp;&nbsp;insertkey(Intmap *map, ulong key, void *val)<br>
    int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;caninsertkey(Intmap *map, ulong key, void *val)<br>
    void* &nbsp;&nbsp;&nbsp;&nbsp;lookupkey(Intmap *map, ulong key)<br>
    void* &nbsp;&nbsp;&nbsp;&nbsp;deletekey(Intmap *map, ulong key)<br>
    </font></tt>
</table>
<p><font size=+1><b>DESCRIPTION     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    An <tt><font size=+1>Intmap</font></tt> is an arbitrary mapping from integers to pointers. <i>Allocmap</i>
    creates a new map, and <i>freemap</i> destroys it. The <i>inc</i> function is
    called each time a new pointer is added to the map; similarly,
    <i>dec</i> is called on each pointer left in the map when it is being
    freed. Typically these functions maintain reference counts.
    New entries are added to the map by calling <i>insertkey</i>, which will
    return the previous value associated with the given <i>key</i>, or zero
    if there was no previous value. <i>Caninsertkey</i> is like <i>insertkey</i>
    but only inserts <i>val</i> if there is no current mapping. It returns
    1 if <i>val</i> was inserted, 0 otherwise. <i>Lookupkey</i> returns the pointer
    associated with <i>key</i>, or zero if there is no such pointer. <i>Deletekey</i>
    removes the entry for <i>id</i> from the map, returning the associated
    pointer, if any. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    Concurrent access to <tt><font size=+1>Intmap</font></tt>s is safe, moderated via a <tt><font size=+1>QLock</font></tt> stored
    in the <tt><font size=+1>Intmap</font></tt> structure. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    In anticipation of the storage of reference-counted structures,
    an increment function <i>inc</i> may be specified at map creation time.
    <i>Lookupkey</i> calls <i>inc</i> (if non-zero) on pointers before returning
    them. If the reference count adjustments were left to the caller
    (and thus not protected by the lock), it would be possible to
    accidentally reclaim a structure if, for example, it was deleted
    from the map and its reference count decremented between the return
    of <i>insertkey</i> and the external increment. <i>Insertkey</i> and <i>caninsertkey</i>
    do <i>not</i> call <i>inc</i> when inserting <i>val</i> into the map, nor do <i>insertkey</i>
    or <i>deletekey</i> call <i>inc</i> when returning old map entries.
    The rationale is that calling an insertion function transfers
    responsibility for the reference to the map, and responsibility
    is given back via the return value of <i>deletekey</i> or the next <i>insertkey</i>.
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <tt><font size=+1>Intmap</font></tt>s are used by the 9P library to implement <tt><font size=+1>Fidpool</font></tt>s and <tt><font size=+1>Reqpool</font></tt>s.<br>
    
</table>
<p><font size=+1><b>SOURCE     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>/usr/local/plan9/src/lib9p/intmap.c<br>
    </font></tt>
</table>
<p><font size=+1><b>SEE ALSO    </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <a href="../man3/9p.html"><i>9p</i>(3)</a>, <a href="../man3/9p-fid.html"><i>9p-fid</i>(3)</a><br>
    
</table>

<td width=20>
<tr height=20><td>
</table>
<!-- TRAILER -->
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=15><td width=10><td><td width=10>
<tr><td><td>
<center>
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
</center>
</table>
<!-- TRAILER -->
</body></html>