Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add name registry #12

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
all: compile

compile clean:
rebar3 $@

test eunit:
rebar3 eunit

.PHONY: test
42 changes: 26 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,37 @@ erlsem

An OTP library implementing counting non-blocking semaphore with the ability to
monitor a process that obtains a lock and to release the corresponding
resource(s) automatically in case the process exits.
resource(s) automatically when the process exits.

Build
-----

$ rebar3 compile
$ rebar3 eunit
```shell
$ rebar3 compile
$ rebar3 eunit
```

Demo
----

Eshell V13.1.3 (abort with ^G)
1> Pid = self().
<0.145.0>
2> S = sema_nif:create(3).
#Ref<0.1541145699.2864316417.117910>
3> L = [spawn(fun() -> Pid ! {self(), sema_nif:acquire(S)}, timer:sleep(10) end) || _ <- lists:seq(1, 5)].
[<0.154.0>,<0.155.0>,<0.156.0>,<0.157.0>,<0.158.0>]
4> [receive {P, X} -> X end || P <- L].
[{ok,1},
{ok,2},
{ok,3},
{error,full},
{error,full}]
```erlang
Eshell V13.1.3 (abort with ^G)
1> Pid = self().
<0.145.0>
2> S = sema_nif:create(3).
#Ref<0.1541145699.2864316417.117910>
3> L = [spawn(fun() -> Pid ! {self(), sema_nif:acquire(S)}, timer:sleep(10) end) || _ <- lists:seq(1, 5)].
[<0.154.0>,<0.155.0>,<0.156.0>,<0.157.0>,<0.158.0>]
4> [receive {P, X} -> X end || P <- L].
[{ok,1},
{ok,2},
{ok,3},
{error,full},
{error,full}]
5> sema_nif:create(sema, 5).
#Ref<0.1541145699.2864316445.123450>
6> sema_nif:acquire(sema).
{ok, 1}
6> sema_nif:release(sema).
{ok, 0}
```
23 changes: 13 additions & 10 deletions c_src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,28 @@ ERL_INTERFACE_LIB_DIR ?= $(shell erl -noshell -eval "io:format(\"~ts\", [code:li
C_SRC_DIR = $(CURDIR)
C_SRC_OUTPUT ?= $(CURDIR)/../priv/$(PROJECT).so

ifeq ($(NIF_DEBUG),)
OPTIMIZE = -O3 -DNDEBUG
else
OPTIMIZE = -g -O0
endif

# System type and C compiler/flags.

UNAME_SYS := $(shell uname -s)
ifeq ($(UNAME_SYS), Darwin)
ifeq ($(UNAME_SYS),Darwin)
CC ?= cc
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
CXXFLAGS ?= -O3 -finline-functions -Wall
CXXFLAGS ?= -finline-functions -Wall
LDFLAGS ?= -flat_namespace -undefined suppress
else ifeq ($(UNAME_SYS), FreeBSD)
else ifeq ($(UNAME_SYS),FreeBSD)
CC ?= cc
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
CXXFLAGS ?= -O3 -finline-functions -Wall
else ifeq ($(UNAME_SYS), Linux)
CXXFLAGS ?= -finline-functions -Wall
else ifeq ($(UNAME_SYS),Linux)
CC ?= gcc
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
CXXFLAGS ?= -O3 -finline-functions -Wall
CXXFLAGS ?= -finline-functions -Wall
endif

CXXFLAGS += -std=c++11
CXXFLAGS += -std=c++20 $(OPTIMIZE)

CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
Expand Down
Loading
Loading