]> git.imager.perl.org - imager.git/blame - mutexwin.c
extend some variable types to avoid overflows for mediancut
[imager.git] / mutexwin.c
CommitLineData
24c9233d
TC
1/*
2=head1 NAME
3
4mutex.c - Imager's mutex API.
5
6=head1 FUNCTIONS
7
8=over
9
10=cut
11*/
12
13#include "imageri.h"
14
15#include <windows.h>
16
17struct i_mutex_tag {
18 CRITICAL_SECTION section;
19};
20
21/*
22=item i_mutex_new()
23=category Mutex functions
24=synopsis i_mutex_t m = i_mutex_new();
25=order 10
26
27Create a mutex.
28
29If a critical section cannot be created for whatever reason, Imager
30will abort.
31
32=cut
33*/
34
35i_mutex_t
36i_mutex_new(void) {
37 i_mutex_t m;
38
a8b8be5b
TC
39 m = malloc(sizeof(*m));
40 if (!m)
41 i_fatal(3, "Cannot allocate mutex object");
24c9233d
TC
42 InitializeCriticalSection(&(m->section));
43
44 return m;
45}
46
47/*
48=item i_mutex_destroy(m)
49=category Mutex functions
50=synopsis i_mutex_destroy(m);
51
52Destroy a mutex.
53
54=cut
55*/
56
57void
58i_mutex_destroy(i_mutex_t m) {
59 DeleteCriticalSection(&(m->section));
a8b8be5b 60 free(m);
24c9233d
TC
61}
62
63/*
64=item i_mutex_lock(m)
65=category Mutex functions
66=synopsis i_mutex_lock(m);
67
68Lock the mutex, waiting if another thread has the mutex locked.
69
70=cut
71*/
72
73void
74i_mutex_lock(i_mutex_t m) {
75 EnterCriticalSection(&(m->section));
76}
77
78/*
79=item i_mutex_unlock(m)
80=category Mutex functions
81=synopsis i_mutex_unlock(m);
82
83Release the mutex.
84
85The behavior of releasing a mutex you don't hold is unspecified.
86
87=cut
88*/
89
90void
91i_mutex_unlock(i_mutex_t m) {
92 LeaveCriticalSection(&(m->section));
93}
94