File: THREADS

package info (click to toggle)
s3d 0.2.2.1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,356 kB
  • sloc: ansic: 21,128; python: 488; perl: 98; makefile: 31; sh: 29
file content (83 lines) | stat: -rw-r--r-- 2,972 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
currently:
----------
mainloop		(main.c)
	onetime
		nanosleep()
		user_main()
		network_main()
		graphics_main()


network_main():
	tcp_pollport()					polls for new processes
	tcp_pollproc()					reads data from the new processes (connected with TCP)
	shm_main()						check for new data from processes (connected via SHM)

user_main:
	user_main_sdl()					get and process SDL events, e.g. sending events to the processes
	-> graphics_pick_obj()			must render the scene, therefore needs exclusive access to GL

graphics_main
	...								setup the camera, set GL stuff
	render_by_mcp()					render the mcp
		render_virtual_object()		render a process (it's an virtual object in the MCPs object space)
			obj_render				render objects from the non-MCP process
		obj_render()				render a "normal" object from the MCP process
		
idea:
-----
NEW: 
  process states:
  UNINITIALIZED:    process has just been created, probably waiting for INIT from client
  GOT_INIT:         received the INIT, waiting for cleanup thread to set it up (mcp etc)
  RUNNING:          everything is set up
  WAIT_TO_DIE:      tells the client to quit as soon as possible.
  THREAD_LEFT:      client thread left, 
  

process threads:
each process has its own thread, blocking in tcp_proc_com_in if TCP, or simply sleeping in SHM 
(polling will be done in network thread):
* block in read()
* if process->state == WAIT_TO_DIE, set process->state = THREAD_LEFT and thread is removed
* lock processlist readonly
* handle incoming packet
* maybe send reply


network/cleanup thread:
does tcp_pollport, spawning new process-threads. After select times out, it polls all SHM 
connections if there is new data and wakes process threads up if there is anything to do.
* block for some time (200ms?), select() for incoming tcp connection
* if new connection, 
  * lock proccess list writeonly
  * setup new process, add mcp-things etc
  * unlock processlist
* lock processlist readonly
* iterate over processes, if SHM-connection and there is new data available wake it up (send condition-signal)
* if one process wants to quit (process->state == THREAD_LEFT), remember it for deletion
* unlock processlist
* if a process wants to quit
  * lock processlist writeonly
  * remove the process(es)
  * unlock processlist

graphic thread:
draws a frame and sleeps until it wakes up. processes make wake it up when new data was
received, or user events (pick object, window was resized/damaged).
* wait for signal to draw, or sleep 1 second (don't update too often, check for last update)
* lock processlist readonly
* render_by_mcp() locks mcp
   * obj_render() locks further objects
* unlock processlist

user/event thread:
processes events from outside (via SDL), send notifications to the processes

* block for the next SDL event (SDL_WaitEvent)
* lock processlist readonly
* when clicking, do as in graphic thread
* lock the process which receives the event
* send the event
* unlock process
* unlock processlist