Skip to content

Instantly share code, notes, and snippets.

View geky's full-sized avatar
🚏
Temporarily disconnected

Christopher Haster geky

🚏
Temporarily disconnected
View GitHub Profile
@geky
geky / events.md
Last active June 8, 2016 04:08
Composable Event Loops

Composable Event Loops

At the simplest level, composable event loops combine the cheap synchronicity of event loops with the composability of preempted threads.

Multithreading

In a traditional OS, asynchronous tasks are generally accomplished by multiple threads or processes. Each thread has its own stack and is preempted periodically to switch between active threads. Low-level synchronization primitives or synchronized queues are often used to communicate between running threads.

Example of a multithreaded teapot:

@geky
geky / mbed.mk
Last active October 15, 2019 20:31
Simple makefile for mbed OS
MBED = $(firstword $(wildcard mbed mbed-os core .))
TARGET = K82F
TOOLCHAIN = GCC_ARM
#SRC ?= $(firstword $(wildcard TESTS/*/*))
BUILD ?= BUILD
BOARD ?= BOARD
VENDOR ?= MBED ARM STMicroelectronics
BAUD ?= 9600
@geky
geky / tips.cpp
Last active November 29, 2016 04:07
// Template programming confusing and gotcha down? overload the template operator for runtime evaluation!
class Hi {
int operator<::>(int i) {
return i+1;
}
};
printf(Hi()<:3:>);
//Tired of typing squiggly brackets? Did you know squiggly brackets can be emitting as long as the code body is a single statement?
@geky
geky / mbed.gdb
Last active October 24, 2017 21:18
define rtx-threads
set $i = 0
set $tcb = (P_TCB)os_active_TCB[0]
while ($tcb)
printf "thread "
output/x $tcb
printf ":\n ptask = "
output/a $tcb->ptask
printf "\n state = "
////// mbed poll //////
// poll for mbed FileHandles
int mbed_poll(FileHandle fhs[], unsigned nfhs, int timeout) {
Timer timer; // set timer to keep spurious wakeups from keeping us from exiting
if (timeout >= 0) {
timer.start();
}
// register semaphore release as sigio callback on all filehandles
#!/usr/bin/env python2
#
# Simple plotter in the shell
#
# Copyright (c) 2016 Christopher Haster
# Distributed under the MIT license
"""
shplot - Simple plotter in the shell
@geky
geky / treemap.py
Last active April 19, 2020 13:35
#!/usr/bin/env python
# Generates a d3-based javascript treemap of memory consumption provided by
# mbed's memap script. Navigating the chart can be done by clicking on a block
# to descend, or the top bar to ascend. Each rectangle is sized proportional
# to the memory footprint, and the memory regions can be filtered by radio
# buttons.
#
# Example usage is something like this in an mbed project:
# python tools/memap.py BUILD/K64F/GCC_ARM/*.map -t GCC_ARM -d 1000 -e json | \
#include "mbed.h"
#include "MBRBlockDevice.h"
#include "SDBlockDevice.h"
#include "FATFileSystem.h"
#include <errno.h>
SDBlockDevice sd(D11, D12, D13, D10);
MBRBlockDevice part1(&sd, 1);
MBRBlockDevice part2(&sd, 2);
#!/usr/bin/env python
import sys
import re
import argparse
import json
import os.path
import itertools
# args
@geky
geky / test.md
Last active October 16, 2017 20:18

Long story long, the minimum block size needed to store all ctz pointers in a filesystem can be found with this formula:

 B = (w/8)log2(2^w / (B - 2(w/8)))

where: B = block size in bytes w = pointer width in bits