|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : pthread_setschedparam.cpp |
|
15 // Part of : PThread library |
|
16 // pthread_setschedparam call implementation. |
|
17 // Version: |
|
18 // |
|
19 |
|
20 |
|
21 |
|
22 #include <pthread.h> |
|
23 #include <errno.h> |
|
24 #include "threadglobals.h" |
|
25 #include "threadcreate.h" |
|
26 #include "pthreadmisc.h" |
|
27 |
|
28 EXPORT_C int pthread_setschedparam(pthread_t thread, int policy, |
|
29 const struct sched_param *param) |
|
30 { |
|
31 int priority; |
|
32 _global_data_t *glbPtr; |
|
33 _pthread_node_t *tempPtr; |
|
34 _pthread_node_t *selfNodePtr; |
|
35 _pthread_node_t *thHandle; |
|
36 |
|
37 THR_PRINTF("[pthread] Begin pthread_setschedparam\n"); |
|
38 |
|
39 if (NULL == param) |
|
40 { |
|
41 THR_PRINTF("[pthread] End of pthread_setschedparam\n"); |
|
42 return EINVAL; |
|
43 } |
|
44 /* Check the policy */ |
|
45 switch (policy) |
|
46 { |
|
47 case SCHED_RR: |
|
48 // Nothing has to be done. |
|
49 THR_PRINTF("[pthread] End pthread_setschedparam\n"); |
|
50 break; |
|
51 |
|
52 default: |
|
53 THR_PRINTF("[pthread] End pthread_setschedparam\n"); |
|
54 return EINVAL; |
|
55 } |
|
56 |
|
57 if ((param->sched_priority < MIN_RR_PRIORITY) || |
|
58 (param->sched_priority > MAX_RR_PRIORITY)) |
|
59 { |
|
60 THR_PRINTF("[pthread] End of pthread_setschedparam\n"); |
|
61 return EINVAL; |
|
62 } |
|
63 |
|
64 /* Mapping POSIX priorities to Symbian Threads priorities |
|
65 POSIX Symbian |
|
66 --------- ------------------ |
|
67 0 - 49 => EPriorityMuchLess |
|
68 50 - 99 => EPriorityLess |
|
69 100 - 149 => EPriorityNormal |
|
70 150 - 199 => EPriorityMore |
|
71 200 - 255 => EPriorityMuchMore |
|
72 */ |
|
73 |
|
74 switch (param->sched_priority / 50) |
|
75 { |
|
76 case 0: |
|
77 priority = EPriorityMuchLess; |
|
78 break; |
|
79 case 1: |
|
80 priority = EPriorityLess; |
|
81 break; |
|
82 case 2: |
|
83 priority = EPriorityNormal; |
|
84 break; |
|
85 case 3: |
|
86 priority = EPriorityMore; |
|
87 break; |
|
88 default: |
|
89 priority = EPriorityMuchMore; |
|
90 break; |
|
91 } |
|
92 |
|
93 /* Verify the thread handle */ |
|
94 |
|
95 //Get the TLS value (self node pointer) |
|
96 selfNodePtr = (_pthread_node_t*) _pthread_getTls(); |
|
97 //coverity[var_compare_op] |
|
98 if (NULL == selfNodePtr) |
|
99 { |
|
100 THR_PRINTF("[pthread] FATAL :TLS is not initialized \n"); |
|
101 THR_PRINTF("[pthread] Terminating the process\n"); |
|
102 RProcess rp; |
|
103 rp.Kill(0); // Terminate the process |
|
104 } |
|
105 |
|
106 thHandle = (_pthread_node_t *)thread; |
|
107 |
|
108 //coverity[var_deref_op] |
|
109 |
|
110 glbPtr = selfNodePtr->glbDataPtr; // point to global struct |
|
111 |
|
112 glbPtr->lockThreadTable.Wait(); // Acquire the thread table lock |
|
113 |
|
114 // Traverse through the list, till destination node is reached |
|
115 for (tempPtr = glbPtr->start; |
|
116 ((tempPtr != thHandle) && (tempPtr != NULL)); |
|
117 tempPtr = tempPtr->next) |
|
118 { |
|
119 ; //Empty loop |
|
120 } |
|
121 |
|
122 if (NULL == tempPtr) // Not found; |
|
123 { |
|
124 THR_PRINTF("[pthread] End of pthread_setschedparam"); |
|
125 glbPtr->lockThreadTable.Signal(); //release global lock |
|
126 return ESRCH; |
|
127 } |
|
128 |
|
129 thHandle->lockNode.Wait(); // Acquire the node lock |
|
130 |
|
131 thHandle->rtHandle.SetPriority((TThreadPriority)priority); |
|
132 thHandle->priority = priority; |
|
133 |
|
134 thHandle->lockNode.Signal(); |
|
135 glbPtr->lockThreadTable.Signal(); // release thread table lock |
|
136 |
|
137 THR_PRINTF("[pthread] End pthread_setschedparam\n"); |
|
138 |
|
139 return 0; |
|
140 } |
|
141 |
|
142 // End of File |
|
143 |