From e913e7c4cf0a468c3021dc186a5a12df2063b5e4 Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Mon, 29 Apr 2024 23:59:55 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E4=BC=98=E5=8C=96=E6=9B=B4=E5=8A=A0?= =?UTF-8?q?=E9=AB=98=E6=95=88=E7=9A=84=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- c_src/eGPidInt/eGPidInt.c | 20 ---- c_src/eGPidInt/rebar.config | 7 -- c_src/eNifLock/eNifLock.cc | 105 ++++++-------------- include/eGLock.hrl | 12 --- src/eCLock.erl | 90 ----------------- src/eGLock.app.src | 3 +- src/eGLock.erl | 193 ++++++------------------------------ src/eGLockMgr.erl | 41 -------- src/eGLock_app.erl | 11 -- src/eGLock_sup.erl | 26 ----- src/eGPidInt.erl | 26 ----- 12 files changed, 66 insertions(+), 472 deletions(-) delete mode 100644 c_src/eGPidInt/eGPidInt.c delete mode 100644 c_src/eGPidInt/rebar.config delete mode 100644 include/eGLock.hrl delete mode 100644 src/eCLock.erl delete mode 100644 src/eGLockMgr.erl delete mode 100644 src/eGLock_app.erl delete mode 100644 src/eGLock_sup.erl delete mode 100644 src/eGPidInt.erl diff --git a/README.md b/README.md index 42e8c55..bf59515 100644 --- a/README.md +++ b/README.md @@ -11,5 +11,5 @@ Build 说明 ---- - eCLock 基于c++11 atomic - + eGLock 基于c++11 atomic + 其中要锁的key 不能是列表的字符串 原因是锁表的key会判断是否为list来区分是锁单key 还是锁列表 diff --git a/c_src/eGPidInt/eGPidInt.c b/c_src/eGPidInt/eGPidInt.c deleted file mode 100644 index f3c0f6b..0000000 --- a/c_src/eGPidInt/eGPidInt.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "erl_nif.h" - -static ERL_NIF_TERM pidToInt(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { - ErlNifUInt64 TermInt = (ErlNifUInt64)argv[0]; - return enif_make_uint64(env, TermInt); -} - -static ERL_NIF_TERM intToPid(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { - ErlNifUInt64 Pid; - if (!enif_get_uint64(env, argv[0], &Pid)) - return enif_make_badarg(env); - return (ERL_NIF_TERM)Pid; -} - -static ErlNifFunc nif_funcs[] = { - {"pidToInt", 1, pidToInt}, - {"intToPid", 1, intToPid} -}; - -ERL_NIF_INIT(eGPidInt, nif_funcs, NULL, NULL, NULL, NULL); \ No newline at end of file diff --git a/c_src/eGPidInt/rebar.config b/c_src/eGPidInt/rebar.config deleted file mode 100644 index e830bd8..0000000 --- a/c_src/eGPidInt/rebar.config +++ /dev/null @@ -1,7 +0,0 @@ -{port_specs, [ - {"../../priv/eGPidInt.so", ["*.c"]} -]}. - - - - diff --git a/c_src/eNifLock/eNifLock.cc b/c_src/eNifLock/eNifLock.cc index a042d66..d26109a 100644 --- a/c_src/eNifLock/eNifLock.cc +++ b/c_src/eNifLock/eNifLock.cc @@ -10,17 +10,14 @@ ERL_NIF_TERM atomTrue; ERL_NIF_TERM atomFalse; ERL_NIF_TERM atomUndefined; -typedef struct KeyNode_r -{ +typedef struct KeyNode_r{ int KeyIx; struct KeyNode_r *next; } KeyNode; -bool isNotLocked(KeyNode *LockedHead, int KeyIx) -{ +bool isNotLocked(KeyNode *LockedHead, int KeyIx){ KeyNode *temp = LockedHead; - while (temp != NULL) - { + while (temp != NULL){ if (temp->KeyIx == KeyIx) return false; temp = temp->next; @@ -28,46 +25,33 @@ bool isNotLocked(KeyNode *LockedHead, int KeyIx) return true; } -int nifLoad(ErlNifEnv *env, void **priv_data, ERL_NIF_TERM) -{ +int nifLoad(ErlNifEnv *env, void **priv_data, ERL_NIF_TERM){ atomTrue = enif_make_atom(env, "true"); atomFalse = enif_make_atom(env, "false"); atomUndefined = enif_make_atom(env, "undefined"); return 0; } -bool lockOne(ErlNifEnv *env, ErlNifPid *ThePid, int KeyIx, uint64_t Val) -{ +bool lockOne(ErlNifEnv *env, ErlNifPid *ThePid, int KeyIx, uint64_t Val){ uint64_t Expected = 0; - if (LockSlot[KeyIx].compare_exchange_strong(Expected, Val)) - { + if (LockSlot[KeyIx].compare_exchange_strong(Expected, Val)){ return true; - } - else - { + }else{ ThePid->pid = (ERL_NIF_TERM)Expected; - if (enif_is_process_alive(env, ThePid)) - { + if (enif_is_process_alive(env, ThePid)){ return false; - } - else - { - if (LockSlot[KeyIx].compare_exchange_strong(Expected, Val)) - { + }else{ + if (LockSlot[KeyIx].compare_exchange_strong(Expected, Val)){ return true; - } - else - { + }else{ return false; } } } } -ERL_NIF_TERM tryLock(ErlNifEnv *env, int, const ERL_NIF_TERM argv[]) -{ - if (enif_is_list(env, argv[0])) - { +ERL_NIF_TERM tryLock(ErlNifEnv *env, int, const ERL_NIF_TERM argv[]){ + if (enif_is_list(env, argv[0])){ ERL_NIF_TERM allList = argv[0]; ERL_NIF_TERM head; ErlNifPid ThePid; @@ -75,22 +59,16 @@ ERL_NIF_TERM tryLock(ErlNifEnv *env, int, const ERL_NIF_TERM argv[]) uint64_t Val = (uint64_t)(ThePid.pid); int KeyIx; KeyNode *LockedHead = NULL; - while (enif_get_list_cell(env, allList, &head, &allList)) - { + while (enif_get_list_cell(env, allList, &head, &allList)){ KeyIx = enif_hash(ERL_NIF_INTERNAL_HASH, head, HashSalt) % LockSize; KeyNode OneKeyNode = {KeyIx, LockedHead}; - if (isNotLocked(LockedHead, KeyIx)) - { - if (lockOne(env, &ThePid, KeyIx, Val)) - { + if (isNotLocked(LockedHead, KeyIx)){ + if (lockOne(env, &ThePid, KeyIx, Val)){ LockedHead = &OneKeyNode; - } - else - { + }else{ uint64_t RExpected; KeyNode *temp = LockedHead; - while (temp != NULL) - { + while (temp != NULL){ RExpected = Val; LockSlot[temp->KeyIx].compare_exchange_strong(RExpected, 0); temp = temp->next; @@ -99,30 +77,23 @@ ERL_NIF_TERM tryLock(ErlNifEnv *env, int, const ERL_NIF_TERM argv[]) } } return atomTrue; - } - else - { + }else{ int KeyIx; KeyIx = enif_hash(ERL_NIF_INTERNAL_HASH, argv[0], HashSalt) % LockSize; ErlNifPid ThePid; enif_self(env, &ThePid); uint64_t Val = (uint64_t)(ThePid.pid); - if (lockOne(env, &ThePid, KeyIx, Val)) - { + if (lockOne(env, &ThePid, KeyIx, Val)){ return atomTrue; - } - else - { + }else{ return atomFalse; } } } -ERL_NIF_TERM releaseLock(ErlNifEnv *env, int, const ERL_NIF_TERM argv[]) -{ - if (enif_is_list(env, argv[0])) - { +ERL_NIF_TERM releaseLock(ErlNifEnv *env, int, const ERL_NIF_TERM argv[]){ + if (enif_is_list(env, argv[0])){ ERL_NIF_TERM allList = argv[0]; ERL_NIF_TERM head; ErlNifPid ThePid; @@ -132,50 +103,39 @@ ERL_NIF_TERM releaseLock(ErlNifEnv *env, int, const ERL_NIF_TERM argv[]) int KeyIx; int isAllOk = 1; - while (enif_get_list_cell(env, allList, &head, &allList)) - { + while (enif_get_list_cell(env, allList, &head, &allList)){ KeyIx = enif_hash(ERL_NIF_INTERNAL_HASH, head, HashSalt) % LockSize; RExpected = Expected; - if (!LockSlot[KeyIx].compare_exchange_strong(RExpected, 0)) - { + if (!LockSlot[KeyIx].compare_exchange_strong(RExpected, 0)){ isAllOk = 0; } } return isAllOk > 0 ? atomTrue : atomFalse; - } - else - { + }else{ int KeyIx; KeyIx = enif_hash(ERL_NIF_INTERNAL_HASH, argv[0], HashSalt) % LockSize; ErlNifPid ThePid; enif_self(env, &ThePid); uint64_t Expected = (uint64_t)(ThePid.pid); - if (LockSlot[KeyIx].compare_exchange_strong(Expected, 0)) - { + if (LockSlot[KeyIx].compare_exchange_strong(Expected, 0)){ return atomTrue; - } - else - { + }else{ return atomFalse; } } } -ERL_NIF_TERM getLockPid(ErlNifEnv *env, int, const ERL_NIF_TERM argv[]) -{ +ERL_NIF_TERM getLockPid(ErlNifEnv *env, int, const ERL_NIF_TERM argv[]){ int KeyIx; KeyIx = enif_hash(ERL_NIF_INTERNAL_HASH, argv[0], HashSalt) % LockSize; ErlNifPid ThePid; uint64_t Var = LockSlot[KeyIx].load(); - if (Var > 0) - { + if (Var > 0){ ThePid.pid = (ERL_NIF_TERM)Var; return enif_make_pid(env, &ThePid); - } - else - { + }else{ return atomUndefined; } } @@ -183,6 +143,7 @@ ERL_NIF_TERM getLockPid(ErlNifEnv *env, int, const ERL_NIF_TERM argv[]) static ErlNifFunc nifFuncs[] = { {"tryLock", 1, tryLock}, {"releaseLock", 1, releaseLock}, - {"getLockPid", 1, getLockPid}}; + {"getLockPid", 1, getLockPid} +}; ERL_NIF_INIT(eNifLock, nifFuncs, &nifLoad, NULL, NULL, NULL) \ No newline at end of file diff --git a/include/eGLock.hrl b/include/eGLock.hrl deleted file mode 100644 index 400a85b..0000000 --- a/include/eGLock.hrl +++ /dev/null @@ -1,12 +0,0 @@ -%% 默认超时时间单位:Ms --define(LockTimeOut, 5000). -%% 超时重试时间单位:Ms --define(ReTryTime, 3). - -%% 数组数量 --define(eGLockBatch, 15). - -%% 数组数量 --define(eGLockSize, 2097152). -%% atomics索引 --define(eGLockRef, eGLockRef). diff --git a/src/eCLock.erl b/src/eCLock.erl deleted file mode 100644 index 3b4818d..0000000 --- a/src/eCLock.erl +++ /dev/null @@ -1,90 +0,0 @@ --module(eCLock). - --define(CASE(Cond, Then, That), case Cond of true -> Then; _ -> That end). - -%% 默认超时时间单位:Ms --define(LockTimeOut, 5000). -%% 超时重试时间单位:Ms --define(ReTryTime, 3). - --export([ - tryLock/1 - , tryLock/2 - , releaseLock/1 - , getLockPid/1 - , lockApply/2 - , lockApply/3 -]). - --spec tryLock(KeyOrKeys :: term() | [term()]) -> true | ltimeout. -tryLock(KeyOrKeys) -> - tryLock(KeyOrKeys, ?LockTimeOut). - -tryLock(KeyOrKeys, TimeOut) -> - doTryLock(KeyOrKeys, TimeOut). - -doTryLock(KeyOrKeys, TimeOut) -> - case eNifLock:tryLock(KeyOrKeys) of - true -> - true; - _ -> - loopLock(KeyOrKeys, TimeOut) - end. - -loopLock(KeyOrKeys, TimeOut) -> - receive - after ?ReTryTime -> - LTimeOut = ?CASE(TimeOut == infinity, TimeOut, TimeOut - ?ReTryTime), - case LTimeOut >= 0 of - true -> - case eNifLock:tryLock(KeyOrKeys) of - true -> - true; - _ -> - loopLock(KeyOrKeys, LTimeOut) - end; - _ -> - ltimeout - end - end. - - --spec releaseLock(KeyOrKeys :: term() | [term()]) -> ok. -releaseLock(KeyOrKeys) -> - eNifLock:releaseLocks(KeyOrKeys). - --spec getLockPid(KeyOrKeys :: term() | [term()]) -> ok. -getLockPid(KeyOrKeys) -> - case is_list(KeyOrKeys) of - true -> - [{OneKey, eNifLock:getLockPid(OneKey)} || OneKey <- KeyOrKeys]; - _ -> - {KeyOrKeys, eNifLock:getLockPid(KeyOrKeys)} - end. - --spec lockApply(KeyOrKeys :: term() | [term()], MFAOrFun :: {M :: atom(), F :: atom(), Args :: list()} | {Fun :: function(), Args :: list()}) -> term() | {error, ltimeout} | {error, {lock_apply_error, term()}}. -lockApply(KeyOrKeys, MFAOrFun) -> - lockApply(KeyOrKeys, MFAOrFun, ?LockTimeOut). - --spec lockApply(KeyOrKeys :: term() | [term()], MFAOrFun :: {M :: atom(), F :: atom(), Args :: list()} | {Fun :: function(), Args :: list()}, TimeOut :: integer() | infinity) -> term(). -lockApply(KeyOrKeys, MFAOrFun, TimeOut) -> - case doTryLock(KeyOrKeys, TimeOut) of - true -> - try doApply(MFAOrFun) - catch C:R:S -> - {error, {lock_apply_error, {C, R, S}}} - after - eNifLock:releaseLock(KeyOrKeys), - ok - end; - ltimeout -> - {error, ltimeout} - end. - -doApply({M, F, Args}) -> - apply(M, F, Args); -doApply({Fun, Args}) -> - apply(Fun, Args). - - - diff --git a/src/eGLock.app.src b/src/eGLock.app.src index ebfea3f..adce8fc 100644 --- a/src/eGLock.app.src +++ b/src/eGLock.app.src @@ -1,8 +1,7 @@ {application, eGLock, - [{description, "An OTP application"}, + [{description, "An OTP library"}, {vsn, "0.1.0"}, {registered, []}, - {mod, {eGLock_app, []}}, {applications, [kernel, stdlib]}, {env, []}, {modules, []}, diff --git a/src/eGLock.erl b/src/eGLock.erl index 47c9e48..76768fb 100644 --- a/src/eGLock.erl +++ b/src/eGLock.erl @@ -1,217 +1,84 @@ -module(eGLock). --include("eGLock.hrl"). -define(CASE(Cond, Then, That), case Cond of true -> Then; _ -> That end). +%% 默认超时时间单位:Ms +-define(LockTimeOut, 5000). +%% 超时重试时间单位:Ms +-define(ReTryTime, 3). + -export([ tryLock/1 , tryLock/2 , releaseLock/1 + , getLockPid/1 , lockApply/2 , lockApply/3 ]). --spec tryLock(KeyOrKeys :: term() | [term()]) -> ok | timeout. +-spec tryLock(KeyOrKeys :: term() | [term()]) -> true | ltimeout. tryLock(KeyOrKeys) -> tryLock(KeyOrKeys, ?LockTimeOut). tryLock(KeyOrKeys, TimeOut) -> - ALockRef = persistent_term:get(?eGLockRef), - PidInt = eGPidInt:pidToInt(self()), - case is_list(KeyOrKeys) of - true -> - KeyIxs = getKexIxs(KeyOrKeys, []), - tryLocks(KeyIxs, ALockRef, PidInt, TimeOut); - _ -> - tryLock(erlang:phash2(KeyOrKeys, ?eGLockSize) + 1, ALockRef, PidInt, TimeOut) - end. + doTryLock(KeyOrKeys, TimeOut). -tryLock(KeyIx, ALockRef, PidInt, TimeOut) -> - case tryLockOne(KeyIx, ALockRef, PidInt) of - ok -> - ok; +doTryLock(KeyOrKeys, TimeOut) -> + case eNifLock:tryLock(KeyOrKeys) of + true -> + true; _ -> - loopLock(KeyIx, ALockRef, PidInt, TimeOut) + loopLock(KeyOrKeys, TimeOut) end. -loopLock(KeyIx, ALockRef, PidInt, TimeOut) -> +loopLock(KeyOrKeys, TimeOut) -> receive after ?ReTryTime -> LTimeOut = ?CASE(TimeOut == infinity, TimeOut, TimeOut - ?ReTryTime), case LTimeOut >= 0 of true -> - case tryLockOne(KeyIx, ALockRef, PidInt) of - ok -> - ok; + case eNifLock:tryLock(KeyOrKeys) of + true -> + true; _ -> - loopLock(KeyIx, ALockRef, PidInt, LTimeOut) + loopLock(KeyOrKeys, LTimeOut) end; _ -> - timeout + ltimeout end end. -tryLocks(KeyIxs, ALockRef, PidInt, TimeOut) -> - case tryLockAll(KeyIxs, ALockRef, PidInt, []) of - ok -> - ok; - _ -> - loopLocks(KeyIxs, ALockRef, PidInt, TimeOut) - end. - -loopLocks(KeyIxs, ALockRef, PidInt, TimeOut) -> - receive - after ?ReTryTime -> - LTimeOut = ?CASE(TimeOut == infinity, TimeOut, TimeOut - ?ReTryTime), - case LTimeOut >= 0 of - true -> - case tryLockAll(KeyIxs, ALockRef, PidInt, []) of - ok -> - ok; - _ -> - loopLocks(KeyIxs, ALockRef, PidInt, LTimeOut) - end; - _ -> - timeout - end - end. -spec releaseLock(KeyOrKeys :: term() | [term()]) -> ok. releaseLock(KeyOrKeys) -> - ALockRef = persistent_term:get(?eGLockRef), - PidInt = eGPidInt:pidToInt(self()), + eNifLock:releaseLock(KeyOrKeys). + +-spec getLockPid(KeyOrKeys :: term() | [term()]) -> ok. +getLockPid(KeyOrKeys) -> case is_list(KeyOrKeys) of true -> - KeyIxs = getKexIxs(KeyOrKeys, []), - [atomics:compare_exchange(ALockRef, OneKeyIx, PidInt, 0) || OneKeyIx <- KeyIxs], - ok; + [{OneKey, eNifLock:getLockPid(OneKey)} || OneKey <- KeyOrKeys]; _ -> - atomics:compare_exchange(ALockRef, erlang:phash2(KeyOrKeys, ?eGLockSize) + 1, PidInt, 0), - ok + {KeyOrKeys, eNifLock:getLockPid(KeyOrKeys)} end. --spec lockApply(KeyOrKeys :: term() | [term()], MFAOrFun :: {M :: atom(), F :: atom(), Args :: list()} | {Fun :: function(), Args :: list()}) -> term(). +-spec lockApply(KeyOrKeys :: term() | [term()], MFAOrFun :: {M :: atom(), F :: atom(), Args :: list()} | {Fun :: function(), Args :: list()}) -> term() | {error, ltimeout} | {error, {lock_apply_error, term()}}. lockApply(KeyOrKeys, MFAOrFun) -> lockApply(KeyOrKeys, MFAOrFun, ?LockTimeOut). -spec lockApply(KeyOrKeys :: term() | [term()], MFAOrFun :: {M :: atom(), F :: atom(), Args :: list()} | {Fun :: function(), Args :: list()}, TimeOut :: integer() | infinity) -> term(). lockApply(KeyOrKeys, MFAOrFun, TimeOut) -> - ALockRef = persistent_term:get(?eGLockRef), - PidInt = eGPidInt:pidToInt(self()), - case is_list(KeyOrKeys) of + case doTryLock(KeyOrKeys, TimeOut) of true -> - KeyIxs = getKexIxs(KeyOrKeys, []), - lockApplys(KeyIxs, KeyOrKeys, ALockRef, PidInt, MFAOrFun, TimeOut); - _ -> - lockApply(erlang:phash2(KeyOrKeys, ?eGLockSize) + 1, KeyOrKeys, ALockRef, PidInt, MFAOrFun, TimeOut) - end. - -lockApply(KeyIx, Key, ALockRef, PidInt, MFAOrFun, TimeOut) -> - case tryLockOne(KeyIx, ALockRef, PidInt) of - ok -> - try doApply(MFAOrFun) - catch C:R:S -> - {error, {lock_apply_error, {C, R, S}}} - after - atomics:exchange(ALockRef, KeyIx, 0), - ok - end; - _ -> - loopApply(KeyIx, Key, ALockRef, PidInt, MFAOrFun, TimeOut) - end. - -loopApply(KeyIx, Key, ALockRef, PidInt, MFAOrFun, TimeOut) -> - receive - after ?ReTryTime -> - LTimeOut = ?CASE(TimeOut == infinity, TimeOut, TimeOut - ?ReTryTime), - case LTimeOut >= 0 of - true -> - case tryLockOne(KeyIx, ALockRef, PidInt) of - ok -> - try doApply(MFAOrFun) - catch C:R:S -> - {error, {lock_apply_error, {C, R, S}}} - after - atomics:exchange(ALockRef, KeyIx, 0), - ok - end; - _ -> - loopApply(KeyIx, Key, ALockRef, PidInt, MFAOrFun, LTimeOut) - end; - _ -> - {error, {lock_timeout, Key}} - end - end. - -lockApplys(KeyIxs, Keys, ALockRef, PidInt, MFAOrFun, TimeOut) -> - case tryLockAll(KeyIxs, ALockRef, PidInt, []) of - ok -> try doApply(MFAOrFun) catch C:R:S -> {error, {lock_apply_error, {C, R, S}}} after - [atomics:exchange(ALockRef, KeyIx, 0) || KeyIx <- KeyIxs], + eNifLock:releaseLock(KeyOrKeys), ok end; - _ -> - loopApplys(KeyIxs, Keys, ALockRef, PidInt, MFAOrFun, TimeOut) - end. - -loopApplys(KeyIxs, Keys, ALockRef, PidInt, MFAOrFun, TimeOut) -> - receive - after ?ReTryTime -> - LTimeOut = ?CASE(TimeOut == infinity, TimeOut, TimeOut - ?ReTryTime), - case LTimeOut >= 0 of - true -> - case tryLockAll(KeyIxs, ALockRef, PidInt, []) of - ok -> - try doApply(MFAOrFun) - catch C:R:S -> - {error, {lock_apply_error, {C, R, S}}} - after - [atomics:exchange(ALockRef, KeyIx, 0) || KeyIx <- KeyIxs], - ok - end; - _ -> - loopApplys(KeyIxs, Keys, ALockRef, PidInt, MFAOrFun, LTimeOut) - end; - _ -> - {error, {lock_timeout, Keys}} - end - end. - -getKexIxs([], IxAcc) -> IxAcc; -getKexIxs([Key | Keys], IxAcc) -> - KeyIx = erlang:phash2(Key, ?eGLockSize) + 1, - getKexIxs(Keys, ?CASE(lists:member(KeyIx, IxAcc), IxAcc, [KeyIx | IxAcc])). - -tryLockOne(KeyIx, ALockRef, PidInt) -> - case atomics:compare_exchange(ALockRef, KeyIx, 0, PidInt) of - ok -> - ok; - OldPidInt -> - case is_process_alive(eGPidInt:intToPid(OldPidInt)) of - true -> - false; - _ -> - case atomics:compare_exchange(ALockRef, KeyIx, OldPidInt, PidInt) of - ok -> - ok; - _ -> - false - end - end - end. - -tryLockAll([], _ALockRef, _PidInt, _LockAcc) -> - ok; -tryLockAll([KeyIx | KeyIxs], ALockRef, PidInt, LockAcc) -> - case tryLockOne(KeyIx, ALockRef, PidInt) of - ok -> - tryLockAll(KeyIxs, ALockRef, PidInt, [KeyIx | LockAcc]); - _ -> - [atomics:compare_exchange(ALockRef, OneLock, PidInt, 0) || OneLock <- LockAcc], - false + ltimeout -> + {error, ltimeout} end. doApply({M, F, Args}) -> diff --git a/src/eGLockMgr.erl b/src/eGLockMgr.erl deleted file mode 100644 index 77d5e99..0000000 --- a/src/eGLockMgr.erl +++ /dev/null @@ -1,41 +0,0 @@ --module(eGLockMgr). - --behaviour(gen_server). - --include("eGLock.hrl"). - --export([start_link/0]). --export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, - code_change/3]). - --define(SERVER, ?MODULE). - --record(state, {}). - -%%%=================================================================== -%%% Spawning and gen_server implementation -%%%=================================================================== - -start_link() -> - gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). - -init([]) -> - process_flag(trap_exit, true), - ATLockRef = atomics:new(?eGLockSize, [{signed, false}]), - persistent_term:put(?eGLockRef, ATLockRef), - {ok, #state{}}. - -handle_call(_Request, _From, State) -> - {reply, ok, State}. - -handle_cast(_Request, State) -> - {noreply, State}. - -handle_info(_Info, State) -> - {noreply, State}. - -terminate(_Reason, _State) -> - ok. - -code_change(_OldVsn, State, _Extra) -> - {ok, State}. diff --git a/src/eGLock_app.erl b/src/eGLock_app.erl deleted file mode 100644 index 4a986b3..0000000 --- a/src/eGLock_app.erl +++ /dev/null @@ -1,11 +0,0 @@ --module(eGLock_app). - --behaviour(application). - --export([start/2, stop/1]). - -start(_StartType, _StartArgs) -> - eGLock_sup:start_link(). - -stop(_State) -> - ok. \ No newline at end of file diff --git a/src/eGLock_sup.erl b/src/eGLock_sup.erl deleted file mode 100644 index 9e4fdaf..0000000 --- a/src/eGLock_sup.erl +++ /dev/null @@ -1,26 +0,0 @@ --module(eGLock_sup). - --behaviour(supervisor). - --include("eGLock.hrl"). - --export([start_link/0]). --export([init/1]). - --define(SERVER, ?MODULE). -start_link() -> - supervisor:start_link({local, ?SERVER}, ?MODULE, []). - -init([]) -> - SupFlags = #{strategy => one_for_all, intensity => 100, period => 3600}, - ChildSpecs = [ - #{ - id => eGLockMgr, - start => {eGLockMgr, start_link, []}, - restart => permanent, - shutdown => 3000, - type => worker, - modules => [eGLockMgr] - } - ], - {ok, {SupFlags, ChildSpecs}}. diff --git a/src/eGPidInt.erl b/src/eGPidInt.erl deleted file mode 100644 index ec7e4c8..0000000 --- a/src/eGPidInt.erl +++ /dev/null @@ -1,26 +0,0 @@ --module(eGPidInt). - --export([pidToInt/1, intToPid/1]). - --on_load(init/0). - -init() -> - SoName = - case code:priv_dir(?MODULE) of - {error, _} -> - case code:which(?MODULE) of - Filename when is_list(Filename) -> - filename:join([filename:dirname(Filename), "../priv", "eGPidInt"]); - _ -> - filename:join("../priv", "eGPidInt") - end; - Dir -> - filename:join(Dir, "eGPidInt") - end, - erlang:load_nif(SoName, 0). - -pidToInt(_Term) -> - erlang:nif_error({not_loaded, [{module, ?MODULE}, {line, ?LINE}]}). - -intToPid(_Term) -> - erlang:nif_error({not_loaded, [{module, ?MODULE}, {line, ?LINE}]}). \ No newline at end of file