• Stars
    star
    270
  • Rank 152,189 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created about 13 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Implementation of Win32 events for *nix platforms, built on top of pthreads.

pevents

pevents is a cross-platform low-level library meant to provide an implementation of the WIN32 events for POSIX systems. pevents is built on pthreads and provides most of the functionality of both manual- and auto-reset events on Windows, most-notably including simultaneous waits on multiple events (ร  la WaitForMultipleObjects).

pevents also doubles as a thin, sane wrapper for CreateEvent() & co. on Windows, meaning you can use pevents directly in your cross-platform code without #ifdefs for Windows/pthreads.

License and Authorship

pevents is developed and maintained by Mahmoud Al-Qudsi <[email protected]> of NeoSmart Technologies <https://neosmart.net/> and is distributed under the open source MIT public license. Refer to the LICENSE file for more information.

About pevents

While POSIX condition variables (pthread_cond_t) and WIN32 events both provide the essential building blocks of the synchronization primitives required to write multithreaded code with signaling, the nature of the differences between the two have lent their way towards creating different synchronization and multithreaded-programming paradigms.

Developers accustomed to WIN32 events might have a hard time transitioning to condition variables; pevents aims to ease the transition for Windows developers looking to write multithreaded code on *nix by providing a familiar synchronization primitive that will allow them to duplicate the essential features of WIN32 auto/manual-reset events.

As mentioned earlier, pevents provides most of the functionality of WIN32 events. The only features not included are only named events and support for security attributes. To the author's best knowledge, this is the only implementation of WIN32 events available for Linux and other posix platforms that provides support for simultaneously waiting on multiple events.

Depending on your needs, we've been told that pevents may be used as a lightweight alternative to libuv/libev while still allowing your code to embrace asynchronous event handling with ease.

Supported platforms

pevents has been used as an extremely simple and lightweight cross-platform synchronization library in code used across multiple platforms (including Windows, FreeBSD, Linux, macOS, iOS, Android, and more).

pevents API

The pevents API is modeled after the Windows CreateEvent(), WaitForSingleObject(), and WaitForMultipleObjects() functions. Users familiar with WIN32 events should have no problem switching the codebase over to the pevents API.

Additionally, pevents is also free of spurious wakeups - returns from waits are guaranteed correctยน.

ยน Spurious wakeups are a normal part of system programming under Linux, and a common pitfall for developers coming from the Windows world.

neosmart_event_t CreateEvent(bool manualReset, bool initialState);

int DestroyEvent(neosmart_event_t event);

int WaitForEvent(neosmart_event_t event, uint64_t milliseconds);

int WaitForMultipleEvents(neosmart_event_t *events, int count,
		bool waitAll, uint64_t milliseconds);

int WaitForMultipleEvents(neosmart_event_t *events, int count,
		bool waitAll, uint64_t milliseconds, int &index);

int SetEvent(neosmart_event_t event);

int ResetEvent(neosmart_event_t event);

int PulseEvent(neosmart_event_t event);

Building and using pevents

All the code is contained within pevents.cpp and pevents.h. You should include these two files in your project as needed. All functions are in the neosmart namespace.

Code structure

  • Core pevents code is in the src/ directory
  • Unit tests (deployable via meson) are in tests/
  • A sample cross-platform application demonstrating the usage of pevents can be found in the examples/ folder. More examples are to come. (Pull requests welcomed!)

Optional build system

Experimental support for building pevents via the meson build system has recently landed. Currently, this is only used to support automated building/testing of pevents core and its supporting utilities and unit tests. To repeat: do not worry about the build system, pevents is purposely written in plain C/C++ and avoids the need for complex configuration or platform-dependent build instructions.

Compilation options:

The following preprocessor definitions may be defined (-DOPTION) at compile time to enable different features.

  • WFMO: Enables WFMO support in pevents. It is recommended to only compile with WFMO support if you are taking advantage of the WaitForMultipleEvents function, as it adds a (small) overhead to all event objects.

  • PULSE: Enables the PulseEvent function. PulseEvent() on Windows is fundamentally broken and should not be relied upon โ€” it will almost never do what you think you're doing when you call it. pevents includes this function only to make porting existing (flawed) code from WIN32 to *nix platforms easier, and this function is not compiled into pevents by default.

More Repositories

1

AsyncLock

An async/await-friendly lock for .NET, complete with asynchronous waits, safe reeฬˆntrance, and more.
C#
193
star
2

securestore-rs

A simple, encrypted, git-friendly, file-backed secrets manager for rust
Rust
136
star
3

CppSQLite

A simple and easy-to-use cross-platform C++ wrapper for the SQLite API. Fork of the CppSQLite project, originally by Rob Groves, currently updated and maintained by NeoSmart Technologies.
C++
131
star
4

tac

A high-performance, cross-platform file reverse utility
Rust
108
star
5

SecureStore

A .NET implementation of the cross-platform SecureStore (symmetrically-encrypted secrets) protocol
C#
96
star
6

RunInBash

Run Linux commands under WSL without leaving your PowerShell or CMD!
C++
91
star
7

unicode.net

A Unicode library for .NET, supporting UTF8, UTF16, and UTF32. With an extra helping of emoji for good measure ๐Ÿ”ฅ๐ŸŒถ๏ธ๐Ÿ˜
C#
87
star
8

SqliteCache

An ASP.NET Core IDistributedCache provider backed by SQLite
C#
82
star
9

msvcrt.lib

msvcrt.lib for linking against msvcrt.dll on all versions of Windows
C
80
star
10

prettysize-rs

Pretty-print file sizes and more
Rust
42
star
11

udpproxy

Cross-platform UDP proxy
Rust
39
star
12

ln-win

JunctionPoint library and ln clone for Windows.
C++
33
star
13

PrettySize.net

Format/print file sizes in a human-readable format.
C#
30
star
14

UrlBase64

A standards-compliant implementation of web/url-safe base64 encoding and decoding for .NET targets
C#
30
star
15

paste

A Windows utility that simply dumps the clipboard data to stdout
C++
26
star
16

rewrite

An in-place file rewrite utility, useful for redirecting output to same file as source.
Rust
26
star
17

rsproxy

A simple, command-line TCP/UDP proxy server
Rust
25
star
18

betterpad

A better notepad. Still simple. Still fast.
C#
24
star
19

cryptostream

Read and Write stream adapters for on-the-fly encryption and decryption for rust
Rust
23
star
20

uuidxx

Cross-platform C++ library for parsing and generating UUIDs or GUIDs. Windows, Mac, Linux, and BSD.
C++
20
star
21

rsevents

Auto- and manual-reset events for rust
Rust
19
star
22

LastPassTo1Password

A LastPass to 1Password converter.
C#
16
star
23

gmake-proxy

A BSD make (bmake) proxy that invokes GNU make (gmake) instead
Makefile
16
star
24

rsevents-extra

Extra event types built on top of rsevents
Rust
16
star
25

EasyBCD-Localization

EasyBCD localization files for NLT. Help us translate EasyBCD into your language, it's easy and rewarding!
Shell
14
star
26

StreamCompare

A .NET library and nuget package for stream comparison.
C#
12
star
27

open

Like macOS `open` but for Windows
C++
12
star
28

UrlPreview

A .NET library for loading URL previews.
C#
11
star
29

collections

A collection of various data structures and containers for .NET Standard
C#
11
star
30

zipcat

Pipe contents of zip file to stdout, supporting multiple files.
Rust
11
star
31

web

A collection of helpful classes and functions for writing ASP.NET projects, for both MVC and forms. Save time and effort with this small and highly-performant "framework."
C#
10
star
32

Localization

The NeoSmart Localization and Regionalization Toolkit (NLRT).
C#
9
star
33

TaskThreads

A Task-based System.Threading.Threads implementation for Universal Windows Platform applications.
C#
9
star
34

pkg-graph

A graphviz generator for pkg, the FreeBSD package manager
Rust
9
star
35

CargoMake

A Makefile for Cargo-based rust projects
Makefile
8
star
36

UtfRedirect

Helper application used to host a guest exe, transparently proxying bi-directional stdin and stdout traffic, forcing the console input and output codepages to UTF8/6501 in order to support internationalized stdin/stdout on Windows.
Rust
8
star
37

ExtensionMethods

A collection of helpful .NET extension methods for desktop and web development
C#
6
star
38

paypalnvp-dotnet

Minimal and lightweight PayPal NVP library for C# and .NET
C#
5
star
39

paypalnvp-php

Minimal and lightweight PayPal NVP Library for PHP.
PHP
4
star
40

run

A simple, invisible application launcher for Windows
C++
4
star
41

xf86-video-scfb

FreeBSD syscons framebuffer Xorg driver
Shell
4
star
42

nettest

Tiny and bare-bones command-line utility to test for the presence of an internet connection on Windows.
Rust
4
star
43

ignore-result

Adds `.ignore()` to rust `Result` types
Rust
4
star
44

RedisDictionary

A redis-backed persistent dictionary for C#, .NET, and .NET Core
C#
3
star
45

UwpTaskbarIcon

Taskbar icon library for Windows 10
C#
3
star
46

linqplus

Additional LINQ methods optimized for specific data structures, functional LINQ methods, and more.
C#
3
star
47

textlist

Generate properly formatted and grammatically correct text lists from arrays and IEnumerables.
C#
2
star
48

hashing.net

NeoSmart hashing library for .NET
C#
2
star
49

synchronization

A collection of async-friendly synchronization objects for .NET and .NET Core
C#
2
star
50

Stream.CopyTo

A Stream.CopyTo() implementation for .NET 2.0, 3.0, and 3.5
C#
2
star
51

bandit.net

A multi-armed bandit A/B testing library for .NET platforms
C#
2
star
52

nst-ses

Community fork of Amazon's AWS SES (Simple Email Service) Perl framework. Contains important compatibility and integration improvements.
Perl
2
star
53

ms-sys

C
2
star
54

nst-log

A basic and cross-platform logging library for C++ applications. Features an easy to use singleton class, a simple API, convience wrappers, and very little overhead. For those looking for a logging library that doesn't overwhelm.
C++
2
star
55

showkeys

Rust
1
star
56

wp-prism

A githubesque syntax highlighting and code fencing plugin for WordPress.
PHP
1
star
57

relaunch

A simple, cross-platform, zero-configuration process monitor/relauncher
Rust
1
star
58

hivexx

C++ wrapper around the excellent hivex library, focused on safety and speed.
C++
1
star
59

UwpCache

An object cache for UWP applications.
C#
1
star