Skip to content

Instantly share code, notes, and snippets.

View kumagi's full-sized avatar
:octocat:
Fine.

Hiroki KUMAZAKI kumagi

:octocat:
Fine.
View GitHub Profile
@kumagi
kumagi / threadpool.hpp
Created January 30, 2010 20:01
thread pool with lockfree queue
#ifndef THREAD_POOL
#define THREAD_POOL
#include <pthread.h>
#include <stdlib.h> // malloc
#include <unistd.h> // sleep,usleep
#include "queue.hpp"
#include <assert.h>
#include <sys/resource.h> // rlimit
namespace{
@kumagi
kumagi / lockfree_stack.cpp
Created February 5, 2010 20:12
lock-free stack like STL
template<typename obj>
class lf_stack{
private:
class node{
public:
obj data;
node* next;
node(const obj& d):data(d),next(NULL){ }
};
volatile node *head;
@kumagi
kumagi / deviding_tag.cpp
Created February 9, 2010 14:48
Deviding tag
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <time.h>
class deviding_tag {
private:
@kumagi
kumagi / lockfree::queue.hpp
Created April 22, 2010 18:26
lockfree queue without hazard pointer
#ifndef LOCKFREE_QUEUE
#define LOCKFREE_QUEUE
#include "atomics.h"
#include <unistd.h> // usleep
#include <stdlib.h> // rand
namespace lockfree{
template<typename T>
@kumagi
kumagi / atomics.h
Created April 22, 2010 18:28
atomic operation wrapper for i386 and x86_64
#ifndef ATOMICS
#define ATOMICS
#if __x86_64__ || _WIN64
#define _64BIT
#define _ptr long long
#else
#define _32BIT
#define _ptr int
#!/usr/bin/python
import msgpack
import socket,struct,sys,time
SET=0
GET=1
DELETE=2
FOUND=3
DONE=4
NONE=5
@kumagi
kumagi / msgpack_client.cpp
Created April 24, 2010 10:13
msgpack KVSclient sample
#include <stdint.h>
#include <msgpack.hpp>
#include <mp/wavy.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
@kumagi
kumagi / msgpack_server.cpp
Created April 24, 2010 10:18
msgpack KVSserver sample
#include <stdint.h>
#include <stdlib.h>
#include <msgpack.hpp>
#include <mp/wavy.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
@kumagi
kumagi / tcp_wrapper.cpp
Created May 28, 2010 07:34
tcp socket wrapper for kumagi
static int OK = 1;
int create_tcpsocket(void){
int fd = socket(AF_INET,SOCK_STREAM, 0);
if(fd < 0){
perror("scocket");
}
return fd;
}
@kumagi
kumagi / tokyo cabinet hashmap in C++
Created June 24, 2010 14:38
tokyo cabinet C++ wrapper
#ifndef TCPP_HPP_
#define TCPP_HPP_
#include <tcutil.h>
#include <tchdb.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>