Skip to content

Instantly share code, notes, and snippets.

@jainvishal
jainvishal / Foo.h
Last active November 3, 2023 23:20
First C++ Apache Module
#pragma once
#include <string>
using std::string;
#include "http_protocol.h"
class Foo {
public:
int RunHandler(request_rec *req) {
@jainvishal
jainvishal / shared_mutex.cpp
Last active August 18, 2017 21:33
pSudo code for Exclusive Write to wait for Shared read to finish, Shared read to wait for Exclusive Write to finish
class MyLocker {
// Exclusive Write, which will wait for shared read to finish
// Shared read, which will wait for Exclusive Write to finish
public:
MyLocker() : mSharedUsage(0), mExclusiveWrite(false) {}
void ExclusiveWriteLock();
void ExclusiveWriteUnLock();
void SharedReadLock();
void SharedReadUnLock();
private:
@jainvishal
jainvishal / mylog.vim
Last active June 28, 2017 16:13
Vim File Detection configuration for Log file and coloring
" Vim syntax file
" Language: My Log Processor
" Maintainer: Vishal Jain
" Latest Revision: 24 September 2014
if exists("b:current_syntax")
finish
endif
syn match String /="[^"]*"&amp;/hs=s+1,he=e-1
@jainvishal
jainvishal / ignoreField.awk
Created August 1, 2016 19:02
Ignore a Field/Column using AWK
## usage awk -F',' -v FieldToIgnore=2 -f ignoreField.awk datafile
## This just gives the basic idea. More error detection can be done.
{
if (FieldToIgnore == "" || FieldToIgnore <= 0) {
print "Incorrect/Missing field"
print "usage: awk -F',' -v FieldToIgnore=<FieldumnToIgnore> -f ignoreField.awk datafile"
exit
}
for (i = 1; i <= NF; i++)
if (i == FieldToIgnore) {
# Signal Hanlder
Handle_Exit_Safely()
{
rm -f $lockfile
exit
}
# Main body
if [ ! -e $lockfile ]; then
# Arm the handler
@jainvishal
jainvishal / gcc4_8_mutex_timing_issue.cpp
Created September 11, 2014 15:41
GCC 4.8 timing issue in mutex locking
/**
* This code displays the timing issue in mutex locking as exhibited by GCC 4.8.
* Parent/main function locks a mutex then starts the thread. This thread tries
* to lock the same mutex for a specified duration (5 second in this example).
* Once lock succeed (because main is expected to unlock mutex in 2 seconds),
* thread waits for another 5 seconds on a conditional variable.
*
* Using gcc 4.6 behaviour is following showing right timeline of events.
* 1410448076263 M mutex locked
* 1410448076264 T lock try