Skip to content

Instantly share code, notes, and snippets.

@rsjaffe
rsjaffe / spinlock.h
Last active April 7, 2021 17:14
Spinlock with exponential backoff, test before lock, randomized backoff
/*
==============================================================================
Copyright 2019 Rory Jaffe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rsjaffe
rsjaffe / ConcurrentQueue.h
Last active June 15, 2022 13:14
Simple Blocking/Nonblocking Concurrent (thread-safe) Queue Adapter, defaulting to deque implementation, using mutexes and condition variable waits
#ifndef RSJ_CONCURRENT_QUEUE_H
#define RSJ_CONCURRENT_QUEUE_H
/*
==============================================================================
Copyright 2019 Rory Jaffe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
@rsjaffe
rsjaffe / randutils.hpp
Created March 28, 2019 16:10 — forked from imneme/randutils.hpp
Addresses common issues with C++11 random number generation; makes good seeding easier, and makes using RNGs easy while retaining all the power.
/*
* Random-Number Utilities (randutil)
* Addresses common issues with C++11 random number generation.
* Makes good seeding easier, and makes using RNGs easy while retaining
* all the power.
*
* The MIT License (MIT)
*
* Copyright (c) 2015 Melissa E. O'Neill
*
@rsjaffe
rsjaffe / move and create junction.bat
Created August 17, 2018 23:45
Windows batch file to move a directory and create a junction from its prior location to its new one. Useful for creating space on a small ssd.
robocopy %1 %2 /E /MOVE /R:3 /W:2
IF NOT ERRORLEVEL 2 mklink /j %1 %2