NCBI C++ ToolKit
prefetch_impl.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef PREFETCH_IMPL__HPP
2 #define PREFETCH_IMPL__HPP
3 
4 /* $Id: prefetch_impl.hpp 58009 2013-05-02 19:00:01Z vasilche $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Aleksey Grichenko, Eugene Vasilchenko
30 *
31 * File Description:
32 * Prefetch implementation
33 *
34 */
35 
36 #include <corelib/ncbistd.hpp>
37 #include <corelib/ncbiobj.hpp>
38 #include <corelib/ncbithr.hpp>
39 #include <objmgr/data_loader.hpp>
40 #include <util/thread_pool.hpp>
41 #include <util/sync_queue.hpp>
42 #include <vector>
43 #include <set>
44 
47 
48 class CScope;
49 class CSeq_id;
50 class CSeq_id_Handle;
51 class CBioseq_Handle;
52 class CPrefetchThreadOld;
53 class CDataSource;
54 class CTSE_Lock;
55 
57 {
58 public:
59  typedef vector<CSeq_id_Handle> TIds;
60 
62 
64 
65 private:
66  friend class CPrefetchTokenOld;
67  friend class CPrefetchThreadOld;
68 
70  typedef vector<TTSE_Lock> TFetchedTSEs;
72 
73  CPrefetchTokenOld_Impl(const TIds& ids, unsigned int depth);
74 
75  void x_InitPrefetch(CScope& scope);
76  void x_SetNon_locking(void);
77 
78  // Hide copy methods
81 
82  bool IsValid(void) const;
83 
84  CBioseq_Handle NextBioseqHandle(CScope& scope);
85 
86  void AddTokenReference(void);
87  void RemoveTokenReference(void);
88 
89  // Called by fetching function when id is loaded
90  void AddResolvedId(size_t id_idx, TTSE_Lock tse);
91 
92  // Checked by CPrefetchThreadOld before processing next id
93  bool IsEmpty(void) const;
94 
95  int m_TokenCount; // Number of tokens referencing this impl
96  TIds m_Ids; // requested ids in the original order
97  size_t m_CurrentId; // next id to return
98  TFetchedTSEs m_TSEs; // loaded TSEs
99  TTSE_Map m_TSEMap; // Map TSE to number of related IDs
100  int m_PrefetchDepth; // Max. number of TSEs to prefetch
101  CSemaphore m_TSESemaphore; // Signal to fetch next TSE
102  bool m_Non_locking; // Do not lock TSEs (used for caching)
104 };
105 
106 
108 {
109 public:
110  CPrefetchThreadOld(CDataSource& data_source);
111 
112  // Add request to the fetcher queue
113  void AddRequest(CPrefetchTokenOld_Impl& token);
114 
115  // Stop the thread (since Exit() can not be called from
116  // data loader's destructor).
117  void Terminate(void);
118 
119 protected:
120  virtual void* Main(void);
121  // protected destructor as required by CThread
122  ~CPrefetchThreadOld(void);
123 
124 private:
125  // Using list to be able to delete elements
127 
131  bool m_Stop; // used to stop the thread
132 };
133 
134 
137 
138 #endif // PREFETCH_IMPL__HPP
CBioseq_Handle –.
CFastMutex –.
Definition: ncbimtx.hpp:667
CObject –.
Definition: ncbiobj.hpp:180
CDataSource & m_DataSource
TPrefetchQueue m_Queue
CSyncQueue< CRef< CPrefetchTokenOld_Impl > > TPrefetchQueue
map< TTSE_Lock, int > TTSE_Map
DECLARE_OPERATOR_BOOL(IsValid())
vector< TTSE_Lock > TFetchedTSEs
CPrefetchTokenOld_Impl(const CPrefetchTokenOld_Impl &)
CPrefetchTokenOld_Impl & operator=(const CPrefetchTokenOld_Impl &)
vector< CSeq_id_Handle > TIds
CPrefetchToken –.
Definition: prefetch.hpp:62
CScope –.
Definition: scope.hpp:92
CSemaphore –.
Definition: ncbimtx.hpp:1375
Thread-safe queue object with a blocking mechanism.
Definition: sync_queue.hpp:217
Include a standard set of the NCBI C++ Toolkit most basic headers.
static unsigned char depth[2 *(256+1+29)+1]
int Main(int argc, const char *argv[])
bool IsValid(const CSeq_point &pt, CScope *scope)
Checks that point >= 0 and point < length of Bioseq.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NCBI_XOBJMGR_EXPORT
Definition: ncbi_export.h:1307
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Multi-threading – classes, functions, and features.
Definition of synchronized queue (CSyncQueue template) and templates related to it.
Pool of generic task-executing threads.
Modified on Fri Sep 20 14:58:28 2024 by modify_doxy.py rev. 669887