diff options
author | Joan Lledó <joanlluislledo@gmail.com> | 2018-01-16 12:54:28 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-10-30 00:47:36 +0100 |
commit | a830bef66e689f6f1defa9988f257a7ec2bb034d (patch) | |
tree | 3d49249a05195148fc8a8e6a84f9c56b46dbab7b /pci-arbiter/ncache.c | |
parent | 6783a1b124eff9383571dfd4b5e83a03ee63866a (diff) | |
download | hurd-a830bef66e689f6f1defa9988f257a7ec2bb034d.tar.gz hurd-a830bef66e689f6f1defa9988f257a7ec2bb034d.tar.bz2 hurd-a830bef66e689f6f1defa9988f257a7ec2bb034d.zip |
PCI Arbiter
Diffstat (limited to 'pci-arbiter/ncache.c')
-rw-r--r-- | pci-arbiter/ncache.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/pci-arbiter/ncache.c b/pci-arbiter/ncache.c new file mode 100644 index 00000000..6a513e37 --- /dev/null +++ b/pci-arbiter/ncache.c @@ -0,0 +1,90 @@ +/* Node caching + + Copyright (C) 1997 Free Software Foundation, Inc. + Written by Miles Bader <miles@gnu.org> + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "ncache.h" + +#include <unistd.h> +#include <string.h> +#include <hurd/netfs.h> + +#include "pcifs.h" +#include "netfs_impl.h" + +/* Implementation of node caching functions */ + +/* Remove NN's node from its position in FS's node cache. */ +void +node_unlink (struct node *node, struct pcifs *fs) +{ + struct netnode *nn = node->nn; + if (nn->ncache_next) + nn->ncache_next->nn->ncache_prev = nn->ncache_prev; + if (nn->ncache_prev) + nn->ncache_prev->nn->ncache_next = nn->ncache_next; + if (fs->node_cache_mru == node) + fs->node_cache_mru = nn->ncache_next; + if (fs->node_cache_lru == node) + fs->node_cache_lru = nn->ncache_prev; + nn->ncache_next = 0; + nn->ncache_prev = 0; + fs->node_cache_len--; +} + +/* Add NODE to the recently-used-node cache, which adds a reference to + prevent it from going away. NODE should be locked. */ +void +node_cache (struct node *node) +{ + struct netnode *nn = node->nn; + + pthread_mutex_lock (&fs->node_cache_lock); + + if (fs->params.node_cache_max > 0 || fs->node_cache_len > 0) + { + if (fs->node_cache_mru != node) + { + if (nn->ncache_next || nn->ncache_prev) + /* Node is already in the cache. */ + node_unlink (node, fs); + else + /* Add a reference from the cache. */ + netfs_nref (node); + + nn->ncache_next = fs->node_cache_mru; + nn->ncache_prev = 0; + if (fs->node_cache_mru) + fs->node_cache_mru->nn->ncache_prev = node; + if (!fs->node_cache_lru) + fs->node_cache_lru = node; + fs->node_cache_mru = node; + fs->node_cache_len++; + } + + /* Forget the least used nodes. */ + while (fs->node_cache_len > fs->params.node_cache_max) + { + struct node *lru = fs->node_cache_lru; + node_unlink (lru, fs); + netfs_nrele (lru); + } + } + + pthread_mutex_unlock (&fs->node_cache_lock); +} |