Skip to content

Commit 694b187

Browse files
author
Michael Kipper
committed
Review comments
1 parent 8a191f1 commit 694b187

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Per the above example, you no longer need to care about the number of tickets. R
187187

188188
In this case, we'd allow 49% of the workers on a particular host to connect to this redis resource.
189189

190-
In particular, 1 worker = 1 ticket (due to `ceil`), 2 workers = 2 tickets (due to `min_tickets`), 4 workers = 2 tickets, 16 workers = 8 tickets, 100 workers = 49 tickets.
190+
In particular, 1 worker = 1 ticket (due to `ceil`), 2 workers = 2 tickets (due to `min_tickets`), 4 workers = 2 tickets (due to `ceil`), 100 workers = 49 tickets.
191191

192192
**Note**:
193193

ext/semian/resource.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ static VALUE
44
cleanup_semian_resource_acquire(VALUE self);
55

66
static void
7-
check_tickets_xor_quota_arg(VALUE tickets, VALUE quota);
7+
check_tickets_xor_quota_arg(VALUE tickets, VALUE min_tickets, VALUE quota);
88

99
static double
1010
check_quota_arg(VALUE quota);
@@ -206,7 +206,7 @@ VALUE
206206
semian_resource_initialize(VALUE self, VALUE id, VALUE tickets, VALUE quota, VALUE permissions, VALUE default_timeout, VALUE min_tickets)
207207
{
208208
// Check and cast arguments
209-
check_tickets_xor_quota_arg(tickets, quota);
209+
check_tickets_xor_quota_arg(tickets, min_tickets, quota);
210210
double c_quota = check_quota_arg(quota);
211211
int c_tickets = check_tickets_arg(tickets);
212212
long c_permissions = check_permissions_arg(permissions);
@@ -257,10 +257,22 @@ check_permissions_arg(VALUE permissions)
257257
}
258258

259259
static void
260-
check_tickets_xor_quota_arg(VALUE tickets, VALUE quota)
260+
check_tickets_xor_quota_arg(VALUE tickets, VALUE min_tickets, VALUE quota)
261261
{
262-
if ((TYPE(tickets) == T_NIL && TYPE(quota) == T_NIL) ||(TYPE(tickets) != T_NIL && TYPE(quota) != T_NIL)){
263-
rb_raise(rb_eArgError, "Must pass exactly one of ticket or quota");
262+
const char *msg = "Must pass exactly one of ticket or quota/min_tickets";
263+
if (TYPE(quota) != T_NIL) {
264+
if (TYPE(tickets) != T_NIL) {
265+
dprintf("FOO");
266+
rb_raise(rb_eArgError, msg);
267+
}
268+
} else if (TYPE(tickets) != T_NIL) {
269+
if (TYPE(quota) != T_NIL || TYPE(min_tickets) != T_NIL) {
270+
dprintf("FOO");
271+
rb_raise(rb_eArgError, msg);
272+
}
273+
} else {
274+
dprintf("FOO");
275+
rb_raise(rb_eArgError, msg);
264276
}
265277
}
266278

ext/semian/tickets.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ calculate_quota_tickets(int sem_id, double quota, int min_tickets)
8484
{
8585
int workers = get_sem_val(sem_id, SI_SEM_REGISTERED_WORKERS);
8686
int tickets = (int) ceil(workers * quota);
87-
dprintf("Calculating quota tickets - sem_id:%d quota:%0.2f%% workers:%d min_tickets:%d tickets:%d", sem_id, quota, workers, min_tickets, tickets);
87+
dprintf("Calculating quota tickets - sem_id:%d quota:%0.2f%% workers:%d min_tickets:%d tickets:%d", sem_id, quota * 100.0, workers, min_tickets, tickets);
8888
return min_tickets > 0 ? min(workers, max(tickets, min_tickets)) : tickets;
8989
}

ext/semian/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <stdio.h>
66
#include <time.h>
77

8-
#if defined(DEBUG) || defined(SEMIAN_DEBUG)
8+
#ifdef DEBUG
99
# define DEBUG_TEST 1
1010
#else
1111
# define DEBUG_TEST 0

lib/semian/resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def instance(*args)
99
end
1010
end
1111

12-
def initialize(name, tickets: nil, quota: nil, permissions: 0660, timeout: 0, min_tickets: 1)
12+
def initialize(name, tickets: nil, quota: nil, permissions: 0660, timeout: 0, min_tickets: nil)
1313
if Semian.semaphores_enabled?
1414
initialize_semaphore(name, tickets, quota, permissions, timeout, min_tickets) if respond_to?(:initialize_semaphore)
1515
else

0 commit comments

Comments
 (0)