Changeset 7c2bb2c in mainline for uspace/srv/hid/remcons/remcons.c


Ignore:
Timestamp:
2012-01-10T14:59:39Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1870d81
Parents:
3806317
Message:

remcons: spawn task in separate fibril

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/remcons/remcons.c

    r3806317 r7c2bb2c  
    336336}
    337337
    338 
    339 static int network_client_fibril(void *arg)
    340 {
     338static int spawn_task_fibril(void *arg)
     339{
     340        client_t *client = arg;
    341341        int rc;
    342         client_t *client = arg;
    343 
    344         rc = loc_service_register(client->service_name, &client->service_id);
    345         if (rc != EOK) {
    346                 fprintf(stderr, "%s: Unable to register device %s\n", NAME,
    347                     client->service_name);
    348                 return EOK;
    349         }
    350         printf("Service %s registered as %" PRIun "\n", client->service_name,
    351             client->service_id);
    352342
    353343        char term[LOC_NAME_MAXLEN];
     
    359349                printf("%s: Error spawning %s -w %s %s (%s)\n", NAME,
    360350                    APP_GETTERM, term, "/app/bdsh", str_error(rc));
     351                fibril_mutex_lock(&client->refcount_mutex);
     352                client->refcount--;
     353                fibril_condvar_signal(&client->refcount_cv);
     354                fibril_mutex_unlock(&client->refcount_mutex);
    361355                return EOK;
    362356        }
    363         fibril_mutex_lock(&client->refcount_mutex);
    364         client->refcount++;
    365         fibril_mutex_unlock(&client->refcount_mutex);
    366357
    367358        task_exit_t task_exit;
     
    370361        printf("%s: getterm terminated: %d, %d\n", NAME, task_exit, task_retval);
    371362
     363        /* Announce destruction. */
     364        fibril_mutex_lock(&client->refcount_mutex);
     365        client->refcount--;
     366        fibril_condvar_signal(&client->refcount_cv);
     367        fibril_mutex_unlock(&client->refcount_mutex);
     368
     369        return EOK;
     370}
     371
     372
     373static int network_client_fibril(void *arg)
     374{
     375        int rc;
     376        client_t *client = arg;
     377
     378        rc = loc_service_register(client->service_name, &client->service_id);
     379        if (rc != EOK) {
     380                fprintf(stderr, "%s: Unable to register device %s\n", NAME,
     381                    client->service_name);
     382                return EOK;
     383        }
     384        printf("Service %s registered as %" PRIun "\n", client->service_name,
     385            client->service_id);
     386
     387        fibril_mutex_lock(&client->refcount_mutex);
     388        client->refcount++;
     389        fibril_mutex_unlock(&client->refcount_mutex);
     390
     391        fid_t spawn_fibril = fibril_create(spawn_task_fibril, client);
     392        assert(spawn_fibril);
     393        fibril_add_ready(spawn_fibril);
     394
     395        /* Wait for all clients to exit. */
     396        fibril_mutex_lock(&client->refcount_mutex);
     397        while (client->refcount > 0) {
     398                fibril_condvar_wait(&client->refcount_cv, &client->refcount_mutex);
     399        }
     400        fibril_mutex_unlock(&client->refcount_mutex);
     401
    372402        closesocket(client->socket);
    373403        rc = loc_service_unregister(client->service_id);
     
    376406        }
    377407
    378         /* Wait for all clients to exit. */
    379         fibril_mutex_lock(&client->refcount_mutex);
    380         /* Drop our reference. */
    381         client->refcount--;
    382         while (client->refcount > 0) {
    383                 fibril_condvar_wait(&client->refcount_cv, &client->refcount_mutex);
    384         }
    385         fibril_mutex_unlock(&client->refcount_mutex);
    386 
     408        printf("Destroying service %s.\n", client->service_name);
    387409        client_destroy(client);
    388410
Note: See TracChangeset for help on using the changeset viewer.