mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-01-29 10:30:50 +08:00
b80b2c0119
The current implementation is a very simple approach to implement a statically sized sleep queue. The problem is that this code requires a certain amount of synchronization because the slots in the queue are used dynamically. To top it off, the Event objects used for sync'ing are created and destroyed on demand. This is complicated, slow, and error prone. There's also a blatant bug here: The number of slots in the queue was wrongly computed in size. It was too small if XSI IPC was used a lot. Make the code more robust. Let the queue have the right size. Every slot is now used for a specific IPC object. All sync objects (switched to Semaphores) are only created when first required, but never destroyed. This reduces the usage of a critical section to the creation of a new sync object. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
57 lines
1.4 KiB
C
57 lines
1.4 KiB
C
/* bsd_mutex.h: BSD Mutex helper
|
|
|
|
This file is part of Cygwin.
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
details. */
|
|
#ifndef _BSD_MUTEX_H
|
|
#define _BSD_MUTEX_H
|
|
|
|
#define MTX_DEF 0
|
|
|
|
#define MA_OWNED 1
|
|
#define MA_NOTOWNED 2
|
|
|
|
#define PZERO (0x20)
|
|
#define PRIO_MASK (0x1f)
|
|
#define PDROP 0x1000
|
|
#define PCATCH 0x2000
|
|
#define PLOCK 0x3000
|
|
|
|
struct mtx {
|
|
HANDLE h;
|
|
const char *name;
|
|
DWORD owner;
|
|
unsigned long cnt;
|
|
};
|
|
|
|
enum ipc_type {
|
|
SHM,
|
|
MSQ,
|
|
SEM
|
|
};
|
|
|
|
/* Some BSD kernel global mutex. */
|
|
extern struct mtx Giant;
|
|
|
|
void mtx_init (mtx *, const char *, const void *, int);
|
|
void _mtx_lock (mtx *, DWORD winpid, const char *, int);
|
|
#define mtx_lock(m) _mtx_lock((m), (td->ipcblk->winpid), __FILE__, __LINE__)
|
|
int mtx_owned (mtx *, DWORD);
|
|
void _mtx_assert(mtx *, int, DWORD winpid, const char *, int);
|
|
#define mtx_assert(m,w,p) _mtx_assert((m),(w),(p),__FILE__,__LINE__)
|
|
void _mtx_unlock (mtx *, const char *, int);
|
|
#define mtx_unlock(m) _mtx_unlock((m),__FILE__,__LINE__)
|
|
|
|
void mtx_destroy (mtx *);
|
|
|
|
void msleep_init (void);
|
|
int _sleep (ipc_type, int, struct mtx *, int, const char *, int, struct thread *);
|
|
#define _msleep(T,i,m,p,w,t) _sleep((T),(i),(m),(p),(w),(t),(td))
|
|
#define _tsleep(T,i,p,w,t) _sleep((T),(i),NULL,(p),(w),(t),(td))
|
|
int _wakeup (ipc_type, int);
|
|
void wakeup_all (void);
|
|
|
|
#endif /* _BSD_MUTEX_H */
|