Mercurial > hg > xemacs-beta
comparison src/event-msw.c @ 363:972bbb6d6ca2 r21-1-11
Import from CVS: tag r21-1-11
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:59:28 +0200 |
parents | 4711e16a8e49 |
children | a4f53d9b3154 |
comparison
equal
deleted
inserted
replaced
362:1e474c183006 | 363:972bbb6d6ca2 |
---|---|
450 /************************************************************************/ | 450 /************************************************************************/ |
451 | 451 |
452 #define NTPIPE_SHOVE_STREAM_DATA(stream) \ | 452 #define NTPIPE_SHOVE_STREAM_DATA(stream) \ |
453 LSTREAM_TYPE_DATA (stream, ntpipe_shove) | 453 LSTREAM_TYPE_DATA (stream, ntpipe_shove) |
454 | 454 |
455 #define MAX_SHOVE_BUFFER_SIZE 128 | 455 #define MAX_SHOVE_BUFFER_SIZE 512 |
456 | 456 |
457 struct ntpipe_shove_stream | 457 struct ntpipe_shove_stream |
458 { | 458 { |
459 LPARAM user_data; /* Any user data stored in the stream object */ | 459 LPARAM user_data; /* Any user data stored in the stream object */ |
460 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */ | 460 HANDLE hev_thread; /* Our thread blocks on this, signaled by caller */ |
483 | 483 |
484 /* Block on event and wait for a job */ | 484 /* Block on event and wait for a job */ |
485 InterlockedIncrement (&s->idle_p); | 485 InterlockedIncrement (&s->idle_p); |
486 WaitForSingleObject (s->hev_thread, INFINITE); | 486 WaitForSingleObject (s->hev_thread, INFINITE); |
487 | 487 |
488 if (s->die_p) | 488 /* Write passed buffer if any */ |
489 break; | 489 if (s->size > 0) |
490 | |
491 /* Write passed buffer */ | |
492 if (!WriteFile (s->hpipe, s->buffer, s->size, &bytes_written, NULL) | |
493 || bytes_written != s->size) | |
494 { | 490 { |
495 s->error_p = TRUE; | 491 if (!WriteFile (s->hpipe, s->buffer, s->size, &bytes_written, NULL) |
496 InterlockedIncrement (&s->die_p); | 492 || bytes_written != s->size) |
493 { | |
494 s->error_p = TRUE; | |
495 InterlockedIncrement (&s->die_p); | |
496 } | |
497 /* Set size to zero so we won't write it again if the closer sets | |
498 die_p and kicks us */ | |
499 s->size = 0; | |
497 } | 500 } |
498 | 501 |
499 if (s->die_p) | 502 if (s->die_p) |
500 break; | 503 break; |
501 } | 504 } |
524 { | 527 { |
525 Lstream_delete (lstr); | 528 Lstream_delete (lstr); |
526 return Qnil; | 529 return Qnil; |
527 } | 530 } |
528 | 531 |
532 /* Set the priority of the thread higher so we don't end up waiting | |
533 on it to send things. */ | |
534 if (!SetThreadPriority (s->hthread, THREAD_PRIORITY_HIGHEST)) | |
535 { | |
536 CloseHandle (s->hthread); | |
537 Lstream_delete (lstr); | |
538 return Qnil; | |
539 } | |
540 | |
529 /* hev_thread is an auto-reset event, initially nonsignaled */ | 541 /* hev_thread is an auto-reset event, initially nonsignaled */ |
530 s->hev_thread = CreateEvent (NULL, FALSE, FALSE, NULL); | 542 s->hev_thread = CreateEvent (NULL, FALSE, FALSE, NULL); |
531 | 543 |
532 /* Now let it go */ | 544 /* Now let it go */ |
533 ResumeThread (s->hthread); | 545 ResumeThread (s->hthread); |
581 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream); | 593 struct ntpipe_shove_stream* s = NTPIPE_SHOVE_STREAM_DATA(stream); |
582 | 594 |
583 /* Force thread stop */ | 595 /* Force thread stop */ |
584 InterlockedIncrement (&s->die_p); | 596 InterlockedIncrement (&s->die_p); |
585 | 597 |
598 /* Thread will end upon unblocking. If it's already unblocked this will | |
599 do nothing, but the thread won't look at die_p until it's written any | |
600 pending output. */ | |
601 SetEvent (s->hev_thread); | |
602 | |
603 /* Wait while thread terminates */ | |
604 WaitForSingleObject (s->hthread, INFINITE); | |
605 | |
586 /* Close pipe handle, possibly breaking it */ | 606 /* Close pipe handle, possibly breaking it */ |
587 CloseHandle (s->hpipe); | 607 CloseHandle (s->hpipe); |
588 | 608 |
589 /* Thread will end upon unblocking */ | 609 /* Close the thread handle */ |
590 SetEvent (s->hev_thread); | |
591 | |
592 /* Wait while thread terminates */ | |
593 WaitForSingleObject (s->hthread, INFINITE); | |
594 CloseHandle (s->hthread); | 610 CloseHandle (s->hthread); |
595 | 611 |
596 /* Destroy the event */ | 612 /* Destroy the event */ |
597 CloseHandle (s->hev_thread); | 613 CloseHandle (s->hev_thread); |
598 | 614 |