Skip to content

Instantly share code, notes, and snippets.

View deadtrickster's full-sized avatar
🤷‍♂️
🍄

Iliia Khaprov deadtrickster

🤷‍♂️
🍄
View GitHub Profile
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-9 9
sudo update-alternatives --install /usr/bin/clang-cl clang-cl /usr/bin/clang-cl-9 9
sudo update-alternatives --install /usr/bin/clang-import-test clang-import-test /usr/bin/clang-import-test-9 9
sudo update-alternatives --install /usr/bin/clang-rename clang-rename /usr/bin/clang-rename-9 9
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-9 9
sudo update-alternatives --install /usr/bin/clang-cpp clang-cpp /usr/bin/clang-cpp-9 9
sudo update-alternatives --install /usr/bin/clang-include-fixer clang-include-fixer /usr/bin/clang-include-fixer-9 9
sudo update-alternatives --install /usr/bin/clang-reorder-fields clang-reorder-fields /usr/bin/clang-reorder-fields-9 9
sudo update-alternatives --install /usr/bin/clang-apply-replacements clang-apply-replacements /usr/bin/clang-apply-replacements-9 9
sudo update-alternatives --install /usr/bin/clang-offload-bundler clang-offload-bundler /usr/bin/clang-offload-bu
## http://pastebin.com/sL6CPidx
## by Tanner__ from #prometheus
## not for production!!!
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus
data:
prometheus.yml: |-
global:
(ql:quickload :iolib)
(ql:quickload :eventfd)
(setf control-fd (eventfd:eventfd.new 0))
(setf event-base (make-instance 'iolib:event-base))
(setf thread (bt:make-thread (lambda ()
(iolib:set-io-handler event-base
control-fd
:read (lambda (fd e ex)
(declare (ignorable fd e ex)))
/* stop all other threads by sending them SIG_STOP_FOR_GC */
for(p=all_threads; p; p=p->next) {
gc_assert(p->os_thread != 0);
FSHOW_SIGNAL((stderr,"/gc_stop_the_world: thread=%lu, state=%x\n",
p->os_thread, thread_state(p)));
if((p!=th) && ((thread_state(p)==STATE_RUNNING))) {
FSHOW_SIGNAL((stderr,"/gc_stop_the_world: suspending thread %lu\n",
p->os_thread));
/* We already hold all_thread_lock, P can become DEAD but
* cannot exit, ergo it's safe to use pthread_kill. */
(with-pinned-objects (queue me)
(setf (waitqueue-token queue) me)
(release-mutex mutex)
;; Now we go to sleep using futex-wait. If anyone else
;; manages to grab MUTEX and call CONDITION-NOTIFY during
;; this comment, it will change the token, and so futex-wait
;; returns immediately instead of sleeping. Ergo, no lost
;; wakeup. We may get spurious wakeups, but that's ok.
(setf status
(case (allow-with-interrupts
(defun receive-message (mailbox &key timeout)
"Removes the oldest message from MAILBOX and returns it as the primary
value, and a secondary value of T. If MAILBOX is empty waits until a message
arrives.
If TIMEOUT is provided, and no message arrives within the specified interval,
returns primary and secondary value of NIL."
(tagbody
;; Disable interrupts for keeping semaphore count in sync with
;; #msgs in the mailbox.
(sb-sys:without-interrupts
@deadtrickster
deadtrickster / io-loop.lisp
Last active October 8, 2016 12:29
io-loop.lisp
(let* ((mailbox (sb-concurrency:make-mailbox))
(event-base (make-instance 'iolib:event-base))
(control-fd (eventfd:eventfd.new 0))
(thread (bt:make-thread (lambda ()
(iolib:set-io-handler event-base
control-fd
:read (lambda (fd e ex)
(declare (ignorable fd e ex))
(log:debug (eventfd.read control-fd))))
(loop (iolib:event-dispatch event-base :one-shot t))))))

Isolated test

Before:

7> benchmark:run(100, 1*1000*1000).
{1190.6,100000000}

After:

Keybase proof

I hereby claim:

  • I am deadtrickster on github.
  • I am deadtrickster (https://keybase.io/deadtrickster) on keybase.
  • I have a public key whose fingerprint is 8838 3471 5B97 B18A 7B12 F958 76A9 29E1 8553 C165

To claim this, I am signing this object:

@deadtrickster
deadtrickster / links
Last active August 22, 2016 18:39
Elixir SuperMacro