https://github.com/jacob-c-smith/sync
Cross platform synchronization primitives and high-precision timing
https://github.com/jacob-c-smith/sync
c synchronization
Last synced: 5 months ago
JSON representation
Cross platform synchronization primitives and high-precision timing
- Host: GitHub
- URL: https://github.com/jacob-c-smith/sync
- Owner: Jacob-C-Smith
- License: mit
- Created: 2023-07-03T04:23:51.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-27T20:50:28.000Z (over 1 year ago)
- Last Synced: 2024-12-27T21:27:52.645Z (over 1 year ago)
- Topics: c, synchronization
- Language: C
- Homepage: https://g10.app/status/#primitives
- Size: 32.2 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sync
[](https://github.com/Jacob-C-Smith/sync/actions/workflows/cmake.yml)
Cross platform synchronization primatives and high precision timestamps
> 0 [Try it](#try-it)
>
> 1 [Download](#download)
>
> 2 [Build](#build)
>
> 3 [Example](#example)
>
>> 3.1 [Example output](#example-output)
>
> 4 [Definitions](#definitions)
>
>> 4.1 [Type definitions](#type-definitions)
>>
>> 4.2 [Function definitions](#function-definitions)
## Try it
[](https://codespaces.new/Jacob-C-Smith/sync?quickstart=1)
Wait for a few moments, then click the play button on the bottom of the window. This will run the example program.
## Download
To download sync, execute the following command
```bash
$ git clone https://github.com/Jacob-C-Smith/sync
```
## Build
To build on UNIX like machines, execute the following commands in the same directory
```bash
$ cd sync
$ cmake .
$ make
```
This will build the example program, the tester program, and dynamic / shared libraries
To build sync for Windows machines, open the base directory in Visual Studio, and build your desired target(s)
## Example
To run the example program, execute this command
```
$ ./sync_example
```
### Example output
[ NONE ]
[Source](main.c)
## Definitions
### Type definitions
```c
typedef ... mutex;
typedef ... rwlock;
typedef ... spinlock;
typedef ... semaphore;
typedef ... condition_variable;
typedef ... monitor;
typedef ... barrier;
typedef signed timestamp;
```
*NOTE: mutex and semaphore definitions are platform dependent*
### Function definitions
```c
// Initializer
void sync_init ( void ) __attribute__((constructor));
// Timer
timestamp timer_high_precision ( void );
signed timer_seconds_divisor ( void );
// Mutex
int mutex_create ( mutex *p_mutex );
int mutex_lock ( mutex *p_mutex );
int mutex_unlock ( mutex *p_mutex );
int mutex_destroy ( mutex *p_mutex );
// Spinlock
int spinlock_create ( spinlock *p_spinlock );
int spinlock_lock ( spinlock *p_spinlock );
int spinlock_unlock ( spinlock *p_spinlock );
int spinlock_destroy ( spinlock *p_spinlock );
// Read Write Lock
int rwlock_create ( rwlock *p_rwlock );
int rwlock_lock_rd ( rwlock *p_rwlock );
int rwlock_lock_wr ( rwlock *p_rwlock );
int rwlock_lock_timeout_rd ( rwlock *p_rwlock, timestamp _time );
int rwlock_lock_timeout_wr ( rwlock *p_rwlock, timestamp _time );
int rwlock_unlock ( rwlock *p_rwlock );
int rwlock_destroy ( rwlock *p_rwlock );
// Semaphore
int semaphore_create ( semaphore *p_semaphore, unsigned int count );
int semaphore_wait ( semaphore _semaphore );
int semaphore_signal ( semaphore _semaphore );
int semaphore_destroy ( semaphore *p_semaphore );
// Condition variable
int condition_variable_create ( condition_variable *p_condition_variable );
int condition_variable_wait ( condition_variable *p_condition_variable, mutex *p_mutex );
int condition_variable_wait_timeout ( condition_variable *p_condition_variable, mutex *p_mutex, timestamp _time );
int condition_variable_signal ( condition_variable *const p_condition_variable );
int condition_variable_broadcast ( condition_variable *const p_condition_variable );
int condition_variable_destroy ( condition_variable *p_condition_variable );
// Monitor
int monitor_create ( monitor *p_monitor );
int monitor_wait ( monitor *p_monitor );
int monitor_notify ( monitor *p_monitor );
int monitor_notify_all ( monitor *p_monitor );
int monitor_destroy ( monitor *p_monitor );
// Barrier
int barrier_create ( barrier *p_barrier, int count );
int barrier_wait ( barrier *p_barrier );
int barrier_destroy ( barrier *p_barrier );
// Cleanup
void sync_exit ( void ) __attribute__((destructor));
```