Skip to content

Commit

Permalink
add missing notify_one
Browse files Browse the repository at this point in the history
  • Loading branch information
ngxson committed Sep 3, 2024
1 parent ec882cc commit d3fedaa
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions examples/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,6 @@ struct server_slot {
return n_remaining > 0; // no budget
}

bool available() const {
return state == SLOT_STATE_IDLE;
}

bool is_processing() const {
return state != SLOT_STATE_IDLE;
}
Expand All @@ -249,7 +245,7 @@ struct server_slot {
{"id_slot", id},
{"id_task", id_task},
{"n_past", n_past},
{"truncated", truncated}
{"truncated", truncated},
});
callback_on_release(id);
}
Expand Down Expand Up @@ -436,6 +432,7 @@ struct server_queue {
void defer(server_task task) {
std::unique_lock<std::mutex> lock(mutex_tasks);
queue_tasks_deferred.push_back(std::move(task));
condition_tasks.notify_one();
}

// Get the next id for creating a new task
Expand All @@ -458,7 +455,6 @@ struct server_queue {

// Call when the state of one slot is changed, it will move one task from deferred to main queue
void pop_deferred_task() {
// move deferred tasks back to main loop
std::unique_lock<std::mutex> lock(mutex_tasks);
if (!queue_tasks_deferred.empty()) {
server_task task = queue_tasks_deferred.front();
Expand Down Expand Up @@ -807,7 +803,7 @@ struct server_context {

for (server_slot & slot : slots) {
// skip the slot if it is not available
if (!slot.available()) {
if (slot.is_processing()) {
continue;
}

Expand Down Expand Up @@ -849,7 +845,7 @@ struct server_context {
int64_t t_last = ggml_time_us();
for (server_slot & slot : slots) {
// skip the slot if it is not available
if (!slot.available()) {
if (slot.is_processing()) {
continue;
}

Expand Down Expand Up @@ -1631,7 +1627,7 @@ struct server_context {
queue_tasks.defer(task);
break;
}
if (!slot->available()) {
if (slot->is_processing()) {
// if requested slot is unavailable, we defer this task for processing later
LOG_VERBOSE("requested slot is unavailable", {{"id_task", task.id}});
queue_tasks.defer(task);
Expand Down Expand Up @@ -1756,7 +1752,7 @@ struct server_context {
send_error(task, "Invalid slot ID", ERROR_TYPE_INVALID_REQUEST);
break;
}
if (!slot->available()) {
if (slot->is_processing()) {
// if requested slot is unavailable, we defer this task for processing later
LOG_VERBOSE("requested slot is unavailable", {{"id_task", task.id}});
queue_tasks.defer(task);
Expand Down Expand Up @@ -1797,7 +1793,7 @@ struct server_context {
send_error(task, "Invalid slot ID", ERROR_TYPE_INVALID_REQUEST);
break;
}
if (!slot->available()) {
if (slot->is_processing()) {
// if requested slot is unavailable, we defer this task for processing later
LOG_VERBOSE("requested slot is unavailable", {{"id_task", task.id}});
queue_tasks.defer(task);
Expand Down Expand Up @@ -1845,7 +1841,7 @@ struct server_context {
send_error(task, "Invalid slot ID", ERROR_TYPE_INVALID_REQUEST);
break;
}
if (!slot->available()) {
if (slot->is_processing()) {
// if requested slot is unavailable, we defer this task for processing later
LOG_VERBOSE("requested slot is unavailable", {{"id_task", task.id}});
queue_tasks.defer(task);
Expand Down

0 comments on commit d3fedaa

Please sign in to comment.