Permalink
Browse files

i cannot believe i did not know about port locking. thats how i assum…

…ed it all worked.
  • Loading branch information...
1 parent 949e404 commit 62d5d52cbc852784b50f1f3cee1dfa7e0a0669cf Cliff Moon committed Feb 22, 2009
Showing with 26 additions and 18 deletions.
  1. +19 −14 c/fnv_drv.c
  2. +7 −4 elibs/fnv.erl
View
33 c/fnv_drv.c
@@ -76,22 +76,27 @@ static void send_hash(ErlDrvPort port, unsigned long hash) {
}
static ErlDrvEntry fnv_driver_entry = {
- NULL, /* init */
+ NULL, /* init */
init,
stop,
- NULL, /* output */
- NULL, /* ready_input */
- NULL, /* ready_output */
- "fnv_drv", /* the name of the driver */
- NULL, /* finish */
- NULL, /* handle */
- control, /* control */
- NULL, /* timeout */
- outputv, /* outputv */
- NULL, /* ready_async */
- NULL, /* flush */
- NULL, /* call */
- NULL /* event */
+ NULL, /* output */
+ NULL, /* ready_input */
+ NULL, /* ready_output */
+ "fnv_drv", /* the name of the driver */
+ NULL, /* finish */
+ NULL, /* handle */
+ control, /* control */
+ NULL, /* timeout */
+ outputv, /* outputv */
+ NULL, /* ready_async */
+ NULL, /* flush */
+ NULL, /* call */
+ NULL, /* event */
+ ERL_DRV_EXTENDED_MARKER, /* ERL_DRV_EXTENDED_MARKER */
+ ERL_DRV_EXTENDED_MAJOR_VERSION, /* ERL_DRV_EXTENDED_MAJOR_VERSION */
+ ERL_DRV_EXTENDED_MAJOR_VERSION, /* ERL_DRV_EXTENDED_MINOR_VERSION */
+ ERL_DRV_FLAG_USE_PORT_LOCKING /* ERL_DRV_FLAGs */
+
};
DRIVER_INIT(fnv_driver) {
View
11 elibs/fnv.erl
@@ -54,12 +54,12 @@ hash(Thing) ->
hash(Thing, Seed) when is_binary(Thing) ->
P = get_or_open(),
- convert(port_control(fnv_drv, Seed, Thing));
+ convert(port_control(P, Seed, Thing));
% recv(P);
hash(Thing, Seed) ->
P = get_or_open(),
- convert(port_control(fnv_drv, Seed, term_to_binary(Thing))).
+ convert(port_control(P, Seed, term_to_binary(Thing))).
% recv(P).
%%====================================================================
@@ -73,8 +73,11 @@ convert(List) ->
Hash.
get_or_open() ->
- case whereis(fnv_drv) of
- undefined -> {ok, P} = start(),
+ case get(fnv_drv) of
+ undefined ->
+ load_driver(),
+ P = open(),
+ put(fnv_drv, P),
P;
P -> P
end.

0 comments on commit 62d5d52

Please sign in to comment.