Skip to content

Commit

Permalink
add external c interface
Browse files Browse the repository at this point in the history
  • Loading branch information
shuaimu committed Jun 27, 2017
1 parent 2086bbe commit 8afa82b
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 14 deletions.
28 changes: 20 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ else()
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) # Not CLion
endif()


conan_basic_setup()

if(APPLE)
Expand All @@ -21,6 +22,16 @@ else()
set(RT "rt")
endif()

# for c build

add_library(
EXTERN_C
extern_interface/scheduler.c
extern_interface/scheduler.h
)

# for cxx build

set(CMAKE_VERBOSE_MAKEFILE on)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
Expand Down Expand Up @@ -137,7 +148,7 @@ add_library(MEMDB
add_executable(JANUS_PROCESS
# deptran/s_main.cc
${DEPTRAN_SRC}
${BENCH_SRC})
${BENCH_SRC} deptran/extern_c/sched.h deptran/extern_c/frame.h deptran/extern_c/frame.cc deptran/extern_c/sched.cc)

add_dependencies(JANUS_PROCESS gen-rpc)

Expand All @@ -148,13 +159,14 @@ target_link_libraries(
${RT})

target_link_libraries(
JANUS_PROCESS
RRR
MEMDB
${RT}
${CONAN_LIBS}
${CMAKE_THREAD_LIBS_INIT}
${PYTHON2_LIBRARIES}
JANUS_PROCESS
RRR
MEMDB
EXTERN_C
${RT}
${CONAN_LIBS}
${CMAKE_THREAD_LIBS_INIT}
${PYTHON2_LIBRARIES}
# ${APR_LIBRARIES}
# ${APRUTIL_LIBRARIES}
# ${PROFILER_LIBRARIES}
Expand Down
1 change: 1 addition & 0 deletions deptran/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace rococo {
#define MODE_BRQ (0x10)
#define MODE_JANUS (0x10)
#define MODE_MDCC (0x12)
#define MODE_EXTERNC (0x14)
#define MODE_RPC_NULL (64)

// deprecated.
Expand Down
15 changes: 15 additions & 0 deletions deptran/extern_c/frame.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Created by Shuai on 6/25/17.
//

#include "frame.h"
#include "sched.h"

using namespace janus;

Scheduler* ExternCFrame::CreateScheduler() {
Scheduler* sched = new ExternCScheduler();
sched->frame_ = this;
return sched;
}

18 changes: 18 additions & 0 deletions deptran/extern_c/frame.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Created by Shuai on 6/25/17.
//

#pragma once

#include "../frame.h"

namespace janus {


class ExternCFrame : public Frame {
public:
ExternCFrame() : Frame(MODE_EXTERNC) { }
Scheduler *CreateScheduler() override;
};

} // namespace janus
32 changes: 32 additions & 0 deletions deptran/extern_c/sched.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Created by Shuai on 6/27/17.
//

#include "sched.h"


extern "C" {

#include "../../extern_interface/scheduler.h"

}

namespace janus {

bool ExternCScheduler::HandleConflicts(DTxn &dtxn,
innid_t inn_id,
vector<string> &conflicts) {
// TODO call C interface
vector<_c_conflict_id_t> cf(conflicts.size());
for (int i = 0; i < conflicts.size(); i++) {
cf[i].key = const_cast<char*>(conflicts[i].data());
cf[i].ptr_mem = nullptr;
cf[i].rw_flag = 1;
cf[i].sz_key = conflicts[i].size();
}
int r = ::handle_conflicts(dtxn.tid_, conflicts.size(), cf.data());
return (r > 0);
return true;
}

} // namespace janus
20 changes: 20 additions & 0 deletions deptran/extern_c/sched.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "../scheduler.h"

//
// Created by Shuai on 6/25/17.
//

namespace janus {

class ExternCScheduler : public Scheduler {
using Scheduler::Scheduler;
public:
virtual bool HandleConflicts(DTxn& dtxn,
innid_t inn_id,
vector<string>& conflicts) override;

};

} // namespace janus
2 changes: 1 addition & 1 deletion deptran/janus/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "../frame.h"

namespace rococo {
namespace janus {

class JanusFrame : public Frame {
public:
Expand Down
2 changes: 1 addition & 1 deletion deptran/janus/sched.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "commo.h"
#include "../rcc/dtxn.h"

using namespace rococo;
using namespace janus;


map<txnid_t, RccDTxn*> JanusSched::Aggregate(RccGraph &graph) {
Expand Down
3 changes: 2 additions & 1 deletion deptran/janus/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#pragma once
#include "../rcc/sched.h"

namespace rococo {
namespace janus {

class RccGraph;
class JanusCommo;
class JanusSched : public RccSched {
Expand Down
1 change: 0 additions & 1 deletion deptran/scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ void Scheduler::OnDispatch(TxnPieceData& piece_data,
verify(!up_pause);
up_pause.reset(new IntEvent(0, 1));
up_pause->Wait();
verify(false);
}

// wait for an execution signal.
Expand Down
19 changes: 19 additions & 0 deletions extern_interface/scheduler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "scheduler.h"

// test for c-cpp bridge
int hello_c() {
return 0;
}


//// a sample implementation for "none" mode.
int32_t handle_conflicts(int64_t txn_id,
int32_t n_confict,
_c_conflict_id_t* conflicts) {
// never pause.
return 0;
}

int64_t poll_executable() {
return 0;
}
32 changes: 32 additions & 0 deletions extern_interface/scheduler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include "inttypes.h"

/**
* This is a C interface for external concurrency control protocols.
* @param txn_id the transaction id greater than 0
* @param rw_flag 0 for read for read, 1 for write.
* @return 0 for continue and 1 for pause.
*/

typedef struct {
int32_t rw_flag;
char* key;
int32_t sz_key;
void** ptr_mem;
} _c_conflict_id_t;

int hello_c();

int32_t handle_conflicts(
int64_t txn_id,
int32_t n_confict,
_c_conflict_id_t* conflicts
);

/**
*
* @return the transaction id for next executable 0 for nothing.
*/
int64_t poll_executable();

10 changes: 8 additions & 2 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pargs = ['--cflags', '--libs']
#BOOST_LIBS = 'BOOST_SYSTEM BOOST_FILESYSTEM BOOST_THREAD BOOST_COROUTINE'

def options(opt):
opt.load("compiler_c")
opt.load("compiler_cxx unittest_gtest")
opt.load(['boost'],
tooldir=['.waf-tools'])
Expand Down Expand Up @@ -42,7 +43,7 @@ def options(opt):
def configure(conf):
_choose_compiler(conf)
_enable_pic(conf)

conf.load("compiler_c")
conf.load("compiler_cxx unittest_gtest")
conf.load("boost")

Expand Down Expand Up @@ -106,6 +107,11 @@ def build(bld):
_depend("old-test/benchmark_service.h", "old-test/benchmark_service.rpc",
"bin/rpcgen --cpp old-test/benchmark_service.rpc")

bld.stlib(source=bld.path.ant_glob("extern_interface/scheduler.c"),
target="externc",
includes="",
use="")

bld.stlib(source=bld.path.ant_glob("rrr/base/*.cpp "
"rrr/misc/*.cpp "
"rrr/rpc/*.cpp "
Expand Down Expand Up @@ -160,7 +166,7 @@ def build(bld):
target="deptran_server",
includes=". rrr deptran ",
uselib="YAML-CPP BOOST",
use="rrr memdb PTHREAD PROFILER RT")
use="externc rrr memdb PTHREAD PROFILER RT")

# bld.program(source=bld.path.ant_glob("deptran/c_main.cc"),
# target="deptran_client",
Expand Down

0 comments on commit 8afa82b

Please sign in to comment.