コード例 #1
0
ファイル: serwer.c プロジェクト: Solmis/SO
/* Ustawia atrybut detached */
void make_attr_detached()
{
    int thr_err;

    if ((thr_err = pthread_attr_init(&attr)) != 0)
        syserr_ext(thr_err, "Error in pthread_attr_init");

    if ((thr_err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)) != 0)
        syserr_ext(thr_err, "Error in pthread_attr_setdetachstate");
}
コード例 #2
0
ファイル: utils.c プロジェクト: SimoGira/ipc
// ------------------------------------------------------------------------------------------------------------
void initialize_sem(int semid, unsigned short values[]){
    
    union semun arg; // union to pass to semctl()
    
    arg.array = values;
    
    if ( semctl(semid, 0, SETALL, arg) == -1){
        syserr_ext ("utils.c" , "semctl",  __LINE__);
    }
}   
コード例 #3
0
ファイル: serwer.c プロジェクト: Solmis/SO
int main(int argc, char *argv[])
{
    L = atol(argv[1]);
    K = atol(argv[2]);
    M = atol(argv[3]);

    if (signal(SIGINT, exit_server) == SIG_ERR)
        syserr("Error in signal (SIGINT)");

    init_queues();

    int thr_err;
    pthread_t thread_id;
    make_attr_detached();
    if (thr_err = pthread_rwlock_init(&rwlock, NULL))
        syserr_ext(thr_err, "Error in function pthread_rwlock_init");

    Mesg mesg;
    int bytes_rcvd;
    while (1)
    {
        if ((bytes_rcvd = msgrcv(msg_rcv_id, &mesg, MAX_BUFF, 0, 0)) <= 0)
            syserr("Error in msgrcv (receiving type(pid))");
        mesg.mesg_data[bytes_rcvd] = '\0';

        if (mesg.mesg_type == READ_TYPE_KOM)
        {
            if ((thr_err = pthread_create(&thread_id, &attr, serve_committee, &mesg.mesg_data)) != 0)
                syserr_ext(thr_err, "Error in pthread_create (for serve_committee)");
        }
        else
        {
            if ((thr_err = pthread_create(&thread_id, &attr, serve_report, &mesg.mesg_data)) != 0)
                syserr_ext(thr_err, "Error in pthread_create (for serve_report)");
        }
    }

    exit_server(0);
}
コード例 #4
0
ファイル: utils.c プロジェクト: SimoGira/ipc
// ------------------------------------------------------------------------------------------------------------
void check_semval(int semid, int nsems){

    printf("check init values of semid %d\n", semid);
    union semun arg; // union to pass to semctl()
    arg.array = NULL;
    
    if( semctl(semid, 0, GETALL, arg) == -1 ){
        syserr_ext ("utils.c" , "semctl",  __LINE__);
    }

    int i;
    for(i = 0; i < nsems; i++){
        printf("%hu ", arg.array[i]);
    }
    printf("\n");
}
コード例 #5
0
ファイル: serwer.c プロジェクト: Solmis/SO
/* Obsłużenie przerwania procesu - m.in. usuwanie kolejek */
void exit_server(int sig) 
{
    int thr_err;

    if (msgctl(msg_rcv_id, IPC_RMID, 0) == -1)
        syserr("Error in msgctl RMID (msg_rcv_id)");

    if (msgctl(msg_rcv_det_id, IPC_RMID, 0) == -1)
        syserr("Error in msgctl RMID (msg_rcv_det_id)");

    if (msgctl(msg_snd_rap_id, IPC_RMID, 0) == -1)
        syserr("Error in msgctl RMID (msg_snd_rap_id)");

    if (msgctl(msg_snd_kom_id, IPC_RMID, 0) == -1)
        syserr("Error in msgctl RMID (msg_snd_kom_id)");

    if ((thr_err = pthread_attr_destroy(&attr)) != 0)
        syserr_ext(thr_err, "attrdestroy");

    exit(0);
}
コード例 #6
0
ファイル: utils.c プロジェクト: SimoGira/ipc
// ------------------------------------------------------------------------------------------------------------
void delete_sem(int semid){
    if (semctl(semid, 0, IPC_RMID, NULL) == -1)
        syserr_ext ("utils.c" , "semctl",  __LINE__);
}
コード例 #7
0
ファイル: utils.c プロジェクト: SimoGira/ipc
// ============================================================================================================
//                                               FUNCTIONS FOR - SEMAPHORE
// ============================================================================================================
int do_semget(key_t key, int nsems){
    int semid;
    if (( semid = semget(key, nsems, IPC_CREAT | 0777)) == -1)
        syserr_ext ("utils.c", " semget " , __LINE__);
    return semid;
}