Fixed indentation

This commit is contained in:
Maas-Maarten Zeeman
2012-10-28 08:14:21 +01:00
parent 768d4b198d
commit 6624096b93
4 changed files with 519 additions and 548 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -10,8 +10,8 @@
struct qitem_t
{
struct qitem_t* next;
void* data;
struct qitem_t* next;
void* data;
};
typedef struct qitem_t qitem;
@@ -32,8 +32,7 @@ queue_create()
queue *ret;
ret = (queue *) enif_alloc(sizeof(struct queue_t));
if(ret == NULL)
goto error;
if(ret == NULL) goto error;
ret->lock = NULL;
ret->cond = NULL;
@@ -43,22 +42,20 @@ queue_create()
ret->length = 0;
ret->lock = enif_mutex_create("queue_lock");
if(ret->lock == NULL)
goto error;
if(ret->lock == NULL) goto error;
ret->cond = enif_cond_create("queue_cond");
if(ret->cond == NULL)
goto error;
if(ret->cond == NULL) goto error;
return ret;
error:
if(ret->lock != NULL)
enif_mutex_destroy(ret->lock);
enif_mutex_destroy(ret->lock);
if(ret->cond != NULL)
enif_cond_destroy(ret->cond);
enif_cond_destroy(ret->cond);
if(ret != NULL)
enif_free(ret);
enif_free(ret);
return NULL;
}
@@ -104,7 +101,7 @@ queue_push(queue *queue, void *item)
{
qitem * entry = (qitem *) enif_alloc(sizeof(struct qitem_t));
if(entry == NULL)
return 0;
return 0;
entry->data = item;
entry->next = NULL;
@@ -114,16 +111,12 @@ queue_push(queue *queue, void *item)
assert(queue->length >= 0 && "Invalid queue size at push");
if(queue->tail != NULL)
{
queue->tail->next = entry;
}
queue->tail = entry;
if(queue->head == NULL)
{
queue->head = queue->tail;
}
queue->length += 1;
@@ -144,9 +137,7 @@ queue_pop(queue *queue)
/* Wait for an item to become available.
*/
while(queue->head == NULL)
{
enif_cond_wait(queue->cond, queue->lock);
}
assert(queue->length >= 0 && "Invalid queue size at pop.");
@@ -157,8 +148,7 @@ queue_pop(queue *queue)
queue->head = entry->next;
entry->next = NULL;
if(queue->head == NULL)
{
if(queue->head == NULL) {
assert(queue->tail == entry && "Invalid queue state: Bad tail.");
queue->tail = NULL;
}
@@ -194,9 +184,7 @@ queue_receive(queue *queue)
/* Wait for an item to become available.
*/
while(queue->message == NULL)
{
enif_cond_wait(queue->cond, queue->lock);
}
item = queue->message;
queue->message = NULL;

View File

@@ -22,14 +22,14 @@
%% higher-level export
-export([open/1, open/2,
exec/2, exec/3,
prepare/2, prepare/3,
step/1, step/2,
bind/2, bind/3,
fetchone/1,
fetchall/1,
column_names/1, column_names/2,
close/1, close/2]).
exec/2, exec/3,
prepare/2, prepare/3,
step/1, step/2,
bind/2, bind/3,
fetchone/1,
fetchall/1,
column_names/1, column_names/2,
close/1, close/2]).
-export([q/2, q/3, map/3, foreach/3]).
@@ -50,10 +50,10 @@ open(Filename, Timeout) ->
Ref = make_ref(),
ok = esqlite3_nif:open(Connection, Ref, self(), Filename),
case receive_answer(Ref, Timeout) of
ok ->
{ok, Connection};
Other ->
{error, Other}
ok ->
{ok, Connection};
Other ->
{error, Other}
end.
%% @doc Execute a sql statement, returns a list with tuples.
@@ -82,50 +82,50 @@ foreach(F, Sql, Connection) ->
%%
foreach_s(F, Statement) when is_function(F, 1) ->
case try_step(Statement, 0) of
'$done' -> ok;
Row when is_tuple(Row) ->
F(Row),
foreach_s(F, Statement)
'$done' -> ok;
Row when is_tuple(Row) ->
F(Row),
foreach_s(F, Statement)
end;
foreach_s(F, Statement) when is_function(F, 2) ->
ColumnNames = column_names(Statement),
case try_step(Statement, 0) of
'$done' -> ok;
Row when is_tuple(Row) ->
F(ColumnNames, Row),
foreach_s(F, Statement)
'$done' -> ok;
Row when is_tuple(Row) ->
F(ColumnNames, Row),
foreach_s(F, Statement)
end.
%%
map_s(F, Statement) when is_function(F, 1) ->
case try_step(Statement, 0) of
'$done' -> [];
Row when is_tuple(Row) ->
[F(Row) | map_s(F, Statement)]
'$done' -> [];
Row when is_tuple(Row) ->
[F(Row) | map_s(F, Statement)]
end;
map_s(F, Statement) when is_function(F, 2) ->
ColumnNames = column_names(Statement),
case try_step(Statement, 0) of
'$done' -> [];
Row when is_tuple(Row) ->
[F(ColumnNames, Row) | map_s(F, Statement)]
'$done' -> [];
Row when is_tuple(Row) ->
[F(ColumnNames, Row) | map_s(F, Statement)]
end.
%%
fetchone(Statement) ->
case try_step(Statement, 0) of
'$done' -> ok;
Row when is_tuple(Row) ->
Row
'$done' -> ok;
Row when is_tuple(Row) ->
Row
end.
%%
fetchall(Statement) ->
case try_step(Statement, 0) of
'$done' ->
[];
Row when is_tuple(Row) ->
[Row | fetchall(Statement)]
'$done' ->
[];
Row when is_tuple(Row) ->
[Row | fetchall(Statement)]
end.
%% Try the step, when the database is busy,
@@ -133,13 +133,13 @@ try_step(_Statement, Tries) when Tries > 5 ->
throw(too_many_tries);
try_step(Statement, Tries) ->
case esqlite3:step(Statement) of
'$busy' ->
timer:sleep(100 * Tries),
try_step(Statement, Tries + 1);
Something ->
Something
'$busy' ->
timer:sleep(100 * Tries),
try_step(Statement, Tries + 1);
Something ->
Something
end.
%% @doc Execute Sql statement, returns the number of affected rows.
%%
%% @spec exec(iolist(), connection()) -> integer() | {error, error_message()}
@@ -226,12 +226,12 @@ add_eos(IoList) ->
receive_answer(Ref, Timeout) ->
receive
{Ref, Resp} ->
Resp;
Other ->
throw(Other)
{Ref, Resp} ->
Resp;
Other ->
throw(Other)
after Timeout ->
throw({error, timeout, Ref})
throw({error, timeout, Ref})
end.

View File

@@ -22,14 +22,14 @@
%% low-level exports
-export([start/0,
open/4,
exec/4,
prepare/4,
step/3,
finalize/3,
bind/4,
column_names/3,
close/3
open/4,
exec/4,
prepare/4,
step/3,
finalize/3,
bind/4,
column_names/3,
close/3
]).
-on_load(init/0).