File: _kievents_wait_windows.c

package info (click to toggle)
python-kinterbasdb 3.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,044 kB
  • ctags: 1,157
  • sloc: ansic: 6,879; python: 2,517; makefile: 77
file content (76 lines) | stat: -rw-r--r-- 2,408 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
/* KInterbasDB Python Package - Implementation of Event Waiting - Windows
**
** Version 3.1
**
** The following contributors hold Copyright (C) over their respective
** portions of code (see license.txt for details):
**
** [Original Author (maintained through version 2.0-0.3.1):]
**   1998-2001 [alex]  Alexander Kuznetsov   <alexan@users.sourceforge.net>
** [Maintainers (after version 2.0-0.3.1):]
**   2001-2002 [maz]   Marek Isalski         <kinterbasdb@maz.nu>
**   2002-2004 [dsr]   David Rushby          <woodsplitter@rocketmail.com>
** [Contributors:]
**   2001      [eac]   Evgeny A. Cherkashin  <eugeneai@icc.ru>
**   2001-2002 [janez] Janez Jere            <janez.jere@void.si>
*/

/* This source file is designed to be directly included in _kievents.c,
** without the involvement of a header file. */

/************************* PUBLIC FUNCTIONS:BEGIN ****************************/

PlatformEventType platform_create_event_object() {
  HANDLE event_handle = CreateEvent(
      NULL, /* no security attributes */

      /* Use *manual* signal reset (rather than automatic, which would reset
      ** the signal when the first waiting thread awakened). */
      TRUE,

      FALSE, /* initial state non-signaled */
      NULL /* name (for access from other processes) */
    );

  return event_handle;
} /* platform_create_event_object */


void platform_free_event_object(PlatformEventType event) {
  if (event == NULL) {
    return;
  }
  CloseHandle(event);
} /* platform_free_event_object */


int event_queue_wait(EventQueue *queue, long timeout_millis) {
  DWORD native_timeout =
    (  timeout_millis == (long) WAIT_INFINITELY
       ? INFINITE : (DWORD) timeout_millis
    );

  DWORD wait_result = WaitForSingleObject(queue->event, native_timeout);

  if (wait_result == WAIT_FAILED) {
    return EVENT_ERROR;
  } else if (wait_result == WAIT_TIMEOUT) {
    return EVENT_TIMEOUT;
  } else {
    return EVENT_OK;
  }
} /* event_queue_wait */


int event_queue_signal(EventQueue *queue) {
  /* SetEvent returns zero on failure. */
  return (SetEvent(queue->event) == 0) ? EVENT_ERROR : EVENT_OK;
} /* event_queue_signal */


int event_queue_unsignal(EventQueue *queue) {
  /* ResetEvent returns zero on failure. */
  return (ResetEvent(queue->event) == 0) ? EVENT_ERROR : EVENT_OK;
} /* event_queue_unsignal */

/************************* PUBLIC FUNCTIONS:END ****************************/