2022-08-19 21:46:27 +08:00
|
|
|
/* miscfuncs.h: Internal functions not having a better home
|
2008-04-08 00:33:44 +08:00
|
|
|
|
|
|
|
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 _MISCFUNCS_H
|
|
|
|
#define _MISCFUNCS_H
|
POSIX barrier implementation, take 3
The attached patch should address all of the review comments.
Modifed change log:
Newlib:
* libc/include/sys/features.h (_POSIX_BARRIERS): Define for Cygwin.
* libc/include/sys/types.h (pthread_barrier_t)
(pthread_barrierattr_t): Do not define for Cygwin.
Cygwin:
* common.din (pthread_barrierattr_init)
(pthread_barrierattr_setpshared, pthread_barrierattr_getpshared)
(pthread_barrierattr_destroy, pthread_barrier_init)
(pthread_barrier_destroy, pthread_barrier_wait): Export.
* include/cygwin/types.h (pthread_barrierattr_t)
(pthread_barrier_t): Declare.
* include/pthread.h (PTHREAD_BARRIER_SERIAL_THREAD)
(pthread_barrierattr_init, pthread_barrierattr_setpshared)
(pthread_barrierattr_getpshared, pthread_barrierattr_destroy)
(pthread_barrier_init, pthread_barrier_destroy)
(pthread_barrier_wait): Declare.
* thread.h (PTHREAD_BARRIER_MAGIC)
(PTHREAD_BARRIERATTR_MAGIC): Define.
(class pthread_barrierattr, class pthread_barrier): Declare.
* thread.cc (delete_and_clear): New local helper function.
(class pthread_barrierattr, class pthread_barrier): Implement.
* miscfuncs.h (likely, unlikely): New macros.
--
VH
2016-02-13 05:25:59 +08:00
|
|
|
|
2017-01-20 04:41:21 +08:00
|
|
|
#include <dinput.h>
|
|
|
|
|
POSIX barrier implementation, take 3
The attached patch should address all of the review comments.
Modifed change log:
Newlib:
* libc/include/sys/features.h (_POSIX_BARRIERS): Define for Cygwin.
* libc/include/sys/types.h (pthread_barrier_t)
(pthread_barrierattr_t): Do not define for Cygwin.
Cygwin:
* common.din (pthread_barrierattr_init)
(pthread_barrierattr_setpshared, pthread_barrierattr_getpshared)
(pthread_barrierattr_destroy, pthread_barrier_init)
(pthread_barrier_destroy, pthread_barrier_wait): Export.
* include/cygwin/types.h (pthread_barrierattr_t)
(pthread_barrier_t): Declare.
* include/pthread.h (PTHREAD_BARRIER_SERIAL_THREAD)
(pthread_barrierattr_init, pthread_barrierattr_setpshared)
(pthread_barrierattr_getpshared, pthread_barrierattr_destroy)
(pthread_barrier_init, pthread_barrier_destroy)
(pthread_barrier_wait): Declare.
* thread.h (PTHREAD_BARRIER_MAGIC)
(PTHREAD_BARRIERATTR_MAGIC): Define.
(class pthread_barrierattr, class pthread_barrier): Declare.
* thread.cc (delete_and_clear): New local helper function.
(class pthread_barrierattr, class pthread_barrier): Implement.
* miscfuncs.h (likely, unlikely): New macros.
--
VH
2016-02-13 05:25:59 +08:00
|
|
|
#define likely(X) __builtin_expect (!!(X), 1)
|
|
|
|
#define unlikely(X) __builtin_expect (!!(X), 0)
|
|
|
|
|
2017-01-20 04:41:21 +08:00
|
|
|
/* Check for Alt+Numpad keys in a console input record. These are used to
|
|
|
|
enter codepoints not available in the current keyboard layout For details
|
|
|
|
see http://www.fileformat.info/tip/microsoft/enter_unicode.htm */
|
|
|
|
static inline bool
|
|
|
|
is_alt_numpad_key (PINPUT_RECORD pirec)
|
|
|
|
{
|
2017-08-01 20:10:50 +08:00
|
|
|
/* Remove lock key state from ControlKeyState. Do not remove enhanced key
|
|
|
|
state since it helps to distinguish between cursor (EK) and numpad keys
|
|
|
|
(non-EK). */
|
|
|
|
DWORD ctrl_state = pirec->Event.KeyEvent.dwControlKeyState
|
|
|
|
& ~(CAPSLOCK_ON | NUMLOCK_ON | SCROLLLOCK_ON);
|
|
|
|
|
2017-01-20 04:41:21 +08:00
|
|
|
return pirec->Event.KeyEvent.uChar.UnicodeChar == 0
|
2017-08-01 20:10:50 +08:00
|
|
|
&& ctrl_state == LEFT_ALT_PRESSED
|
2017-01-20 04:41:21 +08:00
|
|
|
&& pirec->Event.KeyEvent.wVirtualScanCode >= DIK_NUMPAD7
|
|
|
|
&& pirec->Event.KeyEvent.wVirtualScanCode <= DIK_NUMPAD0
|
|
|
|
&& pirec->Event.KeyEvent.wVirtualScanCode != DIK_SUBTRACT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Event for left Alt, with a non-zero character, comes from Alt+Numpad
|
|
|
|
key sequence. e.g. <left-alt> 233 => é This is typically handled
|
|
|
|
as the key up event after releasing the Alt key. */
|
|
|
|
static inline bool
|
|
|
|
is_alt_numpad_event (PINPUT_RECORD pirec)
|
|
|
|
{
|
|
|
|
return pirec->Event.KeyEvent.uChar.UnicodeChar != 0
|
|
|
|
&& pirec->Event.KeyEvent.wVirtualKeyCode == VK_MENU
|
|
|
|
&& pirec->Event.KeyEvent.wVirtualScanCode == 0x38;
|
|
|
|
}
|
2016-03-18 21:46:20 +08:00
|
|
|
|
2022-05-24 03:52:52 +08:00
|
|
|
int winprio_to_nice (DWORD);
|
|
|
|
DWORD nice_to_winprio (int &);
|
2008-04-08 00:33:44 +08:00
|
|
|
|
2022-05-24 03:52:52 +08:00
|
|
|
bool create_pipe (PHANDLE, PHANDLE, LPSECURITY_ATTRIBUTES, DWORD);
|
2008-04-08 00:33:44 +08:00
|
|
|
|
2022-08-05 03:16:32 +08:00
|
|
|
BOOL CreatePipeOverlapped (PHANDLE read_handle, PHANDLE write_handle,
|
|
|
|
LPSECURITY_ATTRIBUTES sa);
|
|
|
|
BOOL ReadPipeOverlapped (HANDLE h, PVOID buf, DWORD len,
|
|
|
|
LPDWORD ret_len, DWORD timeout);
|
|
|
|
BOOL WritePipeOverlapped (HANDLE h, LPCVOID buf, DWORD len,
|
|
|
|
LPDWORD ret_len, DWORD timeout);
|
2011-08-13 18:28:15 +08:00
|
|
|
|
2014-02-09 04:57:27 +08:00
|
|
|
/* class for per-line reading using native functions. The caller provides
|
|
|
|
the file as an POBJECT_ATTRIBUTES, and the buffer space. */
|
|
|
|
class NT_readline
|
|
|
|
{
|
|
|
|
HANDLE fh;
|
|
|
|
PCHAR buf;
|
|
|
|
PCHAR got;
|
|
|
|
PCHAR end;
|
|
|
|
ULONG buflen;
|
|
|
|
ULONG len;
|
|
|
|
ULONG line;
|
|
|
|
public:
|
|
|
|
NT_readline () : fh (NULL) {}
|
|
|
|
bool init (POBJECT_ATTRIBUTES attr, char *buf, ULONG buflen);
|
|
|
|
PCHAR gets ();
|
2014-02-17 00:02:18 +08:00
|
|
|
void close () { if (fh) NtClose (fh); fh = NULL; }
|
|
|
|
~NT_readline () { close (); }
|
2014-02-09 04:57:27 +08:00
|
|
|
};
|
|
|
|
|
2010-03-13 07:13:48 +08:00
|
|
|
extern "C" void yield ();
|
2008-04-08 00:33:44 +08:00
|
|
|
|
|
|
|
void backslashify (const char *, char *, bool);
|
|
|
|
void slashify (const char *, char *, bool);
|
|
|
|
#define isslash(c) ((c) == '/')
|
|
|
|
|
2009-11-02 19:42:04 +08:00
|
|
|
extern void transform_chars (PWCHAR, PWCHAR);
|
2012-12-22 05:30:56 +08:00
|
|
|
extern inline void
|
2009-11-02 19:42:04 +08:00
|
|
|
transform_chars (PUNICODE_STRING upath, USHORT start_idx)
|
|
|
|
{
|
|
|
|
transform_chars (upath->Buffer + start_idx,
|
|
|
|
upath->Buffer + upath->Length / sizeof (WCHAR) - 1);
|
|
|
|
}
|
|
|
|
|
2018-03-03 01:11:57 +08:00
|
|
|
PWCHAR transform_chars_af_unix (PWCHAR, const char *, __socklen_t);
|
|
|
|
|
2021-09-03 16:15:57 +08:00
|
|
|
/* Get handle count of an object. */
|
|
|
|
ULONG get_obj_handle_count (HANDLE h);
|
|
|
|
|
2022-05-24 03:52:52 +08:00
|
|
|
ssize_t check_iovec (const struct iovec *, int, bool);
|
2008-04-08 00:33:44 +08:00
|
|
|
#define check_iovec_for_read(a, b) check_iovec ((a), (b), false)
|
|
|
|
#define check_iovec_for_write(a, b) check_iovec ((a), (b), true)
|
2011-05-16 02:49:40 +08:00
|
|
|
|
2016-07-28 07:40:23 +08:00
|
|
|
void SetThreadName (DWORD dwThreadID, const char* threadName);
|
|
|
|
|
2018-08-07 20:51:10 +08:00
|
|
|
WORD __get_cpus_per_group (void);
|
2019-06-24 05:51:06 +08:00
|
|
|
WORD __get_group_count (void);
|
2018-08-07 20:51:10 +08:00
|
|
|
|
2008-04-08 00:33:44 +08:00
|
|
|
#endif /*_MISCFUNCS_H*/
|