Beispiel #1
0
// 设备注册服务
static void dev_service()
{
	Message msg;
	int ret;
	ret = SmNotifyService( DeviceManagerId, 0, "DeviceManager" );
	if( ret < 0 ){
		printf("[vfs]notify service failed. ret=%d\n", ret );
		SysExitSpace((uint)-1);
	}
	printf("[vfs]dev_service started.\n");
	for(;;){
		memset( &msg, 0, sizeof(msg) );
		ret = WaitMessage(&msg);
		if( ret<0 ){
			printf("[vfs]receive error in dev_service()\n");
			continue;
		}
		msg.Code = 0;
		switch( msg.Command ){
		case Device_Register:
		{
			printf("[vfs]Register %s\n", (char*)&msg.Arguments[3] );
			ReplyMessage( &msg );
			device_t *d = device_register( 
				msg.Arguments[0], //Device Type
				msg.Arguments[1], //ServiceThreadId
				msg.Arguments[2], //Device No. 
				(char*)&msg.Arguments[3]  //Device Name  
				);
			break;
		}
		case Device_Unregister:
			//Not implemented.
			msg.Code = -ERR_NOIMP;
			ReplyMessage( &msg );
			break;
		}
	}
	SmRemoveService( DeviceManagerId );
	SysExitThread(0);
}
Beispiel #2
0
static void pthread_start(void* arg)
{
	struct pthreadArgs* pArgs=(struct pthreadArgs*)arg;
	void* (*start)(void*) = pArgs->startRoutine;
	void* args = pArgs->args;
	
	struct pthread_queue entry;
	struct pthread_queue* head;

	DlTlsCreateContext();
	
	entry.threadId = pGetCurrentThreadId();
	entry.next = NULL;
	
	pthread_mutex_lock(&listMutex);
	
	head = threadList;
	
	while (head->next)
		head = head->next;
		
	head->next = &entry;
	
	pthread_mutex_unlock(&listMutex);

	pthread_cond_signal(pArgs->signal);

	start(args);
	
	/* Remove ourselves from the thread list. */
	pthread_mutex_lock(&listMutex);
	
	head = threadList;
	
	while (head->next && head->next != &entry)
		head = head->next;
	
	if (head->next)
		head->next = head->next->next;
		
	pthread_mutex_unlock(&listMutex);

	/* Wake up and remove everything in the join list. */
	pthread_mutex_lock(&joinMutex);
	
	head = joinList;
	joinList = NULL;
	
	while (head)
	{
		SysResumeThread(head->threadId);
		
		head = head->next;
	}
	
	pthread_mutex_unlock(&joinMutex);
	
	/* Actually exit the thread. We used to be able to return onto a frame
	 * set up by the kernel, but that no longer happens. */
	SysExitThread(-1);
}