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

Subversion Repositories pc_fpga_com

[/] [pc_fpga_com/] [trunk/] [PC_FPGA_PLATFPORM/] [SOFTWARE/] [background_reader.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 NikosAl
/*
2
 * Copyright (C) 2011 Simon A. Berger
3
 *
4
 *  This program is free software; you may redistribute it and/or modify its
5
 *  under the terms of the GNU Lesser General Public License as published by the Free
6
 *  Software Foundation; either version 2 of the License, or (at your option)
7
 *  any later version.
8
 *
9
 *  This program is distributed in the hope that it will be useful, but
10
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11
 *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 *  for more details.
13
 */
14
 
15
 
16
#ifndef BACKGROUND_READER_H
17
#define BACKGROUND_READER_H
18
 
19
 
20
#ifdef __cplusplus
21
 
22
#include <boost/thread/mutex.hpp>
23
#include <boost/thread/thread.hpp>
24
#include <boost/thread/barrier.hpp>
25
#include <boost/scoped_ptr.hpp>
26
 
27
#include <deque>
28
#include <vector>
29
 
30
#include <pthread.h>
31
#include <stdint.h>
32
// the all singing, all dancing background reader, written in shiny new c++
33
 
34
class background_reader
35
{
36
    typedef boost::mutex mutex_t;
37
    //typedef boost::unique_lock<mutex_t> unique_lock_t;
38
    typedef boost::lock_guard<mutex_t> lock_guard_t;
39
 
40
    boost::condition_variable m_can_read_condition;
41
    boost::mutex m_pq_mtx;
42
    //boost::scoped_ptr<boost::thread> m_thread;
43
    boost::thread_group m_thread_group;
44
 
45
    volatile bool m_stop; // FIXME: use atomic var
46
    int m_socket;
47
 
48
    size_t m_max_size;
49
 
50
    std::deque<std::string> m_pq;
51
    size_t m_pq_mem;
52
    size_t m_pq_max_mem;
53
 
54
    size_t m_pq_max_depth;
55
 
56
 
57
    //pthread_t m_native_handle;
58
    boost::mutex m_nh_mtx;
59
    std::vector<pthread_t> m_native_handles;
60
    const size_t N_THREADS;
61
    boost::barrier m_run_barrier;
62
    bool m_threads_joined;
63
 
64
    void run();
65
public:
66
    background_reader( int s, size_t size );
67
    virtual ~background_reader();
68
 
69
    void start();
70
    void interrupt();
71
    void stop() { m_stop = true; __sync_synchronize(); } // try to make sure that the new value of m_stop is visible to all bg threads before interrupt is called.
72
    void join();
73
 
74
    ssize_t block_recv( void* buf, size_t size );
75
    ssize_t poll();
76
    ssize_t purge();
77
 
78
 
79
};
80
#endif
81
 
82
// the boring old ansi c interface
83
 
84
#ifdef __cplusplus
85
extern "C" {
86
#endif
87
 
88
typedef struct fpga_bgr_s {
89
    void *bgr_cpp;
90
} fpga_bgr_t;
91
 
92
 
93
void fpga_bgr_init( fpga_bgr_t *bgr, int socket, size_t size );
94
void fpga_bgr_delete( fpga_bgr_t *bgr );
95
 
96
void fpga_bgr_start( fpga_bgr_t *bgr);
97
ssize_t fpga_bgr_block_recv( fpga_bgr_t *bgr, void *buf, size_t size );
98
ssize_t fpga_bgr_poll();
99
void fpga_bgr_stop_interrupt_join( fpga_bgr_t *bgr);
100
 
101
// high level functions
102
int fpga_bgr_recv_charv( fpga_bgr_t *bgr, char *buf, size_t n );
103
int fpga_bgr_recv_shortv( fpga_bgr_t *bgr, int16_t *buf, size_t n );
104
int fpga_bgr_recv_intv( fpga_bgr_t *bgr, int32_t *buf, size_t n );
105
int fpga_bgr_recv_longv( fpga_bgr_t *bgr, int64_t *buf, size_t n );
106
int fpga_bgr_recv_floatv( fpga_bgr_t *bgr, float *buf, size_t n );
107
int fpga_bgr_recv_doublev( fpga_bgr_t *bgr, double *buf, size_t n );
108
 
109
#ifdef __cplusplus
110
}
111
#endif
112
 
113
 
114
 
115
#endif // BACKGROUND_READER_H

powered by: WebSVN 2.1.0

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