OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [fs/] [jffs2/] [current/] [src/] [gcthread.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
/*
2
 * JFFS2 -- Journalling Flash File System, Version 2.
3
 *
4
 * Copyright (C) 2001-2003 Red Hat, Inc.
5
 *
6
 * Created by David Woodhouse <dwmw2@redhat.com>
7
 *
8
 * For licensing information, see the file 'LICENCE' in this directory.
9
 *
10
 * $Id: gcthread.c,v 1.3 2005/01/22 16:01:12 lunn Exp $
11
 *
12
 */
13
#include <linux/kernel.h>
14
#include "nodelist.h"
15
#include <cyg/kernel/kapi.h>
16
 
17
#define GC_THREAD_FLAG_TRIG 1
18
#define GC_THREAD_FLAG_STOP 2
19
#define GC_THREAD_FLAG_HAS_EXIT 4
20
 
21
static cyg_thread_entry_t jffs2_garbage_collect_thread;
22
 
23
void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c)
24
{
25
     struct super_block *sb=OFNI_BS_2SFFJ(c);
26
 
27
     /* Wake up the thread */
28
     D1(printk("jffs2_garbage_collect_trigger\n"));
29
 
30
     cyg_flag_setbits(&sb->s_gc_thread_flags,GC_THREAD_FLAG_TRIG);
31
}
32
 
33
 
34
void
35
jffs2_start_garbage_collect_thread(struct jffs2_sb_info *c)
36
{
37
     struct super_block *sb=OFNI_BS_2SFFJ(c);
38
 
39
     CYG_ASSERTC(c);
40
     CYG_ASSERTC(!sb->s_gc_thread_handle);
41
 
42
     cyg_flag_init(&sb->s_gc_thread_flags);
43
     cyg_mutex_init(&sb->s_lock);
44
 
45
     D1(printk("jffs2_start_garbage_collect_thread\n"));
46
     /* Start the thread. Doesn't matter if it fails -- it's only an
47
      * optimisation anyway */
48
     cyg_thread_create(CYGNUM_JFFS2_GC_THREAD_PRIORITY,
49
                       jffs2_garbage_collect_thread,
50
                       (cyg_addrword_t)c,"jffs2 gc thread",
51
                       (void*)sb->s_gc_thread_stack,
52
                       sizeof(sb->s_gc_thread_stack),
53
                       &sb->s_gc_thread_handle,
54
                       &sb->s_gc_thread);
55
 
56
     cyg_thread_resume(sb->s_gc_thread_handle);
57
}
58
 
59
void
60
jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c)
61
{
62
     struct super_block *sb=OFNI_BS_2SFFJ(c);
63
 
64
     CYG_ASSERTC(sb->s_gc_thread_handle);
65
 
66
     D1(printk("jffs2_stop_garbage_collect_thread\n"));
67
     /* Stop the thread and wait for it if necessary */
68
 
69
     cyg_flag_setbits(&sb->s_gc_thread_flags,GC_THREAD_FLAG_STOP);
70
 
71
     D1(printk("jffs2_stop_garbage_collect_thread wait\n"));
72
 
73
     cyg_flag_wait(&sb->s_gc_thread_flags,
74
                   GC_THREAD_FLAG_HAS_EXIT,
75
                   CYG_FLAG_WAITMODE_OR| CYG_FLAG_WAITMODE_CLR);
76
 
77
     // Kill and free the resources ...  this is safe due to the flag
78
     // from the thread.
79
     cyg_thread_kill(sb->s_gc_thread_handle);
80
     cyg_thread_delete(sb->s_gc_thread_handle);
81
 
82
     cyg_mutex_destroy(&sb->s_lock);
83
     cyg_flag_destroy(&sb->s_gc_thread_flags);
84
}
85
 
86
 
87
static void
88
jffs2_garbage_collect_thread(cyg_addrword_t data)
89
{
90
     struct jffs2_sb_info *c=(struct jffs2_sb_info *)data;
91
     struct super_block *sb=OFNI_BS_2SFFJ(c);
92
     cyg_flag_value_t flag;
93
     cyg_mtab_entry *mte;
94
 
95
     D1(printk("jffs2_garbage_collect_thread START\n"));
96
 
97
     while(1) {
98
          flag=cyg_flag_timed_wait(&sb->s_gc_thread_flags,
99
                                   GC_THREAD_FLAG_TRIG|GC_THREAD_FLAG_STOP,
100
                                   CYG_FLAG_WAITMODE_OR| CYG_FLAG_WAITMODE_CLR,
101
                                   cyg_current_time()+
102
                                   CYGNUM_JFFS2_GS_THREAD_TICKS);
103
 
104
          if (flag & GC_THREAD_FLAG_STOP)
105
               break;
106
 
107
          D1(printk("jffs2: GC THREAD GC BEGIN\n"));
108
 
109
          mte=cyg_fs_root_lookup((cyg_dir *) sb->s_root);
110
          CYG_ASSERT(mte, "Bad mount point");
111
          cyg_fs_lock(mte, mte->fs->syncmode);
112
 
113
          if (jffs2_garbage_collect_pass(c) == -ENOSPC) {
114
               printf("No space for garbage collection. "
115
                      "Aborting JFFS2 GC thread\n");
116
               break;
117
          }
118
          cyg_fs_unlock(mte, mte->fs->syncmode);
119
          D1(printk("jffs2: GC THREAD GC END\n"));
120
     }
121
 
122
     D1(printk("jffs2_garbage_collect_thread EXIT\n"));
123
     cyg_flag_setbits(&sb->s_gc_thread_flags,GC_THREAD_FLAG_HAS_EXIT);
124
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.