Changeset 400 for trunk/Include/Classes/System
- Timestamp:
- Jan 22, 2008, 9:19:59 PM (17 years ago)
- Location:
- trunk/Include/Classes/System
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/Classes/System/DateTime.ab
r370 r400 296 296 Dim dateTimeFormats = GC_malloc_atomic(SizeOf (TCHAR) * (strLength)) As PTSTR 297 297 GetDateFormat(LOCALE_USER_DEFAULT, 0, time, NULL, dateTimeFormats, dateFormatSize) 298 dateTimeFormats[dateFormatSize - 1] = Asc(" ")298 dateTimeFormats[dateFormatSize - 1] = &H20 As TCHAR 'Asc(" ") As TCHAR 299 299 GetTimeFormat(LOCALE_USER_DEFAULT, 0, time, NULL, dateTimeFormats + dateFormatSize, timeFormatSize) 300 300 'Debug -
trunk/Include/Classes/System/IO/DriveInfo.ab
r288 r400 21 21 debug 22 22 End If 23 driveName.ToUpper() 24 m_DriveName = driveName + ":\" 23 m_DriveName = driveName.ToUpper() + ":\" 25 24 End Sub 26 25 … … 30 29 'property 31 30 Function AvailableFreeSpace() As QWord 32 Dim availableFreeSpace As ULARGE_INTEGER 33 If GetDiskFreeSpaceEx(m_DriveName, availableFreeSpace, ByVal 0, ByVal 0) Then 34 Return (availableFreeSpace.HighPart << 32) Or availableFreeSpace.LowPart 35 Else 36 'IOException 31 If GetDiskFreeSpaceEx(ToTCStr(m_DriveName), ByVal VarPtr(AvailableFreeSpace) As *ULARGE_INTEGER, ByVal 0, ByVal 0) = FALSE Then 32 Throw New IOException("DriveInfo.AvailableFreeSpace: Failed to GetDiskFreeSpaceEx.") 37 33 End If 38 34 End Function … … 40 36 Function DriveFormat() As String 41 37 Dim systemName[15] As TCHAR 42 If GetVolumeInformation(m_DriveName, NULL, 0, NULL, NULL, NULL, systemName, Len (systemName)) Then 43 Dim resultStr = New String( systemName ) 44 Return resultStr 38 If GetVolumeInformation(ToTCStr(m_DriveName), NULL, 0, NULL, NULL, NULL, systemName, Len (systemName) \ SizeOf (TCHAR)) Then 39 DriveFormat = New String( systemName ) 45 40 Else 46 'IOException41 Throw New IOException("DriveInfo.DriveFormat: Failed to GetVolumeInformation.") 47 42 End If 48 43 End Function 49 44 50 45 Function DriveType() As Long 51 Return GetDriveType( m_DriveName)46 Return GetDriveType(ToTCStr(m_DriveName)) 52 47 End Function 53 48 54 49 Function IsReady() As Boolean 55 If GetVolumeInformation( m_DriveName, NULL, 0, NULL, NULL, NULL, NULL, 0) Then50 If GetVolumeInformation(ToTCStr(m_DriveName), NULL, 0, NULL, NULL, NULL, NULL, 0) Then 56 51 Return True 57 52 Else … … 68 63 69 64 Function TotalFreeSpace() As QWord 70 Dim totalFreeSpace As ULARGE_INTEGER 71 If GetDiskFreeSpaceEx(m_DriveName, ByVal 0, ByVal 0, totalFreeSpace) Then 72 Return (totalFreeSpace.HighPart << 32) Or totalFreeSpace.LowPart 73 Else 74 'IOException 65 If GetDiskFreeSpaceEx(ToTCStr(m_DriveName), ByVal 0, ByVal 0, ByVal VarPtr(TotalFreeSpace) As *ULARGE_INTEGER) = FALSE Then 66 Throw New IOException("DriveInfo.TotalFreeSpace: Failed to GetDiskFreeSpaceEx.") 75 67 End If 76 68 End Function 77 69 78 70 Function TotalSize() As QWord 79 Dim totalSize As ULARGE_INTEGER 80 If GetDiskFreeSpaceEx(m_DriveName, ByVal 0, totalSize, ByVal 0) Then 81 Return (totalSize.HighPart << 32) Or totalSize.LowPart 82 Else 83 'IOException 71 If GetDiskFreeSpaceEx(ToTCStr(m_DriveName), ByVal 0, ByVal VarPtr(TotalSize) As *ULARGE_INTEGER, ByVal 0) = FALSE Then 72 Throw New IOException("DriveInfo.TotalSize: Failed to GetDiskFreeSpaceEx.") 84 73 End If 85 74 End Function … … 87 76 Function VolumeLabel() As String 88 77 Dim volumeName[63] As TCHAR 89 If GetVolumeInformation(m_DriveName, volumeName, 64, NULL, NULL, NULL, NULL, 0) Then 90 Dim resultStr = New String( volumeName ) 91 Return resultStr 78 If GetVolumeInformation(ToTCStr(m_DriveName), volumeName, Len (volumeName) \ SizeOf (TCHAR), NULL, NULL, NULL, NULL, 0) Then 79 VolumeLabel = New String( volumeName ) 92 80 Else 93 'IOException81 Throw New IOException("DriveInfo.VolumeLabel: Failed to GetVolumeInformation.") 94 82 End If 95 83 End Function -
trunk/Include/Classes/System/IO/FileSystemInfo.ab
r346 r400 40 40 41 41 Sub Attributes(value As DWord) 42 If SetFileAttributes( FullPath, value) = FALSE Then42 If SetFileAttributes(ToTCStr(FullPath), value) = FALSE Then 43 43 'Exception 44 44 Debug … … 123 123 'Public Methods 124 124 Virtual Sub Delete() 125 If DeleteFile( FullPath) = FALSE Then125 If DeleteFile(ToTCStr(FullPath)) = FALSE Then 126 126 'Exception 127 127 debug -
trunk/Include/Classes/System/String.ab
r391 r400 311 311 Concat = New String 312 312 .AllocStringBuffer(m_Length + lenW) 313 ActiveBasic.Strings.ChrCopy(.Chars, This.Chars, m_Length )313 ActiveBasic.Strings.ChrCopy(.Chars, This.Chars, m_Length As SIZE_T) 314 314 MultiByteToWideChar(CP_THREAD_ACP, 0, text, len, VarPtr(.Chars[m_Length]), lenW) 315 315 .Chars[m_Length + lenW] = 0 -
trunk/Include/Classes/System/Threading/Thread.ab
r374 r400 1 'threading.sbp 2 1 'Thread.ab 3 2 4 3 '-------------------------------------------------------------------- … … 115 114 End Sub 116 115 117 118 119 120 121 116 Sub Start() 122 117 Dim ThreadId As DWord … … 133 128 134 129 'GCにスレッド開始を通知 135 _System_pobj_AllThreads->BeginThread( VarPtr(This),_System_GetSp() As *LONG_PTR)130 _System_pobj_AllThreads->BeginThread(This, _System_GetSp() As *LONG_PTR) 136 131 137 132 … … 147 142 148 143 'GCにスレッド終了を通知 149 _System_pobj_AllThreads->EndThread( VarPtr(This))144 _System_pobj_AllThreads->EndThread(This) 150 145 151 146 '自身のスレッドハンドルを閉じる … … 201 196 End Class 202 197 198 Dim _System_pobj_AllThreads As *Detail._System_CThreadCollection 199 200 Namespace Detail 203 201 204 202 '-------------------------------------------------------------------- … … 206 204 '-------------------------------------------------------------------- 207 205 ' TODO: このクラスをシングルトンにする 206 208 207 Class _System_CThreadCollection 209 208 Public 210 ppobj_Thread As **Thread 211 pStackBase As **LONG_PTR 209 collection As *ThreadInfo 212 210 ThreadNum As Long 213 211 … … 215 213 216 214 Sub _System_CThreadCollection() 217 ppobj_Thread=GC_malloc(1) 218 pStackBase=HeapAlloc(_System_hProcessHeap,0,1) 219 ppException=HeapAlloc(_System_hProcessHeap,0,1) 220 ThreadNum=0 221 222 'クリティカルセッションを生成 215 collection = GC_malloc(1) 216 ThreadNum = 0 223 217 InitializeCriticalSection(CriticalSection) 224 218 End Sub … … 227 221 Dim i As Long 228 222 For i=0 To ELM(ThreadNum) 229 If ppobj_Thread[i] Then 230 If i = 0 Then 231 Delete ppobj_Thread[i] 232 End If 233 ppobj_Thread[i]=0 234 pStackBase[i]=0 235 Delete ppException[i] 236 ppException[i]=0 237 Exit For 223 With collection[i] 224 If .thread Then 225 .thread = Nothing 226 .stackBase = 0 227 .exception = Nothing 228 End If 229 End With 230 Next 231 collection = 0 232 DeleteCriticalSection(CriticalSection) 233 End Sub 234 235 'スレッドを生成 236 Sub BeginThread(thread As Thread, NowSp As *LONG_PTR) 237 EnterCriticalSection(CriticalSection) 238 Dim i = FindFreeIndex 239 With collection[i] 240 .thread = thread 241 .stackBase = NowSp 242 .exception = New ExceptionService '例外処理管理用オブジェクトを生成 243 End With 244 LeaveCriticalSection(CriticalSection) 245 End Sub 246 Private 247 'クリティカルセション内で呼ぶこと 248 Function FindFreeIndex() As Long 249 Dim i As Long 250 For i = 0 To ELM(ThreadNum) 251 If ActiveBasic.IsNothing(collection[i].thread) Then 252 FindFreeIndex = i 253 Exit Function 238 254 End If 239 255 Next 240 241 HeapFree(_System_hProcessHeap,0,pStackBase) 242 pStackBase=0 243 244 HeapFree(_System_hProcessHeap,0,ppException) 245 ppException = 0 246 247 ThreadNum=0 248 249 'クリティカルセッションを破棄 250 DeleteCriticalSection(CriticalSection) 251 End Sub 252 253 'スレッドを生成 254 Sub BeginThread(pThread As *Thread,NowSp As *LONG_PTR) 255 EnterCriticalSection(CriticalSection) 256 257 '例外処理管理用オブジェクトを生成 258 Dim pException As *ExceptionService 259 pException = New ExceptionService 260 261 Dim i As Long 262 For i=0 To ELM(ThreadNum) 263 If ppobj_Thread[i] = 0 Then 264 ppobj_Thread[i] = pThread 265 pStackBase[i] = NowSp 266 ppException[i] = pException 267 Exit For 268 End If 269 Next 270 271 If i = ThreadNum Then 272 ppobj_Thread=realloc(ppobj_Thread,(ThreadNum+1)*SizeOf(*Thread)) 273 ppobj_Thread[ThreadNum]=pThread 274 pStackBase=HeapReAlloc(_System_hProcessHeap,0,pStackBase,(ThreadNum+1)*SizeOf(LONG_PTR)) 275 pStackBase[ThreadNum]=NowSp 276 ppException=HeapReAlloc(_System_hProcessHeap,0,ppException,(ThreadNum+1)*SizeOf(*ExceptionService)) 277 ppException[ThreadNum]=pException 278 ThreadNum++ 279 End If 280 LeaveCriticalSection(CriticalSection) 281 End Sub 256 ThreadNum++ 257 collection = realloc(collection, ThreadNum * SizeOf(ThreadInfo)) 258 FindFreeIndex = i 259 End Function 260 Public 282 261 283 262 'スレッドを終了 284 Sub EndThread( pThread As *Thread)263 Sub EndThread(thread As Thread) 285 264 EnterCriticalSection(CriticalSection) 286 265 Dim i As Long 287 For i=0 To ELM(ThreadNum) 288 If ppobj_Thread[i] = pThread Then 289 If i = 0 Then 290 Delete pThread 266 For i = 0 To ELM(ThreadNum) 267 With collection[i] 268 If thread.Equals(.thread) Then 269 .thread = Nothing 270 .stackBase = 0 271 .exception = Nothing 272 Exit For 291 273 End If 292 ppobj_Thread[i]=0 293 pStackBase[i]=0 294 Delete ppException[i] 295 ppException[i]=0 296 Exit For 297 End If 274 End With 298 275 Next 299 276 LeaveCriticalSection(CriticalSection) … … 303 280 Sub SuspendAllThread() 304 281 Dim i As Long 305 For i=0 To ELM(ThreadNum) 306 If ppobj_Thread[i] Then 307 ppobj_Thread[i]->Suspend() 308 End If 282 For i = 0 To ELM(ThreadNum) 283 With collection[i] 284 If Not ActiveBasic.IsNothing(.thread) Then 285 .thread.Suspend() 286 End If 287 End With 309 288 Next 310 289 End Sub … … 313 292 Sub ResumeAllThread() 314 293 Dim i As Long 315 For i=0 To ELM(ThreadNum) 316 If ppobj_Thread[i] Then 317 ppobj_Thread[i]->Resume() 318 End If 319 Next 320 End Sub 321 294 For i = 0 To ELM(ThreadNum) 295 With collection[i] 296 If Not ActiveBasic.IsNothing(.thread) Then 297 .thread.Resume() 298 End If 299 End With 300 Next 301 End Sub 302 /* 322 303 ' 自分以外のスレッドを中断 323 304 Sub SuspendAnotherThread() 324 Dim currentThread = Thread.CurrentThread()305 Dim currentThread = CurrentThread() 325 306 326 307 Dim i As Long 327 308 For i=0 To ELM(ThreadNum) 328 329 If currentThread.Equals( ppobj_Thread[i] As Object ) Then 330 Continue 331 End If 332 333 If ppobj_Thread[i] Then 334 ppobj_Thread[i]->Suspend() 335 End If 309 With collection[i] 310 If currentThread.Equals(.thread) Then 311 Continue 312 ElseIf Not ActiveBasic.IsNothing(.thread) Then 313 .thread.Suspend() 314 End If 315 End With 336 316 Next 337 317 End Sub … … 339 319 ' 自分以外のスレッドを再開 340 320 Sub ResumeAnotherThread() 341 Dim currentThread = Thread.CurrentThread()321 Dim currentThread = CurrentThread() 342 322 343 323 Dim i As Long 344 324 For i=0 To ELM(ThreadNum) 345 346 If currentThread.Equals( ppobj_Thread[i] As Object ) Then 347 Continue 348 End If 349 350 If ppobj_Thread[i] Then 351 ppobj_Thread[i]->Resume() 352 End If 353 Next 354 End Sub 355 325 With collection[i] 326 If currentThread.Equals(.thread) Then 327 Continue 328 ElseIf Not ActiveBasic.IsNothing(.thread) Then 329 .thread.Resume() 330 End If 331 End With 332 Next 333 End Sub 334 */ 356 335 'カレントスレッドを取得 357 336 Function CurrentThread() As Thread 358 Dim dwNowThreadId As DWord 359 dwNowThreadId=GetCurrentThreadId() 360 361 Dim i As Long 362 For i=0 To ELM(ThreadNum) 363 If ppobj_Thread[i]->ThreadId=dwNowThreadId Then 364 Return ByVal ppobj_Thread[i] 337 Dim p = CurrentThreadInfo() 338 If p = 0 Then 339 ' TODO: エラー処理 340 OutputDebugString( Ex"カレントスレッドの取得に失敗\r\n" ) 341 debug 342 Exit Function 343 End If 344 CurrentThread = p->thread 345 End Function 346 347 Function CurrentThreadInfo() As *ThreadInfo 348 CurrentThreadInfo = FindThreadInfo(GetCurrentThreadId()) 349 End Function 350 351 Function FindThreadInfo(threadID As DWord) As *ThreadInfo 352 Dim i As Long 353 For i = 0 To ELM(ThreadNum) 354 If collection[i].thread.ThreadId = threadID Then 355 FindThreadInfo = VarPtr(collection[i]) 356 Exit Function 365 357 End If 366 358 Next 367 368 ' TODO: エラー処理 369 OutputDebugString( "カレントスレッドの取得に失敗" ) 370 debug 371 End Function 372 359 End Function 373 360 374 361 Private … … 376 363 ' スレッド固有の例外処理制御 377 364 '------------------------------------------ 378 ppException As **ExceptionService 379 380 Public 381 Function GetCurrentException() As *ExceptionService 382 Dim dwNowThreadId As DWord 383 dwNowThreadId=GetCurrentThreadId() 365 366 Public 367 Function GetCurrentException() As ExceptionService 368 Dim dwNowThreadId = GetCurrentThreadId() 384 369 385 370 Dim i As Long 386 371 For i=0 To ELM(ThreadNum) 387 If ppobj_Thread[i]->ThreadId=dwNowThreadId Then 388 Return ppException[i] 389 End If 390 Next 391 392 Return NULL 372 With collection[i] 373 If .thread.ThreadId = dwNowThreadId Then 374 Return .exception 375 End If 376 End With 377 Next 378 379 OutputDebugString( Ex"カレントスレッドの取得に失敗\r\n" ) 380 Return Nothing 393 381 End Function 394 382 End Class 395 Dim _System_pobj_AllThreads As *_System_CThreadCollection 383 384 Type ThreadInfo 385 thread As Thread 386 stackBase As *LONG_PTR 387 exception As ExceptionService 388 End Type 389 390 End Namespace 'Detail -
trunk/Include/Classes/System/misc.ab
r391 r400 16 16 End Interface 17 17 18 Interface IClon able18 Interface ICloneable 19 19 ' Method 20 20 Function Clone() As Object
Note:
See TracChangeset
for help on using the changeset viewer.