source: golgotha/src/i4/file/async.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.4 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef I4_ASYNC_READ_HH
10#define I4_ASYNC_READ_HH
11
12// This class should probably only be used by files in "i4/files/*"
13
14// This class is a portable implemented of async file reading
15// A thread gets created during init() which runs as long as
16// there is stuff to read and then blocks for a signal from the main
17// program so if nothing needs reading, it runs efficiently.  Request
18// to be read are qued up (max of 16).  The request are processed
19// serially.  If you want to read from multiple devices in parallel,
20// you should create two i4_async_reads, one for each device.
21
22#include "memory/que.hh"
23#include "threads/threads.hh"
24#include "init/init.hh"
25#include "file/file.hh"
26
27class i4_async_reader : public i4_init_class
28{
29  volatile i4_bool stop;
30  i4_signal_object sig;
31
32  i4_bool emulation;
33
34  struct read_request
35  {
36    sw32 fd;
37    w32 size;
38    void *buffer;
39    i4_file_class::async_callback callback;
40    void *context;
41    read_request(sw32 fd, void *buffer,
42                 w32 size, i4_file_class::async_callback callback,
43                 void *context)
44      : fd(fd), buffer(buffer), size(size), callback(callback), context(context) {}
45    read_request() { ; }
46  };
47
48  enum { MAX_REQUEST=16 };
49  enum { STACK_SIZE=8096 };
50  i4_critical_section_class que_lock;
51  i4_fixed_que<read_request, MAX_REQUEST> request_que;
52  void emulate_speeds(read_request &r);
53
54protected:
55
56  virtual w32 read(sw32 fd, void *buffer, w32 count) = 0;
57
58public:
59  // name is just some unique name.  Windows requires this for Semaphores
60  i4_async_reader(char *name);
61
62  void init();   // creates thread (called by i4_init()
63  void uninit(); // waits for thread to die (called by i4_uninit()
64
65  // ques up a request
66  i4_bool start_read(int fd, void *buffer, w32 size,
67                     i4_file_class::async_callback call,
68                     void *context);
69
70  void PRIVATE_thread();  // don't call this!
71};
72
73
74#endif
Note: See TracBrowser for help on using the repository browser.