File: syncthread.c

package info (click to toggle)
fsarchiver 0.6.15-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,416 kB
  • sloc: ansic: 10,042; sh: 3,871; makefile: 46
file content (98 lines) | stat: -rw-r--r-- 2,520 bytes parent folder | download | duplicates (2)
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
/*
 * fsarchiver: Filesystem Archiver
 *
 * Copyright (C) 2008-2012 Francois Dupoux.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License v2 as published by the Free Software Foundation.
 *
 * This program 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.
 *
 * Homepage: http://www.fsarchiver.org
 */

#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

#include <signal.h>

#include "fsarchiver.h"
#include "fsarchiver.h"
#include "syncthread.h"
#include "queue.h"

// queue use to share data between the three sort of threads
cqueue g_queue;

// filesystem bitmap used by do_extract() to say to threadio_readimg which filesystems to skip
// eg: "g_fsbitmap[0]=1,g_fsbitmap[1]=0" means that we want to read filesystem 0 and skip fs 1
u8 g_fsbitmap[FSA_MAX_FSPERARCH];

// g_stopfillqueue is set to true when the threads that reads the queue wants to stop
// either because there is an error or because it does not need the next data
atomic_t g_stopfillqueue={ (false) };
atomic_t g_aborted={ (false) };

void set_stopfillqueue()
{   
    atomic_set(&g_stopfillqueue, true);
}

bool get_stopfillqueue()
{
    return atomic_read(&g_stopfillqueue);
}

// how many secondary threads are running (compression/decompression and archio threads)
atomic_t g_secthreads={ (0) };

void inc_secthreads()
{
    (void)__sync_add_and_fetch(&g_secthreads.counter, 1);
}

void dec_secthreads()
{
    (void)__sync_sub_and_fetch(&g_secthreads.counter, 1);
}

int get_secthreads()
{
    return atomic_read(&g_secthreads);
}

bool get_interrupted()
{
    return (get_abort()==true || get_stopfillqueue()==true);
}

// get_abort() returns true if a SIGINT/SIGTERM has been received (interrupted by the user)
int get_abort()
{
    int mysigs[]={SIGINT, SIGTERM, -1};
    sigset_t mask_set;
    sigpending(&mask_set);
    int i;
    
    if (atomic_read(&g_aborted)==true)
        return true;
    
    if (sigpending(&mask_set)==0)
    {
        for (i=0; mysigs[i]!=-1; i++)
        {
            if (sigismember(&mask_set, mysigs[i]))
            {   //msgprintf(MSG_FORCE, "get_terminate(): received signal %d\n", mysigs[i]);
                atomic_set(&g_aborted, true);
                return true;
            }
        }
    }
    
    return false;
}